AnnotationsTrait::getAnnotation()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 2
nop 2
crap 3.1406
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