Inherit::evaluate()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 4
nc 3
nop 1
1
<?php
2
3
namespace Psecio\Invoke\Match\Internal;
4
5
class Inherit extends \Psecio\Invoke\MatchInstance
6
{
7
    /**
8
     * Execute the check
9
     *
10
     * @param \Psecio\Invoke\Data $data Data object instance
11
     * @return boolean Result of evaluation
12
     */
13
    public function evaluate($data)
14
    {
15
        $inherit = $data->route->getConfig('inherit');
0 ignored issues
show
Documentation introduced by
The property $route is declared private in Psecio\Invoke\Data. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
16
17
        if ($inherit !== null) {
18
            $routes = $data->getEnforcer()->getConfig();
0 ignored issues
show
Bug introduced by
The method getConfig cannot be called on $data->getEnforcer() (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
19
20
            // Find the one to inherit from
21
            foreach ($routes as $route) {
22
                if ($route->getConfig('name') === $inherit) {
23
                    $data->getEnforcer()->addMatch($route);
0 ignored issues
show
Bug introduced by
The method addMatch cannot be called on $data->getEnforcer() (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
24
                    return true;
25
                }
26
            }
27
        }
28
        return false;
29
    }
30
}