1 | <?php |
||
24 | class QuantityValue extends DataValueObject { |
||
25 | |||
26 | /** |
||
27 | * The quantity's amount |
||
28 | * |
||
29 | * @var DecimalValue |
||
30 | */ |
||
31 | protected $amount; |
||
32 | |||
33 | /** |
||
34 | * The quantity's unit identifier (use "1" for unitless quantities). |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $unit; |
||
39 | |||
40 | /** |
||
41 | * @param DecimalValue $amount |
||
42 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
43 | * |
||
44 | * @throws IllegalValueException |
||
45 | */ |
||
46 | public function __construct( DecimalValue $amount, $unit, $unused = 'nothing' ) { |
||
63 | |||
64 | /** |
||
65 | * Returns a QuantityValue representing the given amount. |
||
66 | * |
||
67 | * This is a convenience wrapper around the constructor that accepts native values |
||
68 | * instead of DecimalValue objects. |
||
69 | * |
||
70 | * @note: if the amount or a bound is given as a string, the string must conform |
||
71 | * to the rules defined by @see DecimalValue. |
||
72 | * |
||
73 | * @since 0.1 |
||
74 | * |
||
75 | * @param string|int|float|DecimalValue $number |
||
76 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
77 | * |
||
78 | * @return self |
||
79 | * @throws IllegalValueException |
||
80 | */ |
||
81 | public static function newFromNumber( $number, $unit = '1' ) { |
||
86 | |||
87 | /** |
||
88 | * @see newFromNumber |
||
89 | * |
||
90 | * @deprecated since 0.1, use newFromNumber instead |
||
91 | * |
||
92 | * @param string|int|float|DecimalValue $number |
||
93 | * @param string $unit |
||
94 | * @param string|int|float|DecimalValue|null $upperBound |
||
|
|||
95 | * @param string|int|float|DecimalValue|null $lowerBound |
||
96 | * |
||
97 | * @return self |
||
98 | */ |
||
99 | public static function newFromDecimal( $number, $unit = '1' ) { |
||
102 | |||
103 | /** |
||
104 | * Converts $number to a DecimalValue if possible and necessary. |
||
105 | * |
||
106 | * @note: if the $number is given as a string, it must conform to the rules |
||
107 | * defined by @see DecimalValue. |
||
108 | * |
||
109 | * @param string $name The variable name to use in exception messages |
||
110 | * @param string|int|float|DecimalValue|null $number |
||
111 | * @param DecimalValue|null $default |
||
112 | * |
||
113 | * @throws IllegalValueException |
||
114 | * @throws InvalidArgumentException |
||
115 | * @return DecimalValue |
||
116 | */ |
||
117 | protected static function asDecimalValue( $name, $number, DecimalValue $default = null ) { |
||
140 | |||
141 | /** |
||
142 | * @see Serializable::serialize |
||
143 | * |
||
144 | * @since 0.1 |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public function serialize() { |
||
151 | |||
152 | /** |
||
153 | * @see Serializable::unserialize |
||
154 | * |
||
155 | * @since 0.1 |
||
156 | * |
||
157 | * @param string $data |
||
158 | */ |
||
159 | public function unserialize( $data ) { |
||
164 | |||
165 | /** |
||
166 | * @see DataValue::getType |
||
167 | * |
||
168 | * @since 0.1 |
||
169 | * |
||
170 | * @return string |
||
171 | */ |
||
172 | public static function getType() { |
||
175 | |||
176 | /** |
||
177 | * @see DataValue::getSortKey |
||
178 | * |
||
179 | * @since 0.1 |
||
180 | * |
||
181 | * @return float |
||
182 | */ |
||
183 | public function getSortKey() { |
||
186 | |||
187 | /** |
||
188 | * Returns the quantity object. |
||
189 | * @see DataValue::getValue |
||
190 | * |
||
191 | * @since 0.1 |
||
192 | * |
||
193 | * @return self |
||
194 | */ |
||
195 | public function getValue() { |
||
198 | |||
199 | /** |
||
200 | * Returns the amount represented by this quantity. |
||
201 | * |
||
202 | * @since 0.1 |
||
203 | * |
||
204 | * @return DecimalValue |
||
205 | */ |
||
206 | public function getAmount() { |
||
209 | |||
210 | /** |
||
211 | * Returns the unit held by this quantity. |
||
212 | * Unit-less quantities should use "1" as their unit. |
||
213 | * |
||
214 | * @since 0.1 |
||
215 | * |
||
216 | * @return string |
||
217 | */ |
||
218 | public function getUnit() { |
||
221 | |||
222 | /** |
||
223 | * Returns a transformed value derived from this QuantityValue by applying |
||
224 | * the given transformation to the amount and the upper and lower bounds. |
||
225 | * The resulting amount and bounds are rounded to the significant number of |
||
226 | * digits. Note that for exact quantities (with at least one bound equal to |
||
227 | * the amount), no rounding is applied (since they are considered to have |
||
228 | * infinite precision). |
||
229 | * |
||
230 | * The transformation is provided as a callback, which must implement a |
||
231 | * monotonously increasing, fully differentiable function mapping a DecimalValue |
||
232 | * to a DecimalValue. Typically, it will be a linear transformation applying a |
||
233 | * factor and an offset. |
||
234 | * |
||
235 | * @param string $newUnit The unit of the transformed quantity. |
||
236 | * |
||
237 | * @param callable $transformation A callback that implements the desired transformation. |
||
238 | * The transformation will be called three times, once for the amount, once |
||
239 | * for the lower bound, and once for the upper bound. It must return a DecimalValue. |
||
240 | * The first parameter passed to $transformation is the DecimalValue to transform |
||
241 | * In addition, any extra parameters passed to transform() will be passed through |
||
242 | * to the transformation callback. |
||
243 | * |
||
244 | * @param mixed ... Any extra parameters will be passed to the $transformation function. |
||
245 | * |
||
246 | * @throws InvalidArgumentException |
||
247 | * @return self |
||
248 | */ |
||
249 | public function transform( $newUnit, $transformation ) { |
||
280 | |||
281 | public function __toString() { |
||
285 | |||
286 | /** |
||
287 | * @see DataValue::getArrayValue |
||
288 | * |
||
289 | * @since 0.1 |
||
290 | * |
||
291 | * @return array |
||
292 | */ |
||
293 | public function getArrayValue() { |
||
299 | |||
300 | /** |
||
301 | * Constructs a new instance of the DataValue from the provided data. |
||
302 | * This can round-trip with @see getArrayValue |
||
303 | * |
||
304 | * @since 0.1 |
||
305 | * |
||
306 | * @param mixed $data |
||
307 | * |
||
308 | * @return self |
||
309 | * @throws IllegalValueException |
||
310 | */ |
||
311 | public static function newFromArray( $data ) { |
||
319 | |||
320 | /** |
||
321 | * @see Comparable::equals |
||
322 | * |
||
323 | * @since 0.1 |
||
324 | * |
||
325 | * @param mixed $target |
||
326 | * |
||
327 | * @return bool |
||
328 | */ |
||
329 | public function equals( $target ) { |
||
337 | |||
338 | } |
||
339 |
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 methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.