ParsedTemplate::getOccurrences()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Template;
6
7
use AbterPhp\Framework\Html\Attribute;
8
9
class ParsedTemplate
10
{
11
    protected string $type;
12
13
    protected string $identifier;
14
15
    /** @var array<string,Attribute> */
16
    protected array $attributes;
17
18
    /** @var string[] */
19
    protected array $occurrences;
20
21
    /**
22
     * ParsedData constructor.
23
     *
24
     * @param string                       $type
25
     * @param string                       $identifier
26
     * @param array<string,Attribute>|null $attributes
27
     * @param string[]                     $occurrences
28
     */
29
    public function __construct(
30
        string $type,
31
        string $identifier,
32
        ?array $attributes = null,
33
        array $occurrences = []
34
    ) {
35
        $this->type        = $type;
36
        $this->identifier  = $identifier;
37
        $this->attributes  = $attributes ?? [];
38
        $this->occurrences = $occurrences;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getType(): string
45
    {
46
        return $this->type;
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getIdentifier(): string
53
    {
54
        return $this->identifier;
55
    }
56
57
    /**
58
     * @return array<string,Attribute>
59
     */
60
    public function getAttributes(): array
61
    {
62
        return $this->attributes;
63
    }
64
65
    /**
66
     * @param string      $key
67
     * @param string|null $default
68
     *
69
     * @return string|null
70
     */
71
    public function getAttributeValue(string $key, ?string $default = null): ?string
72
    {
73
        if (isset($this->attributes[$key])) {
74
            return $this->attributes[$key]->getValue();
75
        }
76
77
        return $default;
78
    }
79
80
    /**
81
     * @param string $occurrence
82
     *
83
     * @return ParsedTemplate
84
     */
85
    public function addOccurrence(string $occurrence): ParsedTemplate
86
    {
87
        $this->occurrences[] = $occurrence;
88
89
        return $this;
90
    }
91
92
    /**
93
     * @return string[]
94
     */
95
    public function getOccurrences(): array
96
    {
97
        return $this->occurrences;
98
    }
99
}
100