MenuItem::active()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Iatstuti\SimpleMenu;
4
5
use Iatstuti\SimpleMenu\Traits\FetchesWeight;
6
use Iatstuti\SimpleMenu\Traits\ObjectOptions;
7
use Iatstuti\Support\Traits\MethodPropertyAccess;
8
9
/**
10
 * POPO object to wrap a menu item.
11
 *
12
 * @package    Iatstuti\SimpleMenu
13
 * @copyright  2016 IATSTUTI
14
 * @author     Michael Dyrynda <[email protected]>
15
 *
16
 * @property   string $label The menu label
17
 * @property   array $options The menu options
18
 */
19
class MenuItem
20
{
21
22
    use MethodPropertyAccess, ObjectOptions, FetchesWeight;
23
24
    /**
25
     * @var string
26
     */
27
    protected $label;
28
29
    /**
30
     * @var string
31
     */
32
    protected $link;
33
34
    /**
35
     * @var array
36
     */
37
    private $options;
38
39
40
    /**
41
     * MenuItem constructor.
42
     *
43
     * @param  string $label
44
     * @param  string $link
45
     * @param  array $options
46
     */
47
    public function __construct($label, $link, array $options = [ ])
48
    {
49
        $this->label   = $label;
50
        $this->link    = $link;
51
        $this->options = array_merge([
52
            'active' => false,
53
            'class'  => null,
54
            'weight' => 0,
55
        ], $options);
56
    }
57
58
59
    /**
60
     * Return this menu item's label.
61
     *
62
     * @return string
63
     */
64
    public function label()
65
    {
66
        return $this->label;
67
    }
68
69
70
    /**
71
     * Return this menu item's link.
72
     *
73
     * @return string
74
     */
75
    public function link()
76
    {
77
        return $this->link;
78
    }
79
80
81
    /**
82
     * Mark this menu item as the currently active one.
83
     *
84
     * @param  string $class
85
     *
86
     * @return \Iatstuti\SimpleMenu\MenuItem
87
     */
88
    public function active($class = 'active')
89
    {
90
        $this->options = array_merge($this->options, [ 'active' => true, 'class' => $class, ]);
91
92
        return $this;
93
    }
94
}
95