Completed
Pull Request — master (#328)
by Nikola
03:49
created

AnnotatedReflectionMethod   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 16.66%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 2
dl 0
loc 64
ccs 3
cts 18
cp 0.1666
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAnnotation() 0 4 1
A getAnnotations() 0 4 1
A getReader() 0 8 2
A getClosure() 0 16 2
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2014, 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\Support;
12
13
use Doctrine\Common\Annotations\Reader;
14
use Go\Core\AspectKernel;
15
use ReflectionMethod;
16
17
/**
18
 * Extended version of ReflectionMethod with annotation support
19
 */
20
class AnnotatedReflectionMethod extends ReflectionMethod
21
{
22
    /**
23
     * Annotation reader
24
     *
25
     * @var Reader
26
     */
27
    private static $annotationReader = null;
28
29
    /**
30
     * Gets a method annotation.
31
     *
32
     * @param string $annotationName The name of the annotation.
33
     * @return mixed The Annotation or NULL, if the requested annotation does not exist.
34
     */
35
    public function getAnnotation($annotationName)
36
    {
37
        return self::getReader()->getMethodAnnotation($this, $annotationName);
38
    }
39
40
    /**
41
     * Gets the annotations applied to a method.
42
     *
43
     * @return array An array of Annotations.
44
     */
45
    public function getAnnotations()
46
    {
47
        return self::getReader()->getMethodAnnotations($this);
48
    }
49
50
    /**
51
     * Returns an annotation reader
52
     *
53
     * @return Reader $reader
54
     */
55
    private static function getReader()
56
    {
57
        if (!self::$annotationReader) {
58
            self::$annotationReader = AspectKernel::getInstance()->getContainer()->get('aspect.annotation.reader');
59
        };
60
61
        return self::$annotationReader;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 7
    public function getClosure($object)
68
    {
69 7
        if (!defined('HHVM_VERSION')) {
70 7
            return parent::getClosure($object);
71
        }
72
73
        $className  = $this->getDeclaringClass()->name;
74
        $methodName = $this->name;
75
        $closure = function (...$args) use ($methodName, $className) {
76
            $result = forward_static_call_array(array($className, $methodName), $args);
77
78
            return $result;
79
        };
80
81
        return $closure->bindTo($object, $this->class);
82
    }
83
}
84