Completed
Push — cs ( 9c9fc7 )
by Akihito
01:43
created

ReflectionMethod   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 17.39%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 62
ccs 4
cts 23
cp 0.1739
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setObject() 0 5 1
A getDeclaringClass() 0 12 2
A getAnnotations() 0 11 2
A getAnnotation() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Aop;
6
7
final class ReflectionMethod extends \ReflectionMethod implements Reader
8
{
9
    /**
10
     * @var WeavedInterface
11
     */
12
    private $object;
13
14
    /**
15
     * @var string
16
     */
17
    private $method;
18
19
    /**
20
     * Set dependencies
21
     */
22 1
    public function setObject(WeavedInterface $object, \ReflectionMethod $method)
23
    {
24 1
        $this->object = $object;
25 1
        $this->method = $method->name;
26 1
    }
27
28
    public function getDeclaringClass() : ReflectionClass
29
    {
30
        $parencClass = (new \ReflectionClass($this->object))->getParentClass();
31
        if (! $parencClass instanceof \ReflectionClass) {
32
            throw new \LogicException; // @codeCoverageIgnore
33
        }
34
        $originalClass = $parencClass->name;
35
        $class = new ReflectionClass($originalClass);
36
        $class->setObject($this->object);
37
38
        return $class;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getAnnotations() : array
45
    {
46
        /** @var AbstractWeave $object */
47
        $object = $this->object;
48
        $annotations = unserialize($object->methodAnnotations);
49
        if (array_key_exists($this->method, $annotations)) {
50
            return $annotations[$this->method];
51
        }
52
53
        return [];
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getAnnotation(string $annotationName)
60
    {
61
        $annotations = $this->getAnnotations();
62
        foreach ($annotations as $annotation) {
63
            if ($annotation instanceof $annotationName) {
64
                return $annotation;
65
            }
66
        }
67
    }
68
}
69