Completed
Pull Request — 2.x (#349)
by Alexander
02:20
created

AnnotatedReflectionProperty   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 40
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAnnotation() 0 4 1
A getAnnotations() 0 4 1
A getReader() 0 8 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 ReflectionProperty;
17
18
/**
19
 * Extended version of ReflectionProperty with annotation support
20
 */
21
class AnnotatedReflectionProperty extends ReflectionProperty implements AnnotationAccess
22
{
23
    /**
24
     * Annotation reader
25
     *
26
     * @var Reader
27
     */
28
    private static $annotationReader;
29
30
    /**
31
     * Gets property 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()->getPropertyAnnotation($this, $annotationName);
39
    }
40
41
    /**
42
     * Gets the annotations applied to a property.
43
     */
44
    public function getAnnotations(): array
45
    {
46
        return self::getReader()->getPropertyAnnotations($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