ShapeTrait::transpose()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
eloc 1
nc 1
nop 0
1
<?php
2
3
4
namespace Samsara\Fermat\LinearAlgebra\Types\Traits\Matrix;
5
6
7
use Samsara\Fermat\LinearAlgebra\Types\Base\Interfaces\Groups\MatrixInterface;
8
use Samsara\Fermat\Core\Types\NumberCollection;
9
10
trait ShapeTrait
11
{
12
13
    /** @var NumberCollection[] */
14
    protected $rows;
15
    /** @var NumberCollection[] */
16
    protected $columns;
17
    /** @var int */
18
    protected $numRows;
19
    /** @var int */
20
    protected $numColumns;
21
22
    /**
23
     * @return bool
24
     */
25 8
    public function isSquare(): bool
26
    {
27 8
        return $this->getRowCount() === $this->getColumnCount();
28
    }
29
30
    /**
31
     * @return int
32
     */
33 30
    public function getRowCount(): int
34
    {
35 30
        return $this->numRows;
36
    }
37
38
    /**
39
     * @param int $row
40
     * @return NumberCollection
41
     */
42 34
    public function getRow(int $row): NumberCollection
43
    {
44 34
        return clone $this->rows[$row];
45
    }
46
47
    /**
48
     * @return int
49
     */
50 30
    public function getColumnCount(): int
51
    {
52 30
        return $this->numColumns;
53
    }
54
55
    /**
56
     * @param int $column
57
     * @return NumberCollection
58
     */
59 2
    public function getColumn(int $column): NumberCollection
60
    {
61 2
        return clone $this->columns[$column];
62
    }
63
64
    /**
65
     * @return MatrixInterface
66
     */
67
    public function getAdjoint(): MatrixInterface
68
    {
69
        $rows = $this->columns;
70
71
        return $this->setValue($rows);
0 ignored issues
show
Bug introduced by
It seems like setValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        return $this->/** @scrutinizer ignore-call */ setValue($rows);
Loading history...
72
    }
73
74
    /**
75
     * @return MatrixInterface
76
     */
77
    public function getAdjugate(): MatrixInterface
78
    {
79
        return $this->getAdjoint();
80
    }
81
82
    /**
83
     * @return MatrixInterface
84
     */
85
    public function transpose(): MatrixInterface
86
    {
87
        return $this->getAdjoint();
88
    }
89
90
    /**
91
     * @param bool $clockwise
92
     * @return MatrixInterface
93
     */
94 2
    public function rotate(bool $clockwise = true): MatrixInterface
95
    {
96 2
        $tempData =  $clockwise ? $this->rows :  $this->columns;
97 2
        $mode = $clockwise ? self::MODE_COLUMNS_INPUT : self::MODE_ROWS_INPUT;
0 ignored issues
show
Bug introduced by
The constant Samsara\Fermat\LinearAlg...eTrait::MODE_ROWS_INPUT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant Samsara\Fermat\LinearAlg...ait::MODE_COLUMNS_INPUT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
98
99 2
        $tempData = array_reverse($tempData);
100
101 2
        return $this->setValue($tempData, $mode);
102
    }
103
104
}