Completed
Pull Request — 2.x (#79)
by Akihito
02:22
created

ReflectionMethod   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 61
ccs 18
cts 20
cp 0.9
rs 10

4 Methods

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