Completed
Push — master ( d4f643...31fba3 )
by JHONATAN
02:46
created

AnnotationsTrait   A

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 setAnnotations() 0 5 1
A getAnnotations() 0 3 1
A getAnnotation() 0 7 3
A hasAnnotation() 0 3 1
1
<?php
2
3
namespace Vox\Metadata;
4
5
trait AnnotationsTrait
6
{
7
    private $annotations;
8
    
9
    public function getAnnotations(): array
10
    {
11
        return $this->annotations;
12
    }
13
14 16
    public function setAnnotations(array $annotations)
15
    {
16 16
        $this->annotations = $annotations;
17
        
18 16
        return $this;
19
    }
20
    
21 14
    public function getAnnotation(string $annotationName, $throwException = false)
22
    {
23 14
        if (!isset($this->annotations[$annotationName]) && $throwException) {
24
            throw new \InvalidArgumentException("no annotation with name $annotationName");
25
        }
26
        
27 14
        return $this->annotations[$annotationName] ?? null;
28
    }
29
    
30 11
    public function hasAnnotation(string $annotationName)
31
    {
32 11
        return isset($this->annotations[$annotationName]);
33
    }
34
}
35