Passed
Push — master ( db1fd3...5522e6 )
by Maarten de
03:44 queued 01:33
created

AttributePath::offsetSet()   A

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
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cloudstek\SCIM\FilterParser\AST;
6
7
/**
8
 * Attribute path.
9
 */
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
40
    {
41
        return $this->schema;
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
60
    {
61
        return implode('.', $this->names);
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)
92
    {
93
        throw new \LogicException('Attribute path is read-only.');
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()
108
    {
109
        return new \ArrayIterator($this->names);
110
    }
111
    
112
    public function __toString()
113
    {
114
        return $this->getPath();
115
    }
116
}
117