Passed
Pull Request — master (#1151)
by Florian
03:01
created

MenuItemHelper::isLegacySearch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 6
rs 10
c 0
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
    public static function isHeader($item)
19
    {
20
        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
    public static function isLink($item)
30
    {
31
        return isset($item['text']) &&
32
               (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
    public static function isSubmenu($item)
42
    {
43
        return isset($item['text'], $item['submenu']) &&
44
               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
    public static function isLegacySearch($item)
54
    {
55
        return isset($item['text'], $item['search']) &&
56
               $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
    public static function isAllowed($item)
66
    {
67
        return $item && empty($item['restricted']);
68
    }
69
}
70