ArrayMap::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 5
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Diacdg\TypedArray;
4
5
class ArrayMap extends AbstractTypedArray
6
{
7
    protected $offsetType;
8
    
9 6
    public function __construct(string $offsetType, string $valueType, array $array = [], int $flags = 0, string $iteratorClass = "ArrayIterator")
10
    {
11 6
        $this->offsetType = $offsetType;
12 6
        $offsetAcceptedTypes = ['integer', 'string'];
13 6
        if (!in_array(strtolower($offsetType), $offsetAcceptedTypes)) {
14 1
            throw new \InvalidArgumentException('Offest type must be of type: ' . implode(', ', $offsetAcceptedTypes) . '.');
15
        }
16
17 5
        parent::__construct($valueType, $array, $flags, $iteratorClass);
18 5
    }
19
20 4
    protected function checkOffset($offset): void
21
    {
22 4
        if (gettype($offset) !== strtolower($this->offsetType)) {
23 1
            throw new \InvalidArgumentException('Offest must be of type: ' . $this->offsetType . '.');
24
        }
25
    }
26
}