Row   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 69
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 88.24%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 11
c 2
b 1
f 0
lcom 1
cbo 4
dl 69
loc 69
ccs 30
cts 34
cp 0.8824
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setMatrix() 14 14 3
A addElement() 13 13 3
A setElement() 10 10 3
A createFromArray() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Row 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 12
    public function setMatrix(Matrix $matrix, $matrixOffset)
15
    {
16 12
        $this->matrix = $matrix;
17
18 12
        foreach ($this->getElements() as $offset => $element) {
19 4
            if (!$this->matrix->hasColumn($offset)) {
20 4
                $this->matrix->setColumn($offset, new Column([]));
21 4
            }
22
23 4
            $this->matrix->getColumn($offset)->addElement($element);
24 12
        }
25
26 12
        $this->matrixOffset = $matrixOffset;
27 12
    }
28
29
    /**
30
     * @param Element $element
31
     */
32 4
    public function addElement(Element $element)
33
    {
34 4
        array_push($this->elements, $element);
35
36 4
        $keys = array_keys($this->elements);
37 4
        $offset = end($keys);
38
39 4
        if ($this->matrix) {
40 4
            if ($this->matrix->hasColumn($offset)) {
41 2
                $this->matrix->getColumn($offset)->addElement($element);
42 2
            }
43 4
        }
44 4
    }
45
46
    /**
47
     * @param int     $offset
48
     * @param Element $element
49
     */
50 8
    public function setElement($offset, Element $element)
51
    {
52 8
        $this->elements[$offset] = $element;
53
54 8
        if ($this->matrix) {
55
            if ($this->matrix->hasColumn($offset)) {
56
                $this->matrix->getColumn($offset)->setElement($this->matrixOffset, $element);
57
            }
58
        }
59 8
    }
60
61
    /**
62
     * @param mixed[] $values
63
     *
64
     * @return Row
65
     */
66 4
    public static function createFromArray(array $values)
67
    {
68 4
        $vector = new self;
69
70 4
        foreach ($values as $offset => $value) {
71 4
            $vector->setElement($offset, new Element($value));
72 4
        }
73
74 4
        return $vector;
75
    }
76
}
77