AnnotationsTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 28
ccs 8
cts 11
cp 0.7272
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasAnnotation() 0 3 1
A setAnnotations() 0 5 1
A getAnnotation() 0 7 3
A getAnnotations() 0 3 1
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