Passed
Push — master ( 641691...2ce068 )
by Diego
02:59
created

NavbarItemHelper::isAcceptedItem()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 5
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 5
rs 9.6111
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 notification.
33
     *
34
     * @param mixed $item
35
     * @return bool
36
     */
37 3
    public static function isNotification($item)
38
    {
39 3
        return isset($item['id'], $item['icon'], $item['type']) &&
40 3
               (isset($item['url']) || isset($item['route'])) &&
41 3
               $item['type'] === 'navbar-notification';
42
    }
43
44
    /**
45
     * Check if a menu item is a navbar search item (legacy or new).
46
     *
47
     * @param mixed $item
48
     * @return bool
49
     */
50 53
    public static function isSearch($item)
51
    {
52 53
        return self::isLegacySearch($item) ||
53 53
               self::isCustomSearch($item);
54
    }
55
56
    /**
57
     * Check if a menu item is accepted for the navbar section.
58
     *
59
     * @param mixed $item
60
     * @return bool
61
     */
62 3
    public static function isAcceptedItem($item)
63
    {
64 3
        return self::isNotification($item) ||
65 3
               self::isFullscreen($item) ||
66 3
               self::isSubmenu($item) ||
67 3
               self::isSearch($item) ||
68 3
               self::isLink($item);
69
    }
70
71
    /**
72
     * Check if a menu item is valid for the left section of the navbar.
73
     *
74
     * @param mixed $item
75
     * @return bool
76
     */
77 1
    public static function isValidLeftItem($item)
78
    {
79 1
        return self::isAcceptedItem($item) &&
80 1
               isset($item['topnav']) &&
81 1
               $item['topnav'];
82
    }
83
84
    /**
85
     * Check if a menu item belongs to the right section of the navbar.
86
     *
87
     * @param mixed $item
88
     * @return bool
89
     */
90 1
    public static function isValidRightItem($item)
91
    {
92 1
        return self::isAcceptedItem($item) &&
93 1
               isset($item['topnav_right']) &&
94 1
               $item['topnav_right'];
95
    }
96
97
    /**
98
     * Check if a menu item belongs to the user menu section of the navbar.
99
     *
100
     * @param mixed $item
101
     * @return bool
102
     */
103 1
    public static function isValidUserMenuItem($item)
104
    {
105 1
        return self::isAcceptedItem($item) &&
106 1
               isset($item['topnav_user']) &&
107 1
               $item['topnav_user'];
108
    }
109
}
110