DropDown::activeParentage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace NukaCode\Menu;
2
3
use Illuminate\Support\Collection;
4
use NukaCode\Menu\Traits\Activate;
5
use NukaCode\Menu\Traits\Insertable;
6
use NukaCode\Menu\Traits\Linkable;
7
8
/**
9
 * Class DropDown
10
 *
11
 * @package NukaCode\Menu
12
 */
13
class DropDown {
14
    use Linkable;
15
    use Activate;
16
    use Insertable;
17
18
    /**
19
     * @var string
20
     */
21
    public $slug;
22
23
    /**
24
     * @var string|null
25
     */
26
    public $name;
27
28
    /**
29
     * @var bool
30
     */
31
    public $activateWithLinks = true;
32
33
    /**
34
     * Construct a menu
35
     *
36
     * @param $dropDownName The name of the drop down
37
     */
38 10
    public function __construct($dropDownName = null)
39
    {
40 10
        $this->links = new Collection();
41
42 10
        if (isset($dropDownName)) {
43 6
            $this->name = $dropDownName;
44 6
        }
45 10
    }
46
47
    /**
48
     * Check if the current object is a drop down
49
     *
50
     * @return bool
51
     */
52 3
    public function isDropDown()
53
    {
54 3
        return true;
55
    }
56
57
    /**
58
     * Check if the dropdown has links
59
     *
60
     * @return bool
61
     */
62 2
    public function hasLinks()
63
    {
64 2
        return (count($this->links) > 0);
65
    }
66
67
    /**
68
     * This stops the drop down from becoming active
69
     * because a child link is active.
70
     */
71 1
    public function disableActiveParentage()
72
    {
73 1
        $this->activateWithLinks = false;
74 1
    }
75
76
    /**
77
     * Check if the drop down should become active along
78
     * with it's links.
79
     */
80 3
    public function activeParentage()
81
    {
82 3
        return $this->activateWithLinks;
83
    }
84
}
85