Completed
Push — multi ( fbc389...652b22 )
by Akihito
02:23
created

ReflectionClass::getAnnotation()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3
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
class ReflectionClass extends \ReflectionClass implements Reader
12
{
13
    /**
14
     * @var WeavedInterface
15
     */
16
    private $object;
17
18
    /**
19
     * Set dependencies
20
     *
21
     * @param WeavedInterface $object
22
     */
23 2
    public function setObject(WeavedInterface $object)
24
    {
25 2
        $this->object = $object;
26 2
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 2
    public function getAnnotations() : array
32
    {
33
        /** @var AbstractWeave $object */
34 2
        $object = $this->object;
35
36 2
        return unserialize($object->classAnnotations);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 2
    public function getAnnotation(string $annotationName)
43
    {
44 2
        $annotations = $this->getAnnotations();
45 2
        foreach ($annotations as $annotation) {
46 1
            if ($annotation instanceof $annotationName) {
47 1
                return $annotation;
48
            }
49
        }
50
51 1
        return null;
52
    }
53
}
54