1 | <?php |
||
24 | class UnboundedQuantityValue 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 ) { |
||
58 | |||
59 | /** |
||
60 | * Returns a QuantityValue representing the given amount. |
||
61 | * |
||
62 | * This is a convenience wrapper around the constructor that accepts native values |
||
63 | * instead of DecimalValue objects. |
||
64 | * |
||
65 | * @note: if the amount or a bound is given as a string, the string must conform |
||
66 | * to the rules defined by @see DecimalValue. |
||
67 | * |
||
68 | * @since 0.1 |
||
69 | * |
||
70 | * @param string|int|float|DecimalValue $number |
||
71 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
72 | * |
||
73 | * @return UnboundedQuantityValue |
||
74 | * @throws IllegalValueException |
||
75 | */ |
||
76 | public static function newFromNumber( $number, $unit = '1' ) { |
||
81 | |||
82 | /** |
||
83 | * @see newFromNumber |
||
84 | * |
||
85 | * @deprecated since 0.1, use newFromNumber instead |
||
86 | * |
||
87 | * @param string|int|float|DecimalValue $number |
||
88 | * @param string $unit |
||
89 | * @param string|int|float|DecimalValue|null $upperBound |
||
|
|||
90 | * @param string|int|float|DecimalValue|null $lowerBound |
||
91 | * |
||
92 | * @return UnboundedQuantityValue |
||
93 | */ |
||
94 | public static function newFromDecimal( $number, $unit = '1' ) { |
||
97 | |||
98 | /** |
||
99 | * Converts $number to a DecimalValue if possible and necessary. |
||
100 | * |
||
101 | * @note: if the $number is given as a string, it must conform to the rules |
||
102 | * defined by @see DecimalValue. |
||
103 | * |
||
104 | * @param string $name The variable name to use in exception messages |
||
105 | * @param string|int|float|DecimalValue|null $number |
||
106 | * @param DecimalValue|null $default |
||
107 | * |
||
108 | * @throws IllegalValueException |
||
109 | * @throws InvalidArgumentException |
||
110 | * @return DecimalValue |
||
111 | */ |
||
112 | protected static function asDecimalValue( $name, $number, DecimalValue $default = null ) { |
||
135 | |||
136 | /** |
||
137 | * @see Serializable::serialize |
||
138 | * |
||
139 | * @since 0.1 |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | public function serialize() { |
||
146 | |||
147 | /** |
||
148 | * @see Serializable::unserialize |
||
149 | * |
||
150 | * @since 0.1 |
||
151 | * |
||
152 | * @param string $data |
||
153 | */ |
||
154 | public function unserialize( $data ) { |
||
159 | |||
160 | /** |
||
161 | * @see DataValue::getType |
||
162 | * |
||
163 | * @since 0.1 |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | public static function getType() { |
||
170 | |||
171 | /** |
||
172 | * @see DataValue::getSortKey |
||
173 | * |
||
174 | * @since 0.1 |
||
175 | * |
||
176 | * @return float |
||
177 | */ |
||
178 | public function getSortKey() { |
||
181 | |||
182 | /** |
||
183 | * Returns the quantity object. |
||
184 | * |
||
185 | *@see DataValue::getValue |
||
186 | * |
||
187 | * @since 0.1 |
||
188 | * |
||
189 | * @return UnboundedQuantityValue |
||
190 | */ |
||
191 | public function getValue() { |
||
194 | |||
195 | /** |
||
196 | * Returns the amount represented by this quantity. |
||
197 | * |
||
198 | * @since 0.1 |
||
199 | * |
||
200 | * @return DecimalValue |
||
201 | */ |
||
202 | public function getAmount() { |
||
205 | |||
206 | /** |
||
207 | * Returns the unit held by this quantity. |
||
208 | * Unit-less quantities should use "1" as their unit. |
||
209 | * |
||
210 | * @since 0.1 |
||
211 | * |
||
212 | * @return string |
||
213 | */ |
||
214 | public function getUnit() { |
||
217 | |||
218 | /** |
||
219 | * Returns a transformed value derived from this QuantityValue by applying |
||
220 | * the given transformation to the amount and the upper and lower bounds. |
||
221 | * The resulting amount and bounds are rounded to the significant number of |
||
222 | * digits. Note that for exact quantities (with at least one bound equal to |
||
223 | * the amount), no rounding is applied (since they are considered to have |
||
224 | * infinite precision). |
||
225 | * |
||
226 | * The transformation is provided as a callback, which must implement a |
||
227 | * monotonously increasing, fully differentiable function mapping a DecimalValue |
||
228 | * to a DecimalValue. Typically, it will be a linear transformation applying a |
||
229 | * factor and an offset. |
||
230 | * |
||
231 | * @param string $newUnit The unit of the transformed quantity. |
||
232 | * |
||
233 | * @param callable $transformation A callback that implements the desired transformation. |
||
234 | * The transformation will be called three times, once for the amount, once |
||
235 | * for the lower bound, and once for the upper bound. It must return a DecimalValue. |
||
236 | * The first parameter passed to $transformation is the DecimalValue to transform |
||
237 | * In addition, any extra parameters passed to transform() will be passed through |
||
238 | * to the transformation callback. |
||
239 | * |
||
240 | * @param mixed ... Any extra parameters will be passed to the $transformation function. |
||
241 | * |
||
242 | * @throws InvalidArgumentException |
||
243 | * @return UnboundedQuantityValue |
||
244 | */ |
||
245 | public function transform( $newUnit, $transformation ) { |
||
276 | |||
277 | public function __toString() { |
||
281 | |||
282 | /** |
||
283 | * @see DataValue::getArrayValue |
||
284 | * |
||
285 | * @since 0.1 |
||
286 | * |
||
287 | * @return array |
||
288 | */ |
||
289 | public function getArrayValue() { |
||
295 | |||
296 | /** |
||
297 | * Constructs a new instance of the DataValue from the provided data. |
||
298 | * This can round-trip with @see getArrayValue |
||
299 | * |
||
300 | * @since 0.1 |
||
301 | * |
||
302 | * @param mixed $data |
||
303 | * |
||
304 | * @return UnboundedQuantityValue |
||
305 | * @throws IllegalValueException |
||
306 | */ |
||
307 | public static function newFromArray( $data ) { |
||
315 | |||
316 | /** |
||
317 | * @see Comparable::equals |
||
318 | * |
||
319 | * @since 0.1 |
||
320 | * |
||
321 | * @param mixed $target |
||
322 | * |
||
323 | * @return bool |
||
324 | */ |
||
325 | public function equals( $target ) { |
||
333 | |||
334 | } |
||
335 |
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.