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 | * Constructs a new QuantityValue object, representing the given value. |
||
42 | * |
||
43 | * @since 0.1 |
||
44 | * |
||
45 | * @param DecimalValue $amount |
||
46 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
47 | * |
||
48 | * @throws IllegalValueException |
||
49 | */ |
||
50 | public function __construct( DecimalValue $amount, $unit, $unused = 'nothing' ) { |
||
67 | |||
68 | /** |
||
69 | * Returns a QuantityValue representing the given amount. |
||
70 | * |
||
71 | * This is a convenience wrapper around the constructor that accepts native values |
||
72 | * instead of DecimalValue objects. |
||
73 | * |
||
74 | * @note: if the amount or a bound is given as a string, the string must conform |
||
75 | * to the rules defined by @see DecimalValue. |
||
76 | * |
||
77 | * @since 0.1 |
||
78 | * |
||
79 | * @param string|int|float|DecimalValue $number |
||
80 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
81 | * |
||
82 | * @return self |
||
83 | * @throws IllegalValueException |
||
84 | */ |
||
85 | public static function newFromNumber( $number, $unit = '1' ) { |
||
90 | |||
91 | /** |
||
92 | * @see newFromNumber |
||
93 | * |
||
94 | * @deprecated since 0.1, use newFromNumber instead |
||
95 | * |
||
96 | * @param string|int|float|DecimalValue $number |
||
97 | * @param string $unit |
||
98 | * @param string|int|float|DecimalValue|null $upperBound |
||
|
|||
99 | * @param string|int|float|DecimalValue|null $lowerBound |
||
100 | * |
||
101 | * @return self |
||
102 | */ |
||
103 | public static function newFromDecimal( $number, $unit = '1' ) { |
||
106 | |||
107 | /** |
||
108 | * Converts $number to a DecimalValue if possible and necessary. |
||
109 | * |
||
110 | * @note: if the $number is given as a string, it must conform to the rules |
||
111 | * defined by @see DecimalValue. |
||
112 | * |
||
113 | * @param string $name The variable name to use in exception messages |
||
114 | * @param string|int|float|DecimalValue|null $number |
||
115 | * @param DecimalValue|null $default |
||
116 | * |
||
117 | * @throws IllegalValueException |
||
118 | * @throws InvalidArgumentException |
||
119 | * @return DecimalValue |
||
120 | */ |
||
121 | protected static function asDecimalValue( $name, $number, DecimalValue $default = null ) { |
||
144 | |||
145 | /** |
||
146 | * @see Serializable::serialize |
||
147 | * |
||
148 | * @since 0.1 |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | public function serialize() { |
||
155 | |||
156 | /** |
||
157 | * @see Serializable::unserialize |
||
158 | * |
||
159 | * @since 0.1 |
||
160 | * |
||
161 | * @param string $data |
||
162 | */ |
||
163 | public function unserialize( $data ) { |
||
168 | |||
169 | /** |
||
170 | * @see DataValue::getType |
||
171 | * |
||
172 | * @since 0.1 |
||
173 | * |
||
174 | * @return string |
||
175 | */ |
||
176 | public static function getType() { |
||
179 | |||
180 | /** |
||
181 | * @see DataValue::getSortKey |
||
182 | * |
||
183 | * @since 0.1 |
||
184 | * |
||
185 | * @return float |
||
186 | */ |
||
187 | public function getSortKey() { |
||
190 | |||
191 | /** |
||
192 | * Returns the quantity object. |
||
193 | * @see DataValue::getValue |
||
194 | * |
||
195 | * @since 0.1 |
||
196 | * |
||
197 | * @return self |
||
198 | */ |
||
199 | public function getValue() { |
||
202 | |||
203 | /** |
||
204 | * Returns the amount represented by this quantity. |
||
205 | * |
||
206 | * @since 0.1 |
||
207 | * |
||
208 | * @return DecimalValue |
||
209 | */ |
||
210 | public function getAmount() { |
||
213 | |||
214 | /** |
||
215 | * Returns the unit held by this quantity. |
||
216 | * Unit-less quantities should use "1" as their unit. |
||
217 | * |
||
218 | * @since 0.1 |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | public function getUnit() { |
||
225 | |||
226 | /** |
||
227 | * Returns a transformed value derived from this QuantityValue by applying |
||
228 | * the given transformation to the amount and the upper and lower bounds. |
||
229 | * The resulting amount and bounds are rounded to the significant number of |
||
230 | * digits. Note that for exact quantities (with at least one bound equal to |
||
231 | * the amount), no rounding is applied (since they are considered to have |
||
232 | * infinite precision). |
||
233 | * |
||
234 | * The transformation is provided as a callback, which must implement a |
||
235 | * monotonously increasing, fully differentiable function mapping a DecimalValue |
||
236 | * to a DecimalValue. Typically, it will be a linear transformation applying a |
||
237 | * factor and an offset. |
||
238 | * |
||
239 | * @param string $newUnit The unit of the transformed quantity. |
||
240 | * |
||
241 | * @param callable $transformation A callback that implements the desired transformation. |
||
242 | * The transformation will be called three times, once for the amount, once |
||
243 | * for the lower bound, and once for the upper bound. It must return a DecimalValue. |
||
244 | * The first parameter passed to $transformation is the DecimalValue to transform |
||
245 | * In addition, any extra parameters passed to transform() will be passed through |
||
246 | * to the transformation callback. |
||
247 | * |
||
248 | * @param mixed ... Any extra parameters will be passed to the $transformation function. |
||
249 | * |
||
250 | * @throws InvalidArgumentException |
||
251 | * @return self |
||
252 | */ |
||
253 | public function transform( $newUnit, $transformation ) { |
||
284 | |||
285 | public function __toString() { |
||
289 | |||
290 | /** |
||
291 | * @see DataValue::getArrayValue |
||
292 | * |
||
293 | * @since 0.1 |
||
294 | * |
||
295 | * @return array |
||
296 | */ |
||
297 | public function getArrayValue() { |
||
303 | |||
304 | /** |
||
305 | * Constructs a new instance of the DataValue from the provided data. |
||
306 | * This can round-trip with @see getArrayValue |
||
307 | * |
||
308 | * @since 0.1 |
||
309 | * |
||
310 | * @param mixed $data |
||
311 | * |
||
312 | * @return self |
||
313 | * @throws IllegalValueException |
||
314 | */ |
||
315 | public static function newFromArray( $data ) { |
||
323 | |||
324 | /** |
||
325 | * @see Comparable::equals |
||
326 | * |
||
327 | * @since 0.1 |
||
328 | * |
||
329 | * @param mixed $target |
||
330 | * |
||
331 | * @return bool |
||
332 | */ |
||
333 | public function equals( $target ) { |
||
341 | |||
342 | } |
||
343 |
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.