Completed
Push — master ( 7762ce...618a95 )
by Hannes
02:39
created

Definition   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 59
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCodeBlock() 0 4 1
A getAnnotations() 0 4 1
A getAnnotation() 0 10 3
A isAnnotatedWith() 0 10 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\readmetester;
6
7
/**
8
 * Wrapper around the code and annotations defining an example
9
 */
10
class Definition
11
{
12
    /**
13
     * @var Annotation[] The set of annotations
14
     */
15
    private $annotations;
16
17
    /**
18
     * @var CodeBlock Example code
19
     */
20
    private $code;
21
22
    public function __construct(CodeBlock $code, Annotation ...$annotations)
23
    {
24
        $this->code = $code;
25
        $this->annotations = $annotations;
26
    }
27
28
    public function getCodeBlock(): CodeBlock
29
    {
30
        return $this->code;
31
    }
32
33
    /**
34
     * @return Annotation[]
35
     */
36
    public function getAnnotations(): array
37
    {
38
        return $this->annotations;
39
    }
40
41
    /**
42
     * Get annotation matching $name
43
     */
44
    public function getAnnotation(string $name): Annotation
45
    {
46
        foreach ($this->getAnnotations() as $annotation) {
47
            if ($annotation->isNamed($name)) {
48
                return $annotation;
49
            }
50
        }
51
52
        throw new \LogicException("Annotation $name does not exist");
53
    }
54
55
    /**
56
     * Check if annotation $name exists
57
     */
58
    public function isAnnotatedWith(string $name): bool
59
    {
60
        foreach ($this->getAnnotations() as $annotation) {
61
            if ($annotation->isNamed($name)) {
62
                return true;
63
            }
64
        }
65
66
        return false;
67
    }
68
}
69