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

Series::setIncompleteFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Mischa <[email protected]>
5
 * Date: 24/10/2016
6
 * Time: 9:49 AM
7
 */
8
9
namespace CarlosIO\Geckoboard\Data\LineChartV2;
10
11
/**
12
 * Class Series
13
 *
14
 * @package CarlosIO\Geckoboard\Data\LineChartV2
15
 */
16
class Series
17
{
18
19
    /**
20
     * @var string
21
     */
22
    protected $label;
23
24
    /**
25
     * @var
26
     */
27
    protected $value;
28
29
    /**
30
     * @var array
31
     */
32
    public $data;
33
34
    /**
35
     * @var string
36
     */
37
    public $name;
38
39
    /**
40
     * @var
41
     */
42
    public $incompleteFrom = null;
43
44
    /**
45
     * @var
46
     * Can be either "main", or "secondary"
47
     *  defaults to "main" if not specified.
48
     */
49
    protected $type = "main";
50
    private $yRequired = false;
51
    private $size = 0;
52
53
    public function setName($name) {
54
        $this->name = $name;
55
    }
56
57
    public function setIncompleteFrom($incompleteFrom) {
58
        $this->incompleteFrom = $incompleteFrom;
59
    }
60
61
    public function addData($x, $y = null) {
62
        if ($y !== null) {
63
            $this->yRequired = true;
64
            $data = array($x, (float) $y);
65
        } else if ($this->yRequired === true) {
66
            throw new Exception("Y Data is required for this series of data as it has been used before");
67
        } else {
68
            $data = $x;
69
        }
70
        $this->data[] = $data;
71
        $this->size++;
72
        return $this;
73
    }
74
75
    public function length() {
76
        return $this->size;
77
    }
78
79
    public function getData() {
80
        return $this->data;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getLabel() {
87
        return $this->label;
88
    }
89
    /**
90
     * @param $label
91
     * @return $this
92
     */
93
    public function setLabel($label) {
94
        $this->label = $label;
95
96
        return $this;
97
    }
98
99
    /**
100
     * @return float
101
     */
102
    public function getValue() {
103
        return $this->value;
104
    }
105
106
    /**
107
     * @param $value
108
     * @return $this
109
     */
110
    public function setValue($value) {
111
        $this->value = $value;
112
113
        return $this;
114
    }
115
116
    /**
117
     * @return int
118
     */
119
    public function getPreviousRank() {
120
        return $this->previousRank;
0 ignored issues
show
Bug introduced by
The property previousRank does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
121
    }
122
123
    /**
124
     * @param $previousRank
125
     * @return $this
126
     */
127
    public function setPreviousRank($previousRank) {
128
        $this->previousRank = $previousRank;
129
130
        return $this;
131
    }
132
133
    /**
134
     * @return array
135
     */
136
    public function toArray() {
137
        $result = array();
138
        $result['name'] = $this->getName();
0 ignored issues
show
Bug introduced by
The method getName() does not seem to exist on object<CarlosIO\Geckoboa...ata\LineChartV2\Series>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
139
        $result['data'] = $this->getData();
140
        if($this->incompleteFrom !== null) {
141
            $result['incomplete_from'] = $this->incompleteFrom;
142
        }
143
144
        return $result;
145
    }
146
147
}