DemoModeTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
c 0
b 0
f 0
dl 0
loc 51
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A demo() 0 9 3
1
<?php
2
/**
3
 * This file is part of the Shieldon package.
4
 *
5
 * (c) Terry L. <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * php version 7.1.0
11
 *
12
 * @category  Web-security
13
 * @package   Shieldon
14
 * @author    Terry Lin <[email protected]>
15
 * @copyright 2019 terrylinooo
16
 * @license   https://github.com/terrylinooo/shieldon/blob/2.x/LICENSE MIT
17
 * @link      https://github.com/terrylinooo/shieldon
18
 * @see       https://shieldon.io
19
 */
20
21
declare(strict_types=1);
22
23
namespace Shieldon\Firewall\Panel;
24
25
use Shieldon\Firewall\Container;
26
27
/*
28
 * Tradit for demonstration.
29
 */
30
trait DemoModeTrait
31
{
32
    /**
33
     *   Public methods       | Desctiotion
34
     *  ----------------------|---------------------------------------------
35
     *   demo                 | Start a demo mode. Setting fields are hidden.
36
     *  ----------------------|---------------------------------------------
37
     */
38
39
    /**
40
     * The mode of the firewall control panel.
41
     * self: Shieldon | managed: Firewall | demo: Demo
42
     *
43
     * @var string
44
     */
45
    protected $mode = 'self';
46
47
    /**
48
     * Login as a demo user.
49
     *
50
     * @var array
51
     */
52
    protected $demoUser = [
53
        'user' => 'demo',
54
        'pass' => 'demo',
55
    ];
56
57
    /**
58
     * Mark as demo.
59
     *
60
     * @var string
61
     */
62
    protected $markAsDemo = '';
63
64
    /**
65
     * In demo mode, user's submit will not take effect.
66
     *
67
     * @param string $user The user name.
68
     * @param string $pass The user password.
69
     *
70
     * @return void
71
     */
72 8
    public function demo(string $user = '', string $pass = ''): void
73
    {
74 8
        $this->demoUser['user'] = $user ?: 'demo';
75 8
        $this->demoUser['pass'] = $pass ?: 'demo';
76
77 8
        $this->mode = 'demo';
78 8
        $this->markAsDemo = ' (DEMO)';
79
80 8
        Container::get('shieldon')->managedBy('demo');
81
    }
82
}
83