MenuItemHelper::isHeader()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Helpers;
4
5
/**
6
 * TODO: In the future, all the menu items should have a type property. So, we
7
 * can use this property to easily distinguish the item type and avoid guessing
8
 * it by other properties.
9
 */
10
class MenuItemHelper
11
{
12
    /**
13
     * Checks if a menu item is a header.
14
     *
15
     * @param  mixed  $item
16
     * @return bool
17
     */
18 56
    public static function isHeader($item)
19
    {
20 56
        return is_string($item) || isset($item['header']);
21
    }
22
23
    /**
24
     * Checks if a menu item is a link.
25
     *
26
     * @param  mixed  $item
27
     * @return bool
28
     */
29 4
    public static function isLink($item)
30
    {
31 4
        return isset($item['text'])
32 4
            && (isset($item['url']) || isset($item['route']));
33
    }
34
35
    /**
36
     * Checks if a menu item is a submenu.
37
     *
38
     * @param  mixed  $item
39
     * @return bool
40
     */
41 63
    public static function isSubmenu($item)
42
    {
43 63
        return isset($item['text'], $item['submenu'])
44 63
            && is_array($item['submenu']);
45
    }
46
47
    /**
48
     * Checks if a menu item is a legacy search box.
49
     *
50
     * @param  mixed  $item
51
     * @return bool
52
     */
53 58
    public static function isLegacySearch($item)
54
    {
55 58
        return isset($item['text'], $item['search'])
56 58
            && ! empty($item['search']);
57
    }
58
59
    /**
60
     * Checks if a menu item is allowed to be shown (not restricted).
61
     *
62
     * @param  mixed  $item
63
     * @return bool
64
     */
65 61
    public static function isAllowed($item)
66
    {
67
        // We won't allow empty submenu items on the menu.
68
69 61
        if (self::isSubmenu($item) && ! count($item['submenu'])) {
70 6
            return false;
71
        }
72
73
        // In any other case, fallback to the restricted property.
74
75 61
        return $item && empty($item['restricted']);
76
    }
77
}
78