1 | <?php |
||
18 | abstract class AbstractQuantity implements QuantityInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var UnitInterface |
||
22 | */ |
||
23 | private $unit; |
||
24 | |||
25 | /** |
||
26 | * @var float|int|string |
||
27 | */ |
||
28 | private $quantity; |
||
29 | |||
30 | /** |
||
31 | * @var UnitInterface |
||
32 | * @var float|int|string $quantity |
||
33 | */ |
||
34 | 8 | private function __construct(UnitInterface $unit, $quantity) |
|
39 | |||
40 | /** |
||
41 | * Creates quantity with same unit. |
||
42 | * Optimized to return this if same quantity. |
||
43 | * @var float|int|string |
||
44 | */ |
||
45 | 3 | final protected function create($quantity) |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 2 | private function getCalculator() |
|
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 2 | final public function getQuantity() |
|
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | 1 | final public function getUnit() |
|
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | 2 | final public function compare(QuantityInterface $other) |
|
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | 1 | final public function equals(QuantityInterface $other) |
|
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | 1 | final public function isPositive() |
|
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | 1 | final public function isNegative() |
|
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | 1 | final public function isConvertible(UnitInterface $unit) |
|
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | 3 | final public function convert(UnitInterface $unit) |
|
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | final public function add(QuantityInterface $addend) |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | final public function subtract(QuantityInterface $subtrahend) |
||
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | final public function multiply($multiplier) |
||
157 | |||
158 | /** |
||
159 | * {@inheritdoc} |
||
160 | */ |
||
161 | final public function divide($divisor) |
||
167 | |||
168 | /** |
||
169 | * {@inheritdoc} |
||
170 | */ |
||
171 | final public function ceil() |
||
177 | |||
178 | /** |
||
179 | * {@inheritdoc} |
||
180 | */ |
||
181 | final public function floor() |
||
187 | |||
188 | /** |
||
189 | * {@inheritdoc} |
||
190 | */ |
||
191 | final public function round($roundingMode) |
||
197 | |||
198 | /** |
||
199 | * {@inheritdoc} |
||
200 | */ |
||
201 | final public function absolute() |
||
207 | |||
208 | 8 | final public static function __callStatic($unit, $args) |
|
212 | |||
213 | /** |
||
214 | * Returns unit for given unit name. |
||
215 | * The only function to change in child classes. |
||
216 | * XXX Should be defined as abstract but `abstract static` is not supported in PHP5. |
||
217 | * @param string $name |
||
218 | * @throws InvalidConfigException |
||
219 | * @return UnitInterface |
||
220 | */ |
||
221 | protected static function findUnit($unit) |
||
225 | } |
||
226 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: