Completed
Push — master ( bfa80e...3adc88 )
by Alexander
02:11
created

AnnotatedReflectionMethod   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 20%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 3
dl 0
loc 60
ccs 3
cts 15
cp 0.2
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
declare(strict_types = 1);
3
/*
4
 * Go! AOP framework
5
 *
6
 * @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Go\Aop\Support;
13
14
use Doctrine\Common\Annotations\Reader;
15
use Go\Core\AspectKernel;
16
use ReflectionMethod;
17
18
/**
19
 * Extended version of ReflectionMethod with annotation support
20
 */
21
class AnnotatedReflectionMethod extends ReflectionMethod
22
{
23
    /**
24
     * Annotation reader
25
     *
26
     * @var Reader
27
     */
28
    private static $annotationReader;
29
30
    /**
31
     * Gets a method annotation.
32
     *
33
     * @param string $annotationName The name of the annotation.
34
     * @return mixed The Annotation or NULL, if the requested annotation does not exist.
35
     */
36
    public function getAnnotation(string $annotationName)
37
    {
38
        return self::getReader()->getMethodAnnotation($this, $annotationName);
39
    }
40
41
    /**
42
     * Gets the annotations applied to a method.
43
     */
44
    public function getAnnotations() : array
45
    {
46
        return self::getReader()->getMethodAnnotations($this);
47
    }
48
49
    /**
50
     * Returns an annotation reader
51
     */
52
    private static function getReader() : Reader
53
    {
54
        if (!self::$annotationReader) {
55
            self::$annotationReader = AspectKernel::getInstance()->getContainer()->get('aspect.annotation.reader');
56
        };
57
58
        return self::$annotationReader;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 7
    public function getClosure($object)
65
    {
66 7
        if (!defined('HHVM_VERSION')) {
67 7
            return parent::getClosure($object);
68
        }
69
70
        $className  = $this->getDeclaringClass()->name;
71
        $methodName = $this->name;
72
        $closure = function (...$args) use ($methodName, $className) {
73
            $result = forward_static_call_array([$className, $methodName], $args);
74
75
            return $result;
76
        };
77
78
        return $closure->bindTo($object, $this->class);
79
    }
80
}
81