Total Complexity | 12 |
Total Lines | 105 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class AttributePath implements \ArrayAccess, \IteratorAggregate, \Countable |
||
11 | { |
||
12 | private ?string $schema; |
||
13 | |||
14 | private array $names; |
||
15 | |||
16 | /** |
||
17 | * Attribute path. |
||
18 | * |
||
19 | * @param string $schema |
||
20 | * @param string[] $names |
||
21 | * |
||
22 | * @throws \InvalidArgumentException On empty array of names. |
||
23 | */ |
||
24 | public function __construct(?string $schema, array $names) |
||
25 | { |
||
26 | if (empty($names)) { |
||
27 | throw new \InvalidArgumentException('Attribute path should contain at least one attribute name.'); |
||
28 | } |
||
29 | |||
30 | $this->schema = $schema; |
||
31 | $this->names = $names; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Get schema URI. |
||
36 | * |
||
37 | * @return string|null |
||
38 | */ |
||
39 | public function getSchema(): ?string |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Get names. |
||
46 | * |
||
47 | * @return string[] |
||
48 | */ |
||
49 | public function getNames(): array |
||
50 | { |
||
51 | return $this->names; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Get attribute names as dotted path notation. |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getPath(): string |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @inheritDoc |
||
66 | */ |
||
67 | public function offsetExists($offset) |
||
68 | { |
||
69 | return isset($this->names[$offset]); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @inheritDoc |
||
74 | */ |
||
75 | public function offsetGet($offset) |
||
76 | { |
||
77 | return $this->names[$offset]; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @inheritDoc |
||
82 | */ |
||
83 | public function offsetSet($offset, $value) |
||
84 | { |
||
85 | throw new \LogicException('Attribute path is read-only.'); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @inheritDoc |
||
90 | */ |
||
91 | public function offsetUnset($offset) |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * @inheritDoc |
||
98 | */ |
||
99 | public function count() |
||
100 | { |
||
101 | return count($this->names); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @inheritDoc |
||
106 | */ |
||
107 | public function getIterator() |
||
110 | } |
||
111 | |||
112 | public function __toString() |
||
115 | } |
||
116 | } |
||
117 |