Passed
Push — master ( 9a8db4...c61cdb )
by Peter
02:47
created

Item::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Navigation;
6
7
use AbterPhp\Framework\Authorization\Constant\Role;
8
use AbterPhp\Framework\Constant\Html5;
9
use AbterPhp\Framework\Html\Component;
10
11
class Item extends Component implements IResourcable
12
{
13
    const DEFAULT_TAG = Html5::TAG_LI;
14
15
    const INTENT_DROPDOWN = 'dropdown';
16
17
    /** @var string|null */
18
    protected $resource = null;
19
20
    /** @var string */
21
    protected $role = Role::READ;
22
23
    /** @var bool */
24
    protected $enabled = true;
25
26
    /**
27
     * @param string|null $resource
28
     *
29
     * @return $this
30
     */
31
    public function setResource(?string $resource): IResourcable
32
    {
33
        $this->resource = $resource;
34
35
        return $this;
36
    }
37
38
    /**
39
     * @return string|null
40
     */
41
    public function getResource(): ?string
42
    {
43
        return $this->resource;
44
    }
45
46
    /**
47
     * @param string|null $resource
48
     *
49
     * @return $this
50
     */
51
    public function setRole(?string $role): IResourcable
52
    {
53
        $this->role = $role;
54
55
        return $this;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getRole(): string
62
    {
63
        return $this->role;
64
    }
65
66
    /**
67
     * @return $this
68
     */
69
    public function disable(): IResourcable
70
    {
71
        $this->enabled = false;
72
73
        return $this;
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function __toString(): string
80
    {
81
        if (!$this->enabled) {
82
            return '';
83
        }
84
85
        return parent::__toString();
86
    }
87
}
88