1 | <?php |
||
12 | class RangedValueResult extends ValueResult |
||
13 | { |
||
14 | /* ----------------------------------------------------------------- |
||
15 | | Constants |
||
16 | | ----------------------------------------------------------------- |
||
17 | */ |
||
18 | |||
19 | public const GROWTH_CONSTANT = 'constant'; |
||
20 | public const GROWTH_INCREASE = 'increase'; |
||
21 | public const GROWTH_DECREASE = 'decrease'; |
||
22 | public const GROWTH_NOT_PRIOR_DATA = 'no_prior_data'; |
||
23 | |||
24 | /* ----------------------------------------------------------------- |
||
25 | | Properties |
||
26 | | ----------------------------------------------------------------- |
||
27 | */ |
||
28 | |||
29 | /** |
||
30 | * The previous property. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | public $previous = [ |
||
35 | 'value' => null, |
||
36 | 'label' => null, |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * The change property. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | public $change = [ |
||
45 | 'value' => null, |
||
46 | 'label' => null, |
||
47 | ]; |
||
48 | |||
49 | /* ----------------------------------------------------------------- |
||
50 | | Getters & Setters |
||
51 | | ----------------------------------------------------------------- |
||
52 | */ |
||
53 | |||
54 | /** |
||
55 | * Set the value. |
||
56 | * |
||
57 | * @param mixed $value |
||
58 | * |
||
59 | * @return $this |
||
60 | */ |
||
61 | 60 | public function value($value) |
|
67 | |||
68 | /** |
||
69 | * Set the previous property. |
||
70 | * |
||
71 | * @param mixed $value |
||
72 | * @param string|null $label |
||
73 | * |
||
74 | * @return $this |
||
75 | */ |
||
76 | 40 | public function previous($value, $label = null) |
|
82 | |||
83 | /** |
||
84 | * Set the change property. |
||
85 | * |
||
86 | * @param mixed $value |
||
87 | * @param string|null $label |
||
88 | * @param string|null $growth |
||
89 | * |
||
90 | * @return $this |
||
91 | */ |
||
92 | 60 | public function change($value, $label = null, $growth = null) |
|
98 | |||
99 | /* ----------------------------------------------------------------- |
||
100 | | Other Methods |
||
101 | | ----------------------------------------------------------------- |
||
102 | */ |
||
103 | |||
104 | /** |
||
105 | * Update the change property. |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | 60 | protected function updateChange() |
|
130 | |||
131 | /** |
||
132 | * Get the instance as an array. |
||
133 | * |
||
134 | * @return array |
||
135 | */ |
||
136 | 16 | public function toArray(): array |
|
143 | |||
144 | /** |
||
145 | * Calculate the change. |
||
146 | * |
||
147 | * @param float|int $current |
||
148 | * @param float|int $previous |
||
149 | * |
||
150 | * @return float|int |
||
151 | */ |
||
152 | 32 | protected static function calculateChange($current, $previous) |
|
163 | } |
||
164 |