AnnotationsTrait::getAnnotations()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Vox\Metadata;
4
5
/**
6
 * Trait to facilitate the annotations read from the metadata drivers
7
 * 
8
 * @author Jhonatan Teixeira <[email protected]>
9
 */
10
trait AnnotationsTrait
11
{
12
    public $annotations;
13
    
14
    public function getAnnotations(): array
15
    {
16
        return $this->annotations;
17
    }
18
19 65
    public function setAnnotations(array $annotations)
20
    {
21 65
        $this->annotations = $annotations;
22
        
23 65
        return $this;
24
    }
25
    
26 61
    public function getAnnotation(string $annotationName, $throwException = false)
27
    {
28 61
        if (!isset($this->annotations[$annotationName]) && $throwException) {
29
            throw new \InvalidArgumentException("no annotation with name $annotationName");
30
        }
31
        
32 61
        return $this->annotations[$annotationName] ?? null;
33
    }
34
    
35 59
    public function hasAnnotation(string $annotationName)
36
    {
37 59
        return isset($this->annotations[$annotationName]);
38
    }
39
}
40