Completed
Push — master ( eff997...1abf17 )
by Mathieu
03:34
created

AbstractGraphWidget::setColors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Charcoal\Admin\Widget\Graph;
4
5
// From `charcoal-admin`
6
use \Charcoal\Admin\AdminWidget;
7
8
use \Charcoal\Admin\Widget\Graph\GraphWidgetInterface;
9
10
/**
11
 * Base Graph widget
12
 */
13
abstract class AbstractGraphWidget extends AdminWidget implements GraphWidgetInterface
14
{
15
    /**
16
     * @var mixed $height
17
     */
18
    protected $height = 400;
19
    /**
20
     * @var array $colors
21
     */
22
    protected $colors;
23
24
    /**
25
     * @param mixed $height
26
     * @return GraphWidgetInterface Chainable
27
     */
28
    public function setHeight($height)
29
    {
30
        $this->height = $height;
31
        return $this;
32
    }
33
34
    /**
35
     * @return mixed
36
     */
37
    public function height()
38
    {
39
        return $this->height;
40
    }
41
42
    /**
43
     * @param string[] $colors
44
     * @return GraphWidgetInterface Chainable
45
     */
46
    public function setColors(array $colors)
47
    {
48
        $this->colors = $colors;
49
        return $this;
50
    }
51
52
    /**
53
     *
54
     */
55 View Code Duplication
    public function colors()
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...
56
    {
57
        if ($this->colors === null || empty($this->colors)) {
58
            $this->colors = $this->defaultColors();
59
        }
60
        return $this->colors;
61
    }
62
63
    /**
64
     * @todo Read from widget metadata
65
     */
66 View Code Duplication
    public function defaultColors()
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...
67
    {
68
        return [
69
            '#ed5564',
70
            '#337ab7',
71
            '#da70d6',
72
            '#32cd32',
73
            '#6495ed',
74
            '#ff69b4',
75
            '#ba55d3',
76
            '#cd5c5c',
77
            '#ffa500',
78
            '#40e0d0',
79
            '#1e90ff',
80
            '#ff6347',
81
            '#7b68ee',
82
            '#00fa9a',
83
            '#ffd700',
84
            '#6b8e23',
85
            '#ff00ff',
86
            '#3cb371',
87
            '#b8860b',
88
            '#30e0e0'
89
        ];
90
    }
91
92
    /**
93
     * @return array Categories structure.
94
     */
95
    abstract public function categories();
96
97
    /**
98
     * @return string JSONified categories structure.
99
     */
100
    public function seriesJson()
101
    {
102
        return json_encode($this->series());
103
    }
104
105
    /**
106
     * @return array Series structure.
107
     */
108
    abstract public function series();
109
110
    /**
111
     * @return string JSONified categories structure.
112
     */
113
    public function categoriesJson()
114
    {
115
        return json_encode($this->categories());
116
    }
117
}
118