Completed
Pull Request — master (#35)
by
unknown
04:33
created

LineChartV2   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 111
Duplicated Lines 6.31 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 7
loc 111
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A addSeries() 0 3 1
A setAxis() 0 5 1
A addLabel() 7 7 2
A getAxis() 0 8 2
A getData() 0 16 4
A setName() 0 4 1
A getName() 0 4 1

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
 * Created by PhpStorm.
4
 * User: Mischa <[email protected]>
5
 * Date: 24/10/2016
6
 * Time: 9:55 AM
7
 */
8
9
namespace CarlosIO\Geckoboard\Widgets;
10
11
use CarlosIO\Geckoboard\Data\LineChartV2\Series;
12
13
/**
14
 * Class LineChartV2
15
 *
16
 * @package CarlosIO\Geckoboard\Widgets
17
 */
18
class LineChartV2 extends Widget
19
{
20
21
    CONST DIMENSION_X = 'x';
22
    CONST DIMENSION_Y = 'y';
23
    CONST DEFAULT_COLOUR = "ff9900";
24
25
    /**
26
     * @var string $name Line Chart Name
27
     */
28
    protected $name;
29
30
    /**
31
     * @var array $data Line Chart Data
32
     */
33
    protected $data;
34
35
36
    /**
37
     * @var array
38
     */
39
    protected $series = array();
40
41
    /**
42
     * @var array
43
     */
44
    protected $axis;
45
46
    public function addSeries($series) {
47
        $this->series[] = $series;
48
    }
49
50
51
    /**
52
     * Set the elements to appear evenly spread along dimension
53
     *
54
     * @param string $dimension The dimension where labels will be displayed
55
     * @param array $labels Labels displayed in this axis
0 ignored issues
show
Bug introduced by
There is no parameter named $labels. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
56
     * @return $this
57
     */
58
    public function setAxis($dimension, $axis) {
59
        $this->axis[$dimension] = $axis;
60
61
        return $this;
62
    }
63
64
    /**
65
     * Add a new label to an specific axis
66
     *
67
     * @param string $dimension The dimension where labels will be displayed
68
     * @param mix    $label     Label displayed in this axis
69
     */
70 View Code Duplication
    protected function addLabel($dimension, $label) {
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...
71
        if (!in_array($dimension, array(self::DIMENSION_X, self::DIMENSION_Y))) {
72
            throw new \InvalidArgumentException(sprintf("Value '%s' is not a valid dimension", $dimension));
73
        }
74
75
        $this->axis[$dimension][] = $label;
76
    }
77
78
    /**
79
     * Return axises in a 2D array
80
     */
81
    public function getAxis() {
82
        if (null === $this->axis) {
83
            $this->axis[self::DIMENSION_X] = new Axis(self::DIMENSION_X);
84
            $this->axis[self::DIMENSION_Y] = new Axis(self::DIMENSION_Y);
85
        }
86
87
        return $this->axis;
88
    }
89
90
    /**
91
     * Get data in array format.
92
     *
93
     * @return array
94
     */
95
    public function getData() {
96
        $result = array();
97
98
        if (!empty($this->axis[self::DIMENSION_X])) {
99
            $result['x_axis'] = $this->axis[self::DIMENSION_X]->toArray();
100
        }
101
102
        if (!empty($this->axis[self::DIMENSION_Y])) {
103
            $result['y_axis'] = $this->axis[self::DIMENSION_Y]->toArray();
104
        }
105
106
        foreach ($this->series as $series) {
107
            $result['series'][] = $series;
108
        }
109
        return $result;
110
    }
111
112
113
    /**
114
     * @param string $name
115
     */
116
    public function setName($name)
117
    {
118
        $this->name = $name;
119
    }
120
121
    /**
122
     * @return string
123
     */
124
    public function getName()
125
    {
126
        return $this->name;
127
    }
128
}
129