Completed
Push — master ( 3bd89b...647639 )
by Cas
14:54
created

Matrix::getColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace CL\Matrix;
4
5
use CL\Matrix\Vector\Column;
6
use CL\Matrix\Vector\Row;
7
8
class Matrix
9
{
10
    /**
11
     * @var Row[]
12
     */
13
    private $rows = [];
14
15
    /**
16
     * @var Column[]
17
     */
18
    private $columns = [];
19
20
    /**
21
     * @param Row[] $rowVectors
22
     */
23
    public function __construct(array $rowVectors = [])
24
    {
25
        foreach ($rowVectors as $rowVector) {
26
            $this->addRow($rowVector);
27
        }
28
    }
29
30
    /**
31
     * @param Row $row
32
     */
33 View Code Duplication
    public function addRow(Row $row)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        array_push($this->rows, $row);
36
37
        $keys = array_keys($this->rows);
38
        $offset = end($keys);
39
40
        $row->setMatrix($this, $offset);
41
    }
42
43
    /**
44
     * @param int $offset
45
     * @param Row $row
46
     */
47
    public function setRow($offset, Row $row)
48
    {
49
        $this->rows[$offset] = $row;
50
    }
51
52
    /**
53
     * @param int $offset
54
     *
55
     * @return Row
56
     */
57 View Code Duplication
    public function getRow($offset)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        if (!array_key_exists($offset, $this->rows)) {
60
            throw new \InvalidArgumentException(sprintf(
61
                'There is no row in this matrix with that offset: %s',
62
                $offset
63
            ));
64
        }
65
66
        return $this->rows[$offset];
67
    }
68
69
    /**
70
     * @return Row[]
71
     */
72
    public function getRows()
73
    {
74
        return $this->rows;
75
    }
76
77
    /**
78
     * @param int $offset
79
     *
80
     * @return bool
81
     */
82
    public function hasRow($offset)
83
    {
84
        return array_key_exists($offset, $this->rows);
85
    }
86
87
    /**
88
     * @param Column $column
89
     */
90 View Code Duplication
    public function addColumn(Column $column)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92
        array_push($this->columns, $column);
93
94
        $keys = array_keys($this->columns);
95
        $offset = end($keys);
96
97
        $column->setMatrix($this, $offset);
98
    }
99
100
    /**
101
     * @param int    $offset
102
     * @param Column $column
103
     */
104
    public function setColumn($offset, Column $column)
105
    {
106
        $this->columns[$offset] = $column;
107
    }
108
109
    /**
110
     * @param int $offset
111
     *
112
     * @return Column
113
     */
114 View Code Duplication
    public function getColumn($offset)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
    {
116
        if (!array_key_exists($offset, $this->columns)) {
117
            throw new \InvalidArgumentException(sprintf(
118
                'There is no column in this matrix with that offset: %s',
119
                $offset
120
            ));
121
        }
122
123
        return $this->columns[$offset];
124
    }
125
126
    /**
127
     * @return Column[]
128
     */
129
    public function getColumns()
130
    {
131
        return $this->columns;
132
    }
133
134
    /**
135
     * @param int $offset
136
     *
137
     * @return bool
138
     */
139
    public function hasColumn($offset)
140
    {
141
        return array_key_exists($offset, $this->columns);
142
    }
143
}
144