Passed
Pull Request — master (#20)
by
unknown
02:56
created

IntMatrix   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A typeToEnforce() 0 3 1
A fromArrayMatrix() 0 3 1
A collectionType() 0 3 1
A isMutable() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
use TypedArrays\AbstractTypedArray;
6
use TypedArrays\Scalars\ImmutableIntegerList;
7
8
require getcwd() . '/vendor/autoload.php';
9
10
final class IntMatrix extends AbstractTypedArray
11
{
12
13
    public static function fromArrayMatrix($input = [])
14
    {
15
        return new self(array_map(static fn ($row) => new ImmutableIntegerList($row), $input));
16
    }
17
18
    protected function typeToEnforce(): string
19
    {
20
        return ImmutableIntegerList::class;
21
    }
22
23
    protected function isMutable(): bool
24
    {
25
        return false;
26
    }
27
28
    protected function collectionType(): string
29
    {
30
        return self::COLLECTION_TYPE_LIST;
31
    }
32
}
33
34
$intRow1 = new ImmutableIntegerList([1, 2, 3]);
35
$intRow2 = new ImmutableIntegerList([4, 5, 6]);
36
$intRow3 = new ImmutableIntegerList([7, 8, 9]);
37
$intMatrix1 = new IntMatrix([$intRow1, $intRow2, $intRow3]);
38
39
var_dump($intMatrix1);
40
41
$intMatrix2 = IntMatrix::fromArrayMatrix([
42
    [1, 2, 3],
43
    [4, 5, 6],
44
    [7, 8, 9],
45
]);
46
47
var_dump($intMatrix2);
48