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

MenuItemHelper::isValidNavbarItem()   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
nc 5
nop 1
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 5
rs 9.6111
c 1
b 0
f 0
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Helpers;
4
5
/**
6
 * TODO: On the future, all menu items should have a type property. We can use
7
 * the type property to easy distinguish the item type and avoid guessing it by
8
 * they properties.
9
 */
10
class MenuItemHelper
11
{
12
    /**
13
     * Check if a menu item is a header.
14
     *
15
     * @param mixed $item
16
     * @return bool
17
     */
18 52
    public static function isHeader($item)
19
    {
20 52
        return is_string($item) || isset($item['header']);
21
    }
22
23
    /**
24
     * Check 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
     * Check if a menu item is a submenu.
37
     *
38
     * @param mixed $item
39
     * @return bool
40
     */
41 56
    public static function isSubmenu($item)
42
    {
43 56
        return isset($item['text'], $item['submenu']) &&
44 56
               is_array($item['submenu']);
45
    }
46
47
    /**
48
     * Check if a menu item is a legacy search bar.
49
     *
50
     * @param mixed $item
51
     * @return bool
52
     */
53 54
    public static function isLegacySearch($item)
54
    {
55 54
        return isset($item['text'], $item['search']) &&
56 54
               $item['search'];
57
    }
58
59
    /**
60
     * Check if a menu item is allowed to be shown (not restricted).
61
     *
62
     * @param mixed $item
63
     * @return bool
64
     */
65 56
    public static function isAllowed($item)
66
    {
67 56
        return $item && empty($item['restricted']);
68
    }
69
}
70