AIterator::offsetExists()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
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