Instance::getReflection()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 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