AIterator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 45
ccs 15
cts 15
cp 1
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 3 1
A count() 0 3 1
A offsetExists() 0 3 1
A getIterator() 0 3 1
A offsetGet() 0 4 2
A offsetUnset() 0 4 2
1
<?php
2
3
namespace kalanis\kw_connect\core;
4
5
6
/**
7
 * Class AIterator
8
 * @package kalanis\kw_connect\core
9
 * Iterate over specific inner variable
10
 */
11
abstract class AIterator implements \ArrayAccess, \IteratorAggregate, \Countable
12
{
13
    /**
14
     * Iterable variable
15
     * @var array<string|int, string|int|float|bool|null>
16
     */
17
    protected array $iterable = [];
18
19
    /**
20
     * Name of iterable variable;
21
     * @return string
22
     */
23
    abstract protected function getIterableName(): string;
24
25 6
    public function getIterator(): \Traversable
26
    {
27 6
        return new \ArrayIterator($this->{$this->getIterableName()});
28
    }
29
30 2
    public function offsetExists($offset): bool
31
    {
32 2
        return isset($this->{$this->getIterableName()}[$offset]);
33
    }
34
35
    #[\ReturnTypeWillChange]
36 1
    public function offsetGet($offset)
37
    {
38 1
        return $this->offsetExists($offset) ? $this->{$this->getIterableName()}[$offset] : null ;
39
    }
40
41 2
    public function offsetSet($offset, $value): void
42
    {
43 2
        $this->{$this->getIterableName()}[$offset] = $value;
44 2
    }
45
46 1
    public function offsetUnset($offset): void
47
    {
48 1
        if ($this->offsetExists($offset)) {
49 1
            unset($this->{$this->getIterableName()}[$offset]);
50
        }
51 1
    }
52
53 2
    public function count(): int
54
    {
55 2
        return count($this->{$this->getIterableName()});
56
    }
57
}
58