AbstractInfo::getAnnotations()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Saxulum\AnnotationManager\Helper;
4
5
abstract class AbstractInfo
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $name;
11
12
    /**
13
     * @var array
14
     */
15
    protected $annotations;
16
17
    /**
18
     * @param string $name
19
     * @param array  $annotations
20
     */
21
    public function __construct($name, array $annotations = array())
22
    {
23
        $this->name = $name;
24
        $this->annotations = $annotations;
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function getName()
31
    {
32
        return $this->name;
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function getAnnotations()
39
    {
40
        return $this->annotations;
41
    }
42
43
    /**
44
     * @param  string $className
45
     * @return array
46
     */
47
    public function getAnnotationsInstanceof($className)
48
    {
49
        $annotationsInstanceOf = array();
50
        foreach ($this->getAnnotations() as $annotation) {
51
            if ($annotation instanceof $className) {
52
                $annotationsInstanceOf[] = $annotation;
53
            }
54
        }
55
56
        return $annotationsInstanceOf;
57
    }
58
59
    /**
60
     * @param  string      $className
61
     * @return null|object
62
     */
63
    public function getFirstAnnotationInstanceof($className)
64
    {
65
        foreach ($this->getAnnotations() as $annotation) {
66
            if ($annotation instanceof $className) {
67
                return $annotation;
68
            }
69
        }
70
71
        return null;
72
    }
73
}
74