1 | <?php |
||
23 | class QuantityValue extends UnboundedQuantityValue { |
||
24 | |||
25 | /** |
||
26 | * The quantity's upper bound |
||
27 | * |
||
28 | * @var DecimalValue |
||
29 | */ |
||
30 | private $upperBound; |
||
31 | |||
32 | /** |
||
33 | * The quantity's lower bound |
||
34 | * |
||
35 | * @var DecimalValue |
||
36 | */ |
||
37 | private $lowerBound; |
||
38 | |||
39 | /** |
||
40 | * @param DecimalValue $amount |
||
41 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
42 | * @param DecimalValue $upperBound The upper bound of the quantity, inclusive. |
||
43 | * @param DecimalValue $lowerBound The lower bound of the quantity, inclusive. |
||
44 | * |
||
45 | * @throws IllegalValueException |
||
46 | */ |
||
47 | public function __construct( DecimalValue $amount, $unit, DecimalValue $upperBound, DecimalValue $lowerBound ) { |
||
61 | |||
62 | /** |
||
63 | * Returns a QuantityValue representing the given amount. |
||
64 | * If no upper or lower bound is given, the amount is assumed to be absolutely exact, |
||
65 | * that is, the amount itself will be used as the upper and lower bound. |
||
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.7 |
||
74 | * |
||
75 | * @param string|int|float|DecimalValue|UnboundedQuantityValue $number |
||
76 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
77 | * @param string|int|float|DecimalValue|null $upperBound |
||
78 | * @param string|int|float|DecimalValue|null $lowerBound |
||
79 | * |
||
80 | * @return QuantityValue |
||
81 | * @throws IllegalValueException |
||
82 | */ |
||
83 | public static function newFromNumber( $number, $unit = '1', $upperBound = null, $lowerBound = null ) { |
||
90 | |||
91 | /** |
||
92 | * @see newFromNumber |
||
93 | * |
||
94 | * @deprecated since 0.1, use newFromNumber instead |
||
95 | * |
||
96 | * @param string|int|float|DecimalValue|UnboundedQuantityValue $number |
||
97 | * @param string $unit |
||
98 | * @param string|int|float|DecimalValue|null $upperBound |
||
99 | * @param string|int|float|DecimalValue|null $lowerBound |
||
100 | * |
||
101 | * @return QuantityValue |
||
102 | */ |
||
103 | public static function newFromDecimal( $number, $unit = '1', $upperBound = null, $lowerBound = null ) { |
||
106 | |||
107 | /** |
||
108 | * @see Serializable::unserialize |
||
109 | * |
||
110 | * @since 0.7 |
||
111 | * |
||
112 | * @param string $data |
||
113 | */ |
||
114 | public function unserialize( $data ) { |
||
121 | |||
122 | /** |
||
123 | * Returns this quantity's upper bound. |
||
124 | * |
||
125 | * @since 0.7 |
||
126 | * |
||
127 | * @return DecimalValue |
||
128 | */ |
||
129 | public function getUpperBound() { |
||
132 | |||
133 | /** |
||
134 | * Returns this quantity's lower bound. |
||
135 | * |
||
136 | * @since 0.7 |
||
137 | * |
||
138 | * @return DecimalValue |
||
139 | */ |
||
140 | public function getLowerBound() { |
||
143 | |||
144 | /** |
||
145 | * Returns the size of the uncertainty interval. |
||
146 | * This can roughly be interpreted as "amount +/- uncertainty/2". |
||
147 | * |
||
148 | * The exact interpretation of the uncertainty interval is left to the concrete application or |
||
149 | * data point. For example, the uncertainty interval may be defined to be that part of a |
||
150 | * normal distribution that is required to cover the 95th percentile. |
||
151 | * |
||
152 | * @since 0.7 |
||
153 | * |
||
154 | * @return float |
||
155 | */ |
||
156 | public function getUncertainty() { |
||
159 | |||
160 | /** |
||
161 | * Returns a DecimalValue representing the symmetrical offset to be applied |
||
162 | * to the raw amount for a rough representation of the uncertainty interval, |
||
163 | * as in "amount +/- offset". |
||
164 | * |
||
165 | * The offset is calculated as max( amount - lowerBound, upperBound - amount ). |
||
166 | * |
||
167 | * @since 0.7 |
||
168 | * |
||
169 | * @return DecimalValue |
||
170 | */ |
||
171 | public function getUncertaintyMargin() { |
||
180 | |||
181 | /** |
||
182 | * Returns the order of magnitude of the uncertainty as the exponent of |
||
183 | * last significant digit in the amount-string. The value returned by this |
||
184 | * is suitable for use with @see DecimalMath::roundToExponent(). |
||
185 | * |
||
186 | * @example: if two digits after the decimal point are significant, this |
||
187 | * returns -2. |
||
188 | * |
||
189 | * @example: if the last two digits before the decimal point are insignificant, |
||
190 | * this returns 2. |
||
191 | * |
||
192 | * Note that this calculation assumes a symmetric uncertainty interval, |
||
193 | * and can be misleading. |
||
194 | * |
||
195 | * @since 0.7 |
||
196 | * |
||
197 | * @return int |
||
198 | */ |
||
199 | public function getOrderOfUncertainty() { |
||
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 QuantityValue |
||
248 | */ |
||
249 | public function transform( $newUnit, $transformation ) { |
||
296 | |||
297 | public function __toString() { |
||
304 | |||
305 | /** |
||
306 | * @see DataValue::getArrayValue |
||
307 | * |
||
308 | * @since 0.7 |
||
309 | * |
||
310 | * @return array |
||
311 | */ |
||
312 | public function getArrayValue() { |
||
320 | |||
321 | /** |
||
322 | * Constructs a new instance of the DataValue from the provided data. |
||
323 | * This can round-trip with @see getArrayValue |
||
324 | * |
||
325 | * @since 0.7 |
||
326 | * |
||
327 | * @param mixed $data |
||
328 | * |
||
329 | * @return QuantityValue |
||
330 | * @throws IllegalValueException |
||
331 | */ |
||
332 | public static function newFromArray( $data ) { |
||
347 | |||
348 | } |
||
349 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: