Passed
Push — master ( c62529...5628da )
by Florian
03:24
created

ClassesFilter::makeSubmenuClasses()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 11
ccs 5
cts 5
cp 1
crap 3
rs 10
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Menu\Filters;
4
5
use JeroenNoten\LaravelAdminLte\Helpers\MenuItemHelper;
6
7
class ClassesFilter implements FilterInterface
8
{
9
    /**
10
     * Transforms a menu item. Add classes related attributes when suitable.
11
     *
12
     * @param array $item A menu item
13
     * @return array The transformed menu item
14
     */
15 44
    public function transform($item)
16
    {
17 44
        if (! MenuItemHelper::isHeader($item)) {
18 43
            $item['class'] = implode(' ', $this->makeClasses($item));
19
        }
20
21 44
        if (MenuItemHelper::isSubmenu($item)) {
22 10
            $item['submenu_class'] = implode(' ', $this->makeSubmenuClasses($item));
23
        }
24
25 44
        return $item;
26
    }
27
28
    /**
29
     * Make classes related to the components of a menu item.
30
     *
31
     * @param array $item A menu item
32
     * @return array The array of classes
33
     */
34 43
    protected function makeClasses($item)
35
    {
36 43
        $classes = [];
37
38
        // Add the active class when the item is active.
39
40 43
        if ($item['active']) {
41 32
            $classes[] = 'active';
42
        }
43
44 43
        return $classes;
45
    }
46
47
    /**
48
     * Make classes related to the components of a submenu item.
49
     *
50
     * @param array $item A menu item
51
     * @return array The array of classes
52
     */
53 10
    protected function makeSubmenuClasses($item)
54
    {
55 10
        $classes = [];
56
57
        // Add the menu-open class when a sidebar submenu is active.
58
59 10
        if (MenuItemHelper::isSidebarItem($item) && $item['active']) {
60 7
            $classes[] = 'menu-open';
61
        }
62
63 10
        return $classes;
64
    }
65
}
66