Completed
Push — cs ( 9c9fc7...96045f )
by Akihito
02:05
created

ReflectionMethod::setObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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 3
    public function setObject(WeavedInterface $object, \ReflectionMethod $method)
23
    {
24 3
        $this->object = $object;
25 3
        $this->method = $method->name;
26 3
    }
27
28 2
    public function getDeclaringClass() : ReflectionClass
29
    {
30 2
        $parencClass = (new \ReflectionClass($this->object))->getParentClass();
31 2
        if (! $parencClass instanceof \ReflectionClass) {
32
            throw new \LogicException; // @codeCoverageIgnore
33
        }
34 2
        $originalClass = $parencClass->name;
35 2
        $class = new ReflectionClass($originalClass);
36 2
        $class->setObject($this->object);
37
38 2
        return $class;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function getAnnotations() : array
45
    {
46
        /** @var AbstractWeave $object */
47 2
        $object = $this->object;
48 2
        $annotations = unserialize($object->methodAnnotations);
49 2
        if (array_key_exists($this->method, $annotations)) {
50 1
            return $annotations[$this->method];
51
        }
52
53 1
        return [];
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 2
    public function getAnnotation(string $annotationName)
60
    {
61 2
        $annotations = $this->getAnnotations();
62 2
        foreach ($annotations as $annotation) {
63 1
            if ($annotation instanceof $annotationName) {
64 1
                return $annotation;
65
            }
66
        }
67 1
    }
68
}
69