NavbarItemHelper::isAcceptedItem()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 6
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 6
rs 9.2222
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Helpers;
4
5
class NavbarItemHelper extends MenuItemHelper
6
{
7
    /**
8
     * Checks if a menu item is a navbar custom search box.
9
     *
10
     * @param  mixed  $item
11
     * @return bool
12
     */
13 55
    public static function isCustomSearch($item)
14
    {
15 55
        return isset($item['text'], $item['type'])
16 55
            && $item['type'] === 'navbar-search';
17
    }
18
19
    /**
20
     * Checks 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']) && $item['type'] === 'fullscreen-widget';
28
    }
29
30
    /**
31
     * Checks if a menu item is a navbar dark mode toggle widget.
32
     *
33
     * @param  mixed  $item
34
     * @return bool
35
     */
36 3
    public static function isDarkmode($item)
37
    {
38 3
        return isset($item['type']) && $item['type'] === 'darkmode-widget';
39
    }
40
41
    /**
42
     * Checks if a menu item is a navbar notification.
43
     *
44
     * @param  mixed  $item
45
     * @return bool
46
     */
47 3
    public static function isNotification($item)
48
    {
49 3
        return isset($item['id'], $item['icon'], $item['type'])
50 3
            && (isset($item['url']) || isset($item['route']))
51 3
            && $item['type'] === 'navbar-notification';
52
    }
53
54
    /**
55
     * Checks if a menu item is a navbar search item (legacy or new).
56
     *
57
     * @param  mixed  $item
58
     * @return bool
59
     */
60 57
    public static function isSearch($item)
61
    {
62 57
        return self::isLegacySearch($item) || self::isCustomSearch($item);
63
    }
64
65
    /**
66
     * Checks if a menu item is accepted for the navbar section.
67
     *
68
     * @param  mixed  $item
69
     * @return bool
70
     */
71 3
    public static function isAcceptedItem($item)
72
    {
73 3
        return self::isNotification($item)
74 3
            || self::isFullscreen($item)
75 3
            || self::isDarkmode($item)
76 3
            || self::isSubmenu($item)
77 3
            || self::isSearch($item)
78 3
            || self::isLink($item);
79
    }
80
81
    /**
82
     * Checks if a menu item is valid for the left section of the navbar.
83
     *
84
     * @param  mixed  $item
85
     * @return bool
86
     */
87 1
    public static function isValidLeftItem($item)
88
    {
89 1
        return self::isAcceptedItem($item) && ! empty($item['topnav']);
90
    }
91
92
    /**
93
     * Checks if a menu item is valid for the right section of the navbar.
94
     *
95
     * @param  mixed  $item
96
     * @return bool
97
     */
98 1
    public static function isValidRightItem($item)
99
    {
100 1
        return self::isAcceptedItem($item) && ! empty($item['topnav_right']);
101
    }
102
103
    /**
104
     * Checks if a menu item is valid for the user menu section of the navbar.
105
     *
106
     * @param  mixed  $item
107
     * @return bool
108
     */
109 1
    public static function isValidUserMenuItem($item)
110
    {
111 1
        return self::isAcceptedItem($item) && ! empty($item['topnav_user']);
112
    }
113
}
114