AbstractConnective::getIterator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cloudstek\SCIM\FilterParser\AST;
6
7
/**
8
 * Abstract connective.
9
 */
10
abstract class AbstractConnective extends AbstractNode implements Connective
11
{
12
    /** @var Node[] */
13
    protected array $nodes;
14
15
    /**
16
     * Logical conjunction (AND).
17
     *
18
     * @param Node[]    $nodes
19
     * @param Node|null $parent
20
     */
21
    public function __construct(array $nodes, ?Node $parent = null)
22
    {
23
        parent::__construct($parent);
24
25
        $this->nodes = $nodes;
26
27
        foreach ($this->nodes as $node) {
28
            $node->setParent($this);
29
        }
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35
    public function getNodes(): array
36
    {
37
        return $this->nodes;
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function offsetExists($offset): bool
44
    {
45
        if (is_int($offset) === false) {
46
            throw new \InvalidArgumentException('Expected numeric offset.');
47
        }
48
49
        return isset($this->nodes[$offset]);
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55
    public function offsetGet($offset): mixed
56
    {
57
        if (is_int($offset) === false) {
58
            throw new \InvalidArgumentException('Expected numeric offset.');
59
        }
60
61
        return $this->nodes[$offset];
62
    }
63
64
    /**
65
     * @inheritDoc
66
     */
67
    public function offsetSet($offset, $value): void
68
    {
69
        throw new \LogicException('Conjunction is read-only.');
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75
    public function offsetUnset($offset): void
76
    {
77
        throw new \LogicException('Conjunction is read-only.');
78
    }
79
80
    /**
81
     * @inheritDoc
82
     */
83
    public function count(): int
84
    {
85
        return count($this->nodes);
86
    }
87
88
    /**
89
     * @inheritDoc
90
     */
91
    public function getIterator(): \Traversable
92
    {
93
        return new \ArrayIterator($this->nodes);
94
    }
95
}
96