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

IntMatrix::isMutable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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