Passed
Push — master ( d0ad7b...a7252f )
by Diego
03:00
created

NavbarItemHelper   A

Complexity

Total Complexity 27

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 116
ccs 35
cts 35
cp 1
rs 10
wmc 27

9 Methods

Rating   Name   Duplication   Size   Complexity  
A isCustomSearch() 0 4 2
A isFullscreen() 0 4 2
A isSearch() 0 4 2
A isValidLeftItem() 0 5 3
A isValidRightItem() 0 5 3
A isValidUserMenuItem() 0 5 3
A isNotification() 0 5 4
A isAcceptedItem() 0 8 6
A isDarkmode() 0 4 2
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Helpers;
4
5
class NavbarItemHelper extends MenuItemHelper
6
{
7
    /**
8
     * Check if a menu item is a navbar custom search bar.
9
     *
10
     * @param mixed $item
11
     * @return bool
12
     */
13 51
    public static function isCustomSearch($item)
14
    {
15 51
        return isset($item['text'], $item['type']) &&
16 51
               $item['type'] === 'navbar-search';
17
    }
18
19
    /**
20
     * Check if a menu item is a navbar fullscreen toggle widget.
21
     *
22
     * @param mixed $item
23
     * @return bool
24
     */
25 3
    public static function isFullscreen($item)
26
    {
27 3
        return isset($item['type']) &&
28 3
               $item['type'] === 'fullscreen-widget';
29
    }
30
31
    /**
32
     * Check if a menu item is a navbar dark mode toggle widget.
33
     *
34
     * @param mixed $item
35
     * @return bool
36
     */
37 3
    public static function isDarkmode($item)
38
    {
39 3
        return isset($item['type']) &&
40 3
               $item['type'] === 'darkmode-widget';
41
    }
42
43
    /**
44
     * Check if a menu item is a navbar notification.
45
     *
46
     * @param mixed $item
47
     * @return bool
48
     */
49 3
    public static function isNotification($item)
50
    {
51 3
        return isset($item['id'], $item['icon'], $item['type']) &&
52 3
               (isset($item['url']) || isset($item['route'])) &&
53 3
               $item['type'] === 'navbar-notification';
54
    }
55
56
    /**
57
     * Check if a menu item is a navbar search item (legacy or new).
58
     *
59
     * @param mixed $item
60
     * @return bool
61
     */
62 53
    public static function isSearch($item)
63
    {
64 53
        return self::isLegacySearch($item) ||
65 53
               self::isCustomSearch($item);
66
    }
67
68
    /**
69
     * Check if a menu item is accepted for the navbar section.
70
     *
71
     * @param mixed $item
72
     * @return bool
73
     */
74 3
    public static function isAcceptedItem($item)
75
    {
76 3
        return self::isNotification($item) ||
77 3
               self::isFullscreen($item) ||
78 3
               self::isDarkmode($item) ||
79 3
               self::isSubmenu($item) ||
80 3
               self::isSearch($item) ||
81 3
               self::isLink($item);
82
    }
83
84
    /**
85
     * Check if a menu item is valid for the left section of the navbar.
86
     *
87
     * @param mixed $item
88
     * @return bool
89
     */
90 1
    public static function isValidLeftItem($item)
91
    {
92 1
        return self::isAcceptedItem($item) &&
93 1
               isset($item['topnav']) &&
94 1
               $item['topnav'];
95
    }
96
97
    /**
98
     * Check if a menu item belongs to the right section of the navbar.
99
     *
100
     * @param mixed $item
101
     * @return bool
102
     */
103 1
    public static function isValidRightItem($item)
104
    {
105 1
        return self::isAcceptedItem($item) &&
106 1
               isset($item['topnav_right']) &&
107 1
               $item['topnav_right'];
108
    }
109
110
    /**
111
     * Check if a menu item belongs to the user menu section of the navbar.
112
     *
113
     * @param mixed $item
114
     * @return bool
115
     */
116 1
    public static function isValidUserMenuItem($item)
117
    {
118 1
        return self::isAcceptedItem($item) &&
119 1
               isset($item['topnav_user']) &&
120 1
               $item['topnav_user'];
121
    }
122
}
123