Passed
Branch main (dc6ce0)
by Roman
03:14
created
src/Helpers/MenuItem.php 2 patches
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -15,157 +15,157 @@
 block discarded – undo
15 15
 
16 16
 class MenuItem
17 17
 {
18
-    private $request;
19
-    private $title;
20
-    private $menuItemLinkType = MenuItemLinkType::ROUTE;
21
-    private $link;
22
-    private $baseLink;
23
-    private $icon;
24
-    private $children;
25
-    private $hash;
26
-    private $abbr;
27
-    private $isChild;
28
-    private $classes = [
29
-        'nav-item',
30
-    ];
31
-
32
-    public function __construct(
33
-        string $title,
34
-        string $menuItemLinkType,
35
-        string $link,
36
-        Icon $icon = null,
37
-        array $children = [],
38
-        bool $isChild = false
39
-    )
40
-    {
41
-        $this->title = $title;
42
-        $this->menuItemLinkType = $menuItemLinkType;
43
-        $this->link = $this->baseLink = $link;
44
-        $this->icon = $icon;
45
-        $this->children = collect($children);
46
-        $this->isChild = $isChild;
47
-        $this->hash = Uuid::fromString(md5($this->title));
48
-        $this->request = resolve(Request::class);
49
-
50
-        $this->setAbbr();
51
-        $this->setActive();
52
-    }
53
-
54
-    private function setAbbr()
55
-    {
56
-        $words = explode(' ', $this->getTitle());
57
-        $abbrArray = array_map(
58
-            static function ($word) {
59
-                return mb_strtoupper($word[0]);
60
-            },
61
-            $words
62
-        );
63
-
64
-        $abbrString = implode('', $abbrArray);
65
-        $this->abbr = preg_replace(
66
-            '/([^0-9A-Za-z])/',
67
-            '',
68
-            $abbrString
69
-        );
70
-    }
71
-
72
-    public function getTitle(): string
73
-    {
74
-        return $this->title;
75
-    }
76
-
77
-    private function setActive()
78
-    {
79
-        /** @var Route $route */
80
-        $route = $this->request->route();
81
-
82
-        if (!is_null($route)) {
83
-            switch ($this->menuItemLinkType) {
84
-                case MenuItemLinkType::ROUTE:
85
-                    if ($this->getBaseLink() === $route->getName()) {
86
-                        $this->classes[] = 'active';
87
-                    }
88
-
89
-                    break;
90
-                case MenuItemLinkType::URI:
91
-                    $match0 = mb_strpos(
92
-                            $route->uri(),
93
-                            $this->getBaseLink()
94
-                        ) === 0;
95
-
96
-                    if ($match0) {
97
-                        $this->classes[] = 'active';
98
-                    }
99
-                    break;
100
-            }
101
-        }
102
-    }
103
-
104
-    private function getBaseLink(): string
105
-    {
106
-        return $this->baseLink;
107
-    }
108
-
109
-    public function getLink(): string
110
-    {
111
-        $uri = '#';
112
-
113
-        switch ($this->hasChildren()) {
114
-            case true:
115
-                $uri = sprintf('#%s', $this->getMenuItemHash());
116
-                break;
117
-            case false:
118
-                switch ($this->menuItemLinkType) {
119
-                    case MenuItemLinkType::ROUTE:
120
-                        $uri = route($this->link);
121
-                        break;
122
-                    case MenuItemLinkType::URI:
123
-                        $uri = $this->link;
124
-                        break;
125
-                }
126
-                break;
127
-        }
128
-
129
-        return $uri;
130
-    }
131
-
132
-    public function hasChildren(): bool
133
-    {
134
-        return $this->children->isNotEmpty();
135
-    }
136
-
137
-    public function getMenuItemHash(): string
138
-    {
139
-        return $this->hash->toString();
140
-    }
141
-
142
-    public function hasIcon(): bool
143
-    {
144
-        return !is_null($this->getIcon());
145
-    }
146
-
147
-    public function getIcon(): ?Icon
148
-    {
149
-        return $this->icon;
150
-    }
151
-
152
-    public function isChild(): bool
153
-    {
154
-        return $this->isChild;
155
-    }
156
-
157
-    public function getChildren(): Collection
158
-    {
159
-        return $this->children;
160
-    }
161
-
162
-    public function getAbbr(): string
163
-    {
164
-        return $this->abbr;
165
-    }
166
-
167
-    public function getClasses(): string
168
-    {
169
-        return implode(' ', $this->classes);
170
-    }
18
+	private $request;
19
+	private $title;
20
+	private $menuItemLinkType = MenuItemLinkType::ROUTE;
21
+	private $link;
22
+	private $baseLink;
23
+	private $icon;
24
+	private $children;
25
+	private $hash;
26
+	private $abbr;
27
+	private $isChild;
28
+	private $classes = [
29
+		'nav-item',
30
+	];
31
+
32
+	public function __construct(
33
+		string $title,
34
+		string $menuItemLinkType,
35
+		string $link,
36
+		Icon $icon = null,
37
+		array $children = [],
38
+		bool $isChild = false
39
+	)
40
+	{
41
+		$this->title = $title;
42
+		$this->menuItemLinkType = $menuItemLinkType;
43
+		$this->link = $this->baseLink = $link;
44
+		$this->icon = $icon;
45
+		$this->children = collect($children);
46
+		$this->isChild = $isChild;
47
+		$this->hash = Uuid::fromString(md5($this->title));
48
+		$this->request = resolve(Request::class);
49
+
50
+		$this->setAbbr();
51
+		$this->setActive();
52
+	}
53
+
54
+	private function setAbbr()
55
+	{
56
+		$words = explode(' ', $this->getTitle());
57
+		$abbrArray = array_map(
58
+			static function ($word) {
59
+				return mb_strtoupper($word[0]);
60
+			},
61
+			$words
62
+		);
63
+
64
+		$abbrString = implode('', $abbrArray);
65
+		$this->abbr = preg_replace(
66
+			'/([^0-9A-Za-z])/',
67
+			'',
68
+			$abbrString
69
+		);
70
+	}
71
+
72
+	public function getTitle(): string
73
+	{
74
+		return $this->title;
75
+	}
76
+
77
+	private function setActive()
78
+	{
79
+		/** @var Route $route */
80
+		$route = $this->request->route();
81
+
82
+		if (!is_null($route)) {
83
+			switch ($this->menuItemLinkType) {
84
+				case MenuItemLinkType::ROUTE:
85
+					if ($this->getBaseLink() === $route->getName()) {
86
+						$this->classes[] = 'active';
87
+					}
88
+
89
+					break;
90
+				case MenuItemLinkType::URI:
91
+					$match0 = mb_strpos(
92
+							$route->uri(),
93
+							$this->getBaseLink()
94
+						) === 0;
95
+
96
+					if ($match0) {
97
+						$this->classes[] = 'active';
98
+					}
99
+					break;
100
+			}
101
+		}
102
+	}
103
+
104
+	private function getBaseLink(): string
105
+	{
106
+		return $this->baseLink;
107
+	}
108
+
109
+	public function getLink(): string
110
+	{
111
+		$uri = '#';
112
+
113
+		switch ($this->hasChildren()) {
114
+			case true:
115
+				$uri = sprintf('#%s', $this->getMenuItemHash());
116
+				break;
117
+			case false:
118
+				switch ($this->menuItemLinkType) {
119
+					case MenuItemLinkType::ROUTE:
120
+						$uri = route($this->link);
121
+						break;
122
+					case MenuItemLinkType::URI:
123
+						$uri = $this->link;
124
+						break;
125
+				}
126
+				break;
127
+		}
128
+
129
+		return $uri;
130
+	}
131
+
132
+	public function hasChildren(): bool
133
+	{
134
+		return $this->children->isNotEmpty();
135
+	}
136
+
137
+	public function getMenuItemHash(): string
138
+	{
139
+		return $this->hash->toString();
140
+	}
141
+
142
+	public function hasIcon(): bool
143
+	{
144
+		return !is_null($this->getIcon());
145
+	}
146
+
147
+	public function getIcon(): ?Icon
148
+	{
149
+		return $this->icon;
150
+	}
151
+
152
+	public function isChild(): bool
153
+	{
154
+		return $this->isChild;
155
+	}
156
+
157
+	public function getChildren(): Collection
158
+	{
159
+		return $this->children;
160
+	}
161
+
162
+	public function getAbbr(): string
163
+	{
164
+		return $this->abbr;
165
+	}
166
+
167
+	public function getClasses(): string
168
+	{
169
+		return implode(' ', $this->classes);
170
+	}
171 171
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
     {
56 56
         $words = explode(' ', $this->getTitle());
57 57
         $abbrArray = array_map(
58
-            static function ($word) {
58
+            static function($word) {
59 59
                 return mb_strtoupper($word[0]);
60 60
             },
61 61
             $words
Please login to merge, or discard this patch.
src/Helpers/MenuBuilder.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,31 +8,31 @@
 block discarded – undo
8 8
 
9 9
 class MenuBuilder
10 10
 {
11
-    public static function build(): array
12
-    {
13
-        return self::processMenu(
14
-            Config::get('mdp.menu', [])
15
-        );
16
-    }
17
-
18
-    private static function processMenu(array $menuItems, bool $isChild = false): array
19
-    {
20
-        foreach ($menuItems as $index => $menuItem) {
21
-
22
-            $link = array_key_exists('link', $menuItem) ?
23
-                $menuItem['link'] :
24
-                ['type' => MenuItemLinkType::URI, 'uri' => '#'];
25
-
26
-            $menuItems[$index] = new MenuItem(
27
-                $menuItem['title'],
28
-                $link['type'],
29
-                $link[$link['type']],
30
-                $isChild ? null : $menuItem['icon'],
31
-                self::processMenu($menuItem['children'] ?? [], true),
32
-                $isChild
33
-            );
34
-        }
35
-
36
-        return $menuItems;
37
-    }
11
+	public static function build(): array
12
+	{
13
+		return self::processMenu(
14
+			Config::get('mdp.menu', [])
15
+		);
16
+	}
17
+
18
+	private static function processMenu(array $menuItems, bool $isChild = false): array
19
+	{
20
+		foreach ($menuItems as $index => $menuItem) {
21
+
22
+			$link = array_key_exists('link', $menuItem) ?
23
+				$menuItem['link'] :
24
+				['type' => MenuItemLinkType::URI, 'uri' => '#'];
25
+
26
+			$menuItems[$index] = new MenuItem(
27
+				$menuItem['title'],
28
+				$link['type'],
29
+				$link[$link['type']],
30
+				$isChild ? null : $menuItem['icon'],
31
+				self::processMenu($menuItem['children'] ?? [], true),
32
+				$isChild
33
+			);
34
+		}
35
+
36
+		return $menuItems;
37
+	}
38 38
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,8 +20,7 @@
 block discarded – undo
20 20
         foreach ($menuItems as $index => $menuItem) {
21 21
 
22 22
             $link = array_key_exists('link', $menuItem) ?
23
-                $menuItem['link'] :
24
-                ['type' => MenuItemLinkType::URI, 'uri' => '#'];
23
+                $menuItem['link'] : ['type' => MenuItemLinkType::URI, 'uri' => '#'];
25 24
 
26 25
             $menuItems[$index] = new MenuItem(
27 26
                 $menuItem['title'],
Please login to merge, or discard this patch.
src/config/mdp/menu.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -7,25 +7,25 @@
 block discarded – undo
7 7
 use KielD01\LaravelMaterialDashboardPro\Helpers\MenuItemLinkType;
8 8
 
9 9
 return [
10
-    [
11
-        'title' => 'Dashboard',
12
-        'link' => [
13
-            'type' => MenuItemLinkType::ROUTE,
14
-            'route' => 'dashboard.index',
15
-        ],
16
-        'icon' => new MaterialIcon('dashboard'),
17
-    ],
18
-    [
19
-        'title' => 'Users',
20
-        'icon' => new FontAwesomeIcon('login'),
21
-        'children' => [
22
-            [
23
-                'title' => 'Create User',
24
-                'link' => [
25
-                    'type' => MenuItemLinkType::ROUTE,
26
-                    'route' => 'users.create',
27
-                ],
28
-            ]
29
-        ]
30
-    ],
10
+	[
11
+		'title' => 'Dashboard',
12
+		'link' => [
13
+			'type' => MenuItemLinkType::ROUTE,
14
+			'route' => 'dashboard.index',
15
+		],
16
+		'icon' => new MaterialIcon('dashboard'),
17
+	],
18
+	[
19
+		'title' => 'Users',
20
+		'icon' => new FontAwesomeIcon('login'),
21
+		'children' => [
22
+			[
23
+				'title' => 'Create User',
24
+				'link' => [
25
+					'type' => MenuItemLinkType::ROUTE,
26
+					'route' => 'users.create',
27
+				],
28
+			]
29
+		]
30
+	],
31 31
 ];
Please login to merge, or discard this patch.