Skip to content

Commit 79ea8c3

Browse files
committed
Apply fixes from StyleCI
1 parent 2257ddd commit 79ea8c3

40 files changed

+234
-158
lines changed

src/Contracts/ItemRenderer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Contains the ItemRenderer interface.
46
*

src/Contracts/MenuRenderer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Contains the MenuRenderer interface.
46
*

src/Exceptions/DuplicateItemNameException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Contains the DuplicateItemNameException class.
46
*

src/Exceptions/InvalidMenuConfigurationException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Contains the InvalidMenuConfigurationException class.
46
*

src/Exceptions/MenuAlreadyExistsException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Contains the MenuAlreadyExistsException class.
46
*

src/Exceptions/MenuItemNotFoundException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Contains the MenuItemNotFoundException class.
46
*

src/Facades/Menu.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Contains the Menu facade class.
46
*

src/Item.php

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
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
);

src/ItemCollection.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Contains the Menu Item Collection class.
46
*
@@ -16,6 +18,27 @@
1618

1719
class ItemCollection extends Collection
1820
{
21+
/**
22+
* Search the items based on an attribute
23+
*
24+
* @param string $method
25+
* @param array $args
26+
*
27+
* @return \Konekt\Menu\ItemCollection
28+
*/
29+
public function __call($method, $args)
30+
{
31+
preg_match('/^[W|w]here([a-zA-Z0-9_]+)$/', $method, $matches);
32+
33+
if (!$matches) {
34+
trigger_error('Call to undefined method ' . __CLASS__ . '::' . $method . '()', E_USER_ERROR);
35+
}
36+
37+
$attribute = strtolower($matches[1]);
38+
$value = $args ? $args[0] : null;
39+
40+
return $this->filterByProperty($attribute, $value);
41+
}
1942
/**
2043
* Alias to addItem. Needed for Laravel 5.8 compatibility
2144
* @see https://github.com/artkonekt/menu/issues/3
@@ -183,28 +206,6 @@ public function haveParent()
183206
});
184207
}
185208

186-
/**
187-
* Search the items based on an attribute
188-
*
189-
* @param string $method
190-
* @param array $args
191-
*
192-
* @return \Konekt\Menu\ItemCollection
193-
*/
194-
public function __call($method, $args)
195-
{
196-
preg_match('/^[W|w]here([a-zA-Z0-9_]+)$/', $method, $matches);
197-
198-
if (!$matches) {
199-
trigger_error('Call to undefined method ' . __CLASS__ . '::' . $method . '()', E_USER_ERROR);
200-
}
201-
202-
$attribute = strtolower($matches[1]);
203-
$value = $args ? $args[0] : null;
204-
205-
return $this->filterByProperty($attribute, $value);
206-
}
207-
208209
/**
209210
* @param $property
210211
* @param $value

src/Link.php

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Contains the Menu Link class.
46
*
@@ -18,6 +20,9 @@ class Link
1820
{
1921
use HasAttributes;
2022

23+
/** @var bool Flag for active state */
24+
public $isActive = false;
25+
2126
/** @var array Path Information */
2227
protected $path = [];
2328

@@ -27,9 +32,6 @@ class Link
2732
/** @var string Explicit href for the link */
2833
protected $href;
2934

30-
/** @var bool Flag for active state */
31-
public $isActive = false;
32-
3335
/**
3436
* Class constructor
3537
*
@@ -38,18 +40,35 @@ class Link
3840
*/
3941
public function __construct($path = [], $activeClass = 'active')
4042
{
41-
$this->path = $path;
43+
$this->path = $path;
4244
$this->activeClass = $activeClass;
4345
}
4446

47+
/**
48+
* Check for a method of the same name if the attribute doesn't exist.
49+
*
50+
* @param string $property
51+
*
52+
* @return mixed
53+
*/
54+
public function __get($property)
55+
{
56+
return $this->attr($property);
57+
}
58+
59+
public function __set($property, $value)
60+
{
61+
return $this->attr($property, $value);
62+
}
63+
4564
/**
4665
* Make the anchor active
4766
*
4867
* @return static
4968
*/
5069
public function activate()
5170
{
52-
$this->isActive = true;
71+
$this->isActive = true;
5372
$this->attributes['class'] = Utils::addHtmlClass(
5473
Arr::get($this->attributes, 'class', ''),
5574
$this->activeClass
@@ -92,23 +111,6 @@ public function url()
92111
return null;
93112
}
94113

95-
/**
96-
* Check for a method of the same name if the attribute doesn't exist.
97-
*
98-
* @param string $property
99-
*
100-
* @return mixed
101-
*/
102-
public function __get($property)
103-
{
104-
return $this->attr($property);
105-
}
106-
107-
public function __set($property, $value)
108-
{
109-
return $this->attr($property, $value);
110-
}
111-
112114
/**
113115
* Get the action for "url" option.
114116
*
@@ -118,7 +120,7 @@ protected function getUrl()
118120
{
119121
$url = $this->path['url'];
120122

121-
$uri = is_array($url) ? $url[0] : $url;
123+
$uri = is_array($url) ? $url[0] : $url;
122124
$params = is_array($url) ? array_slice($url, 1) : null;
123125

124126
if (Utils::isAbsoluteUrl($uri)) {

0 commit comments

Comments
 (0)