Completed
Push — 1.x ( c183a4...05b51a )
by Alexander
8s
created

AbstractMethodInvocation::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 3
crap 2
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2011, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\Aop\Framework;
12
13
use Go\Aop\Intercept\MethodInvocation;
14
use Go\Aop\Support\AnnotatedReflectionMethod;
15
use ReflectionMethod;
16
17
/**
18
 * Abstract method invocation implementation
19
 */
20
abstract class AbstractMethodInvocation extends AbstractInvocation implements MethodInvocation
21
{
22
23
    /**
24
     * Instance of object for invoking or class name for static call
25
     *
26
     * @var object|string
27
     */
28
    protected $instance;
29
30
    /**
31
     * Instance of reflection method for class
32
     *
33
     * @var ReflectionMethod
34
     */
35
    protected $reflectionMethod;
36
37
    /**
38
     * Name of the invocation class
39
     *
40
     * @var string
41
     */
42
    protected $className = '';
43
44
    /**
45
     * Constructor for method invocation
46
     *
47
     * @param string $className Class name
48
     * @param string $methodName Method to invoke
49
     * @param $advices array List of advices for this invocation
50
     */
51 26
    public function __construct($className, $methodName, array $advices)
52
    {
53 26
        parent::__construct($advices);
54 26
        $this->className        = $className;
55 26
        $this->reflectionMethod = $method = new AnnotatedReflectionMethod($this->className, $methodName);
56
57
        // Give an access to call protected method
58 26
        if ($method->isProtected()) {
59 5
            $method->setAccessible(true);
60
        }
61 26
    }
62
63
    /**
64
     * Gets the method being called.
65
     *
66
     * @return AnnotatedReflectionMethod the method being called.
67
     */
68 2
    public function getMethod()
69
    {
70 2
        return $this->reflectionMethod;
71
    }
72
73
    /**
74
     * Returns the object that holds the current joinpoint's static
75
     * part.
76
     *
77
     * @return object|string the object for dynamic call or string with name of scope
78
     */
79
    public function getThis()
80
    {
81
        return $this->instance;
82
    }
83
84
    /**
85
     * Returns the static part of this joinpoint.
86
     *
87
     * @return object
88
     */
89 1
    public function getStaticPart()
90
    {
91 1
        return $this->getMethod();
92
    }
93
94
    /**
95
     * Returns friendly description of this joinpoint
96
     *
97
     * @return string
98
     */
99
    final public function __toString()
100
    {
101
        return sprintf(
102
            "execution(%s%s%s())",
103
            is_object($this->instance) ? get_class($this->instance) : $this->instance,
104
            $this->reflectionMethod->isStatic() ? '::' : '->',
105
            $this->reflectionMethod->name
106
        );
107
    }
108
}
109