Callback   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A evaluate() 0 11 2
1
<?php
2
3
namespace Psecio\Invoke\Match\Object;
4
5
class Callback extends \Psecio\Invoke\MatchInstance
6
{
7
	protected $error = 'Failure returned from callback :data';
8
9
	/**
10
	 * Execute the provided callback
11
	 *
12
	 * @param \Psecio\Invoke\Data $data Data object instance
13
	 * @return boolean Result of evaluation
14
	 */
15
	public function evaluate($data)
16
	{
17
		$config = $data->route->getConfig();
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...
18
19
		// Break up the class and method
20
		list($class, $method) = explode('::', $config['callback']);
21
		if (!class_exists($class)) {
22
			throw new \InvalidArgumentException('Class "'.$class.'" does not exist');
23
		}
24
		return $class::$method($data);
25
	}
26
}