IterableParser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 43
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetUnset() 0 3 1
A offsetSet() 0 8 2
A offsetGet() 0 4 1
A offsetExists() 0 3 1
A getIterator() 0 3 1
1
<?php
2
3
namespace Vanderlee\Comprehend\Parser\Structure;
4
5
use ArrayAccess;
6
use ArrayIterator;
7
use IteratorAggregate;
8
use Vanderlee\Comprehend\Core\ArgumentsTrait;
9
use Vanderlee\Comprehend\Parser\Parser;
10
11
/**
12
 * Abstract class indicating a parser that consists of multiple parsers and can be accessed as an array.
13
 *
14
 * @author Martijn
15
 */
16
abstract class IterableParser extends Parser implements IteratorAggregate, ArrayAccess
17
{
18
    use ArgumentsTrait;
19
20
    /**
21
     * @var Parser[]
22
     */
23
    protected $parsers = [];
24
25
    // implements IteratorAggregate
26
27 1
    public function getIterator()
28
    {
29 1
        return new ArrayIterator($this->parsers);
30
    }
31
32
    // implements ArrayAccess
33
34 2
    public function offsetSet($offset, $value)
35
    {
36 2
        $value = self::getArgument($value);
37
38 2
        if (is_null($offset)) {
39 2
            $this->parsers[] = $value;
40
        } else {
41 1
            $this->parsers[$offset] = $value;
42
        }
43 2
    }
44
45 1
    public function offsetExists($offset)
46
    {
47 1
        return isset($this->parsers[$offset]);
48
    }
49
50 2
    public function offsetUnset($offset)
51
    {
52 2
        unset($this->parsers[$offset]);
53 2
    }
54
55 1
    public function offsetGet($offset)
56
    {
57 1
        return $this->parsers[$offset]
58 1
            ?? null;
59
    }
60
}
61