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

Column::setMatrix()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
rs 9.4285
cc 3
eloc 7
nc 3
nop 2
1
<?php
2
3
namespace CL\Matrix\Vector;
4
5
use CL\Matrix\Element;
6
use CL\Matrix\Matrix;
7
8 View Code Duplication
class Column extends AbstractVector
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    /**
11
     * @param Matrix $matrix
12
     * @param int    $matrixOffset
13
     */
14
    public function setMatrix(Matrix $matrix, $matrixOffset)
15
    {
16
        $this->matrix = $matrix;
17
18
        foreach ($this->getElements() as $offset => $element) {
19
            if (!$this->matrix->hasRow($offset)) {
20
                $this->matrix->setRow($offset, new Row([]));
21
            }
22
23
            $this->matrix->getRow($offset)->addElement($element);
24
        }
25
26
        $this->matrixOffset = $matrixOffset;
27
    }
28
29
    /**
30
     * @param Element $element
31
     */
32
    public function addElement(Element $element)
33
    {
34
        array_push($this->elements, $element);
35
36
        $keys = array_keys($this->elements);
37
        $offset = end($keys);
38
39
        if ($this->matrix) {
40
            if ($this->matrix->hasRow($offset)) {
41
                $this->matrix->getRow($offset)->addElement($element);
42
            }
43
        }
44
    }
45
46
    /**
47
     * @param int     $offset
48
     * @param Element $element
49
     */
50
    public function setElement($offset, Element $element)
51
    {
52
        $this->elements[$offset] = $element;
53
54
        if ($this->matrix) {
55
            if ($this->matrix->hasRow($offset)) {
56
                $this->matrix->getRow($offset)->setElement($this->matrixOffset, $element);
57
            }
58
        }
59
    }
60
}
61