Instance   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 38
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A runTarget() 0 11 2
A getReflection() 0 11 2
1
<?php
2
/*
3
 * This file is part of the Respect\Rest package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Respect\Rest\Routes;
10
11
use ReflectionMethod;
12
use InvalidArgumentException;
13
use Respect\Rest\Routable;
14
15
class Instance extends AbstractRoute
16
{
17
    public $class = '';
18
    protected $instance = null;
19
    /** @var ReflectionMethod */
20
    protected $reflection;
21
22 8
    public function __construct($method, $pattern, $instance)
23
    {
24 8
        $this->instance = $instance;
25 8
        $this->class = get_class($instance);
26 8
        parent::__construct($method, $pattern);
27 8
    }
28
29 1
    public function getReflection($method)
30
    {
31 1
        if (empty($this->reflection)) {
32 1
            $this->reflection = new ReflectionMethod(
33 1
                $this->instance,
34 1
                $method
35
            );
36
        }
37
38 1
        return $this->reflection;
39
    }
40
41 5
    public function runTarget($method, &$params)
42
    {
43 5
        if (!$this->instance instanceof Routable) {
44 1
            throw new InvalidArgumentException('Route target must be an instance of Respect\Rest\Routable');
45
        }
46
47 4
        return call_user_func_array(
48 4
            array($this->instance, $method),
49 4
            $params
50
        );
51
    }
52
}
53