Completed
Push — develop ( e25e8d...0bf4e9 )
by Abdelrahman
01:12
created

MenuItem::isHidden()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Menus\Models;
6
7
use Illuminate\Support\Facades\Route;
8
use Collective\Html\HtmlFacade as HTML;
9
use Illuminate\Support\Facades\Request;
10
11
class MenuItem
12
{
13
    /**
14
     * The properties array.
15
     *
16
     * @var array
17
     */
18
    public $properties = [];
19
20
    /**
21
     * The childs collection.
22
     *
23
     * @var \Illuminate\Support\Collection
24
     */
25
    protected $childs;
26
27
    /**
28
     * The hide callback.
29
     *
30
     * @var callable
31
     */
32
    protected $hideWhen;
33
34
    /**
35
     * The active callback.
36
     *
37
     * @var callable
38
     */
39
    protected $activeWhen;
40
41
    /**
42
     * Constructor.
43
     *
44
     * @param array $properties
45
     */
46
    public function __construct($properties = [])
47
    {
48
        $this->fill($properties);
49
        $this->childs = collect();
50
    }
51
52
    /**
53
     * Get property.
54
     *
55
     * @param string $key
56
     *
57
     * @return mixed
58
     */
59
    public function __get($key)
60
    {
61
        return data_get($this->properties, $key);
62
    }
63
64
    /**
65
     * Fill the properties.
66
     *
67
     * @param array $properties
68
     *
69
     * @return static
70
     */
71
    public function fill($properties)
72
    {
73
        $this->properties = array_merge($this->properties, $properties);
74
75
        return $this;
76
    }
77
78
    /**
79
     * Create new menu with dropdown.
80
     *
81
     * @param callable $callback
82
     * @param string   $title
83
     * @param int      $order
0 ignored issues
show
Documentation introduced by
Should the type for parameter $order not be null|integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
84
     * @param string   $icon
0 ignored issues
show
Documentation introduced by
Should the type for parameter $icon not be null|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
85
     * @param array    $attributes
86
     *
87
     * @return static
88
     */
89
    public function dropdown(callable $callback, string $title, int $order = null, string $icon = null, array $attributes = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
90
    {
91
        call_user_func($callback, $item = $this->add(compact('title', 'order', 'icon', 'attributes')));
92
93
        return $item;
94
    }
95
96
    /**
97
     * Register new menu item using registered route.
98
     *
99
     * @param string $route
0 ignored issues
show
Documentation introduced by
Should the type for parameter $route not be array? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
100
     * @param string $title
101
     * @param int    $order
0 ignored issues
show
Documentation introduced by
Should the type for parameter $order not be null|integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
102
     * @param string $icon
0 ignored issues
show
Documentation introduced by
Should the type for parameter $icon not be null|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
103
     * @param array  $attributes
104
     *
105
     * @return static
106
     */
107
    public function route(array $route, string $title, int $order = null, string $icon = null, array $attributes = [])
108
    {
109
        return $this->add(compact('route', 'title', 'order', 'icon', 'attributes'));
110
    }
111
112
    /**
113
     * Register new menu item using url.
114
     *
115
     * @param string $url
116
     * @param string $title
117
     * @param int    $order
0 ignored issues
show
Documentation introduced by
Should the type for parameter $order not be null|integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
118
     * @param string $icon
0 ignored issues
show
Documentation introduced by
Should the type for parameter $icon not be null|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
119
     * @param array  $attributes
120
     *
121
     * @return static
122
     */
123
    public function url(string $url, string $title, int $order = null, string $icon = null, array $attributes = [])
124
    {
125
        return $this->add(compact('url', 'title', 'order', 'icon', 'attributes'));
126
    }
127
128
    /**
129
     * Add new header item.
130
     *
131
     * @param string $title
132
     * @param int    $order
0 ignored issues
show
Documentation introduced by
Should the type for parameter $order not be null|integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
133
     * @param string $icon
0 ignored issues
show
Documentation introduced by
Should the type for parameter $icon not be null|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
134
     * @param array  $attributes
135
     *
136
     * @return static
137
     */
138
    public function header(string $title, int $order = null, string $icon = null, array $attributes = [])
139
    {
140
        $type = 'header';
141
142
        return $this->add(compact('type', 'url', 'title', 'order', 'icon', 'attributes'));
143
    }
144
145
    /**
146
     * Add new divider item.
147
     *
148
     * @param int   $order
0 ignored issues
show
Documentation introduced by
Should the type for parameter $order not be null|integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
149
     * @param array $attributes
150
     *
151
     * @return static
152
     */
153
    public function divider(int $order = null, array $attributes = [])
154
    {
155
        return $this->add(['type' => 'divider', 'order' => $order, 'attributes' => $attributes]);
156
    }
157
158
    /**
159
     * Get childs.
160
     *
161
     * @return \Illuminate\Support\Collection
162
     */
163
    public function getChilds()
164
    {
165
        return $this->childs->sortBy('properties.order');
166
    }
167
168
    /**
169
     * Get url.
170
     *
171
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Contracts\Routing\UrlGenerator|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
172
     */
173
    public function getUrl()
174
    {
175
        return $this->route ? route($this->route[0], $this->route[1] ?? []) : ($this->url ? url($this->url) : '');
0 ignored issues
show
Documentation introduced by
The property route does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property url does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
176
    }
177
178
    /**
179
     * Get HTML attribute data.
180
     *
181
     * @return mixed
182
     */
183
    public function getAttributes()
184
    {
185
        return HTML::attributes($this->attributes);
0 ignored issues
show
Documentation introduced by
The property attributes does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
186
    }
187
188
    /**
189
     * Check if the current item is divider.
190
     *
191
     * @return bool
192
     */
193
    public function isDivider(): bool
194
    {
195
        return $this->type === 'divider';
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
196
    }
197
198
    /**
199
     * Check if the current item is header.
200
     *
201
     * @return bool
202
     */
203
    public function isHeader(): bool
204
    {
205
        return $this->type === 'header';
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
206
    }
207
208
    /**
209
     * Check is the current item has sub menu .
210
     *
211
     * @return bool
212
     */
213
    public function hasChilds()
214
    {
215
        return $this->childs->isNotEmpty();
216
    }
217
218
    /**
219
     * Check the active state for current menu.
220
     *
221
     * @return bool
222
     */
223
    public function hasActiveOnChild()
224
    {
225
        return $this->hasChilds() ? $this->hasActiveStateFromChilds() : false;
226
    }
227
228
    /**
229
     * Set hide callback for current menu item.
230
     *
231
     * @param callable $callback
232
     *
233
     * @return $this
234
     */
235
    public function hideWhen(callable $callback)
236
    {
237
        $this->hideWhen = $callback;
238
239
        return $this;
240
    }
241
242
    /**
243
     * Set authorization callback for current menu item.
244
     *
245
     * @param string $ability
246
     * @param mixed  $params
247
     *
248
     * @return $this
249
     */
250
    public function ifCan(string $ability, $params = null)
251
    {
252
        $this->hideWhen = function () use ($ability, $params) {
253
            return ! auth()->user()->can($ability, $params);
0 ignored issues
show
Bug introduced by
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
254
        };
255
256
        return $this;
257
    }
258
259
    /**
260
     * Set authentication callback for current menu item.
261
     *
262
     * @return $this
263
     */
264
    public function ifUser()
265
    {
266
        $this->hideWhen = function () {
267
            return ! auth()->user();
0 ignored issues
show
Bug introduced by
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
268
        };
269
270
        return $this;
271
    }
272
273
    /**
274
     * Set authentication callback for current menu item.
275
     *
276
     * @return $this
277
     */
278
    public function ifGuest()
279
    {
280
        $this->hideWhen = function () {
281
            return auth()->user();
0 ignored issues
show
Bug introduced by
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
282
        };
283
284
        return $this;
285
    }
286
287
    /**
288
     * Check if the menu item is hidden.
289
     *
290
     * @return bool
291
     */
292
    public function isHidden()
293
    {
294
        return $this->hideWhen ? (bool) call_user_func($this->hideWhen) : false;
295
    }
296
297
    /**
298
     * Get active state for current item.
299
     *
300
     * @return bool
301
     */
302
    public function isActive()
303
    {
304
        if (is_callable($activeWhen = $this->activeWhen)) {
305
            return call_user_func($activeWhen);
306
        }
307
308
        if ($this->route) {
0 ignored issues
show
Documentation introduced by
The property route does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
309
            return $this->hasActiveStateFromRoute();
310
        }
311
312
        return $this->hasActiveStateFromUrl();
313
    }
314
315
    /**
316
     * Set active callback.
317
     *
318
     * @param callable $route
0 ignored issues
show
Bug introduced by
There is no parameter named $route. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
319
     *
320
     * @return $this
321
     */
322
    public function activateWhen(callable $callback)
323
    {
324
        $this->activeWhen = $callback;
325
326
        return $this;
327
    }
328
329
    /**
330
     * Set active callback on the given route.
331
     *
332
     * @param string $route
333
     *
334
     * @return $this
335
     */
336
    public function activateOnRoute(string $route)
337
    {
338
        $this->activeWhen = function () use ($route) {
339
            return str_contains(Route::currentRouteName(), $route);
340
        };
341
342
        return $this;
343
    }
344
345
    /**
346
     * Add new child item.
347
     *
348
     * @param array $properties
349
     *
350
     * @return static
351
     */
352
    protected function add(array $properties = [])
353
    {
354
        $properties['attributes']['id'] = $properties['attributes']['id'] ?? md5(json_encode($properties));
355
        $this->childs->push($item = new static($properties));
356
357
        return $item;
358
    }
359
360
    /**
361
     * Get active status using route.
362
     *
363
     * @return bool
364
     */
365
    protected function hasActiveStateFromRoute(): bool
366
    {
367
        return Route::is($this->route);
0 ignored issues
show
Documentation introduced by
The property route does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
368
    }
369
370
    /**
371
     * Get active status using request url.
372
     *
373
     * @return bool
374
     */
375
    protected function hasActiveStateFromUrl(): bool
376
    {
377
        return Request::is($this->url);
0 ignored issues
show
Documentation introduced by
The property url does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
378
    }
379
380
    /**
381
     * Check if the item has active state from childs.
382
     *
383
     * @return bool
384
     */
385
    protected function hasActiveStateFromChilds(): bool
386
    {
387
        return $this->getChilds()->contains(function (MenuItem $child) {
388
                return ($child->hasChilds() && $child->hasActiveStateFromChilds())
389
                       || ($child->route && $child->hasActiveStateFromRoute())
0 ignored issues
show
Documentation introduced by
The property route does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
390
                       || $child->isActive() || $child->hasActiveStateFromUrl();
391
            }) ?? false;
392
    }
393
}
394