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

MenuItemHelper   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 58
ccs 0
cts 13
cp 0
rs 10
c 2
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isLink() 0 4 3
A isSubmenu() 0 4 2
A isLegacySearch() 0 4 2
A isAllowed() 0 3 2
A isHeader() 0 3 2
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