11<?php
2+
3+ declare (strict_types=1 );
24/**
35 * Contains the Menu Item class.
46 *
@@ -63,21 +65,41 @@ class Item
6365 */
6466 public function __construct (Menu $ menu , $ name , $ title , $ options )
6567 {
66- $ this ->menu = $ menu ;
67- $ this ->name = $ name ;
68- $ this ->title = $ title ;
68+ $ this ->menu = $ menu ;
69+ $ this ->name = $ name ;
70+ $ this ->title = $ title ;
6971 $ this ->attributes = Arr::except ($ options , $ this ->reserved );
70- $ this ->parent = $ this ->resolveParent (Arr::get ($ options , 'parent ' , null ));
71- $ this ->renderer = Arr::get ($ options , 'renderer ' , null );
72+ $ this ->parent = $ this ->resolveParent (Arr::get ($ options , 'parent ' , null ));
73+ $ this ->renderer = Arr::get ($ options , 'renderer ' , null );
7274
73- $ path = Arr::only ($ options , array ( 'url ' , 'route ' , 'action ' ) );
75+ $ path = Arr::only ($ options , [ 'url ' , 'route ' , 'action ' ] );
7476 if (!empty ($ path )) {
7577 $ this ->link = new Link ($ path , $ this ->menu ->config ->activeClass );
7678 }
7779
7880 $ this ->checkActivation ();
7981 }
8082
83+ /**
84+ * Search in meta data if a property doesn't exist otherwise return the property
85+ *
86+ * @param string
87+ *
88+ * @return string
89+ */
90+ public function __get ($ prop )
91+ {
92+ if (property_exists ($ this , $ prop )) {
93+ return $ this ->$ prop ;
94+ }
95+
96+ if ($ this ->children ()->has ($ prop )) {
97+ return $ this ->children ()->get ($ prop );
98+ }
99+
100+ return $ this ->data ($ prop );
101+ }
102+
81103 /**
82104 * Creates a sub Item
83105 *
@@ -89,7 +111,7 @@ public function __construct(Menu $menu, $name, $title, $options)
89111 */
90112 public function addSubItem ($ name , $ title , $ options = [])
91113 {
92- $ options = is_array ($ options ) ? $ options : ['url ' => $ options ];
114+ $ options = is_array ($ options ) ? $ options : ['url ' => $ options ];
93115 $ options ['parent ' ] = $ this ;
94116
95117 return $ this ->menu ->addItem ($ name , $ title , $ options );
@@ -239,15 +261,15 @@ public function childrenAllowed(Authenticatable $user = null)
239261 */
240262 public function hasParent ()
241263 {
242- return (bool )$ this ->parent ;
264+ return (bool ) $ this ->parent ;
243265 }
244266
245267 /**
246268 * Sets the item as active
247269 */
248270 public function activate ()
249271 {
250- if ($ this ->menu ->config ->activeElement == ' item ' ) {
272+ if (' item ' == $ this ->menu ->config ->activeElement ) {
251273 $ this ->setToActive ();
252274 } else {
253275 if ($ this ->link ) {
@@ -330,7 +352,7 @@ public function hasData($key)
330352 */
331353 public function hasLink ()
332354 {
333- return (bool )$ this ->link ;
355+ return (bool ) $ this ->link ;
334356 }
335357
336358 /**
@@ -362,26 +384,6 @@ public function hasProperty($property)
362384 $ this ->hasData ($ property );
363385 }
364386
365- /**
366- * Search in meta data if a property doesn't exist otherwise return the property
367- *
368- * @param string
369- *
370- * @return string
371- */
372- public function __get ($ prop )
373- {
374- if (property_exists ($ this , $ prop )) {
375- return $ this ->$ prop ;
376- }
377-
378- if ($ this ->children ()->has ($ prop )) {
379- return $ this ->children ()->get ($ prop );
380- }
381-
382- return $ this ->data ($ prop );
383- }
384-
385387 /**
386388 * Activate the item if it's enabled in menu config and item's url matches the request URI
387389 */
@@ -441,7 +443,7 @@ private function resolveParent($parent)
441443 throw new MenuItemNotFoundException (
442444 sprintf (
443445 'Item named `%s` could not be found in the `%s` menu ' ,
444- (string )$ parent ,
446+ (string ) $ parent ,
445447 $ this ->menu ->name
446448 )
447449 );
0 commit comments