Passed
Push — main ( 3c0f49...2c259b )
by Peter
04:10
created

ParsedTemplate   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 87
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdentifier() 0 3 1
A getAttributes() 0 3 1
A __construct() 0 6 1
A getType() 0 3 1
A getAttribute() 0 7 2
A getOccurrences() 0 3 1
A addOccurrence() 0 5 1
1
<?php
2
3
namespace AbterPhp\Framework\Template;
4
5
class ParsedTemplate
6
{
7
    /** @var string */
8
    protected string $type;
9
10
    /** @var string */
11
    protected string $identifier;
12
13
    /** @var string[] */
14
    protected array $attributes;
15
16
    /** @var string[] */
17
    protected array $occurrences;
18
19
    /**
20
     * ParsedData constructor.
21
     *
22
     * @param string   $type
23
     * @param string   $identifier
24
     * @param string[] $attributes
25
     * @param string[] $occurences
26
     */
27
    public function __construct(string $type, string $identifier, array $attributes = [], array $occurences = [])
28
    {
29
        $this->type       = $type;
30
        $this->identifier = $identifier;
31
        $this->attributes = $attributes;
32
        $this->occurrences = $occurences;
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getType(): string
39
    {
40
        return $this->type;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getIdentifier(): string
47
    {
48
        return $this->identifier;
49
    }
50
51
    /**
52
     * @return string[]
53
     */
54
    public function getAttributes(): array
55
    {
56
        return $this->attributes;
57
    }
58
59
    /**
60
     * @param string      $attribute
61
     * @param string|null $default
62
     *
63
     * @return string|null
64
     */
65
    public function getAttribute(string $attribute, ?string $default = null): ?string
66
    {
67
        if (array_key_exists($attribute, $this->attributes)) {
68
            return $this->attributes[$attribute];
69
        }
70
71
        return $default;
72
    }
73
74
    /**
75
     * @param string $occurrence
76
     *
77
     * @return ParsedTemplate
78
     */
79
    public function addOccurrence(string $occurrence): ParsedTemplate
80
    {
81
        $this->occurrences[] = $occurrence;
82
83
        return $this;
84
    }
85
86
    /**
87
     * @return string[]
88
     */
89
    public function getOccurrences(): array
90
    {
91
        return $this->occurrences;
92
    }
93
}
94