1 | <?php |
||
19 | class BoundedQuantityValue extends QuantityValue { |
||
20 | |||
21 | /** |
||
22 | * The quantity's upper bound |
||
23 | * |
||
24 | * @var DecimalValue |
||
25 | */ |
||
26 | private $upperBound; |
||
27 | |||
28 | /** |
||
29 | * The quantity's lower bound |
||
30 | * |
||
31 | * @var DecimalValue |
||
32 | */ |
||
33 | private $lowerBound; |
||
34 | |||
35 | /** |
||
36 | * Constructs a new QuantityValue object, representing the given value. |
||
37 | * |
||
38 | * @since 0.1 |
||
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.1 |
||
74 | * |
||
75 | * @param string|int|float|DecimalValue|QuantityValue $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 self |
||
81 | * @throws IllegalValueException |
||
82 | */ |
||
83 | public static function newFromNumber( $number, $unit = '1', $upperBound = null, $lowerBound = null ) { |
||
94 | |||
95 | /** |
||
96 | * @see newFromNumber |
||
97 | * |
||
98 | * @deprecated since 0.1, use newFromNumber instead |
||
99 | * |
||
100 | * @param string|int|float|DecimalValue|QuantityValue $number |
||
101 | * @param string $unit |
||
102 | * @param string|int|float|DecimalValue|null $upperBound |
||
103 | * @param string|int|float|DecimalValue|null $lowerBound |
||
104 | * |
||
105 | * @return self |
||
106 | */ |
||
107 | public static function newFromDecimal( $number, $unit = '1', $upperBound = null, $lowerBound = null ) { |
||
114 | |||
115 | /** |
||
116 | * @see Serializable::unserialize |
||
117 | * |
||
118 | * @since 0.1 |
||
119 | * |
||
120 | * @param string $data |
||
121 | */ |
||
122 | public function unserialize( $data ) { |
||
126 | |||
127 | /** |
||
128 | * @see DataValue::getType |
||
129 | * |
||
130 | * @since 0.1 |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | public static function getType() { |
||
137 | |||
138 | /** |
||
139 | * Returns this quantity's upper bound. |
||
140 | * |
||
141 | * @since 0.1 |
||
142 | * |
||
143 | * @return DecimalValue |
||
144 | */ |
||
145 | public function getUpperBound() { |
||
148 | |||
149 | /** |
||
150 | * Returns this quantity's lower bound. |
||
151 | * |
||
152 | * @since 0.1 |
||
153 | * |
||
154 | * @return DecimalValue |
||
155 | */ |
||
156 | public function getLowerBound() { |
||
159 | |||
160 | /** |
||
161 | * Returns the size of the uncertainty interval. |
||
162 | * This can roughly be interpreted as "amount +/- uncertainty/2". |
||
163 | * |
||
164 | * The exact interpretation of the uncertainty interval is left to the concrete application or |
||
165 | * data point. For example, the uncertainty interval may be defined to be that part of a |
||
166 | * normal distribution that is required to cover the 95th percentile. |
||
167 | * |
||
168 | * @since 0.1 |
||
169 | * |
||
170 | * @return float |
||
171 | */ |
||
172 | public function getUncertainty() { |
||
175 | |||
176 | /** |
||
177 | * Returns a DecimalValue representing the symmetrical offset to be applied |
||
178 | * to the raw amount for a rough representation of the uncertainty interval, |
||
179 | * as in "amount +/- offset". |
||
180 | * |
||
181 | * The offset is calculated as max( amount - lowerBound, upperBound - amount ). |
||
182 | * |
||
183 | * @since 0.1 |
||
184 | * |
||
185 | * @return DecimalValue |
||
186 | */ |
||
187 | public function getUncertaintyMargin() { |
||
196 | |||
197 | /** |
||
198 | * Returns the order of magnitude of the uncertainty as the exponent of |
||
199 | * last significant digit in the amount-string. The value returned by this |
||
200 | * is suitable for use with @see DecimalMath::roundToExponent(). |
||
201 | * |
||
202 | * @example: if two digits after the decimal point are significant, this |
||
203 | * returns -2. |
||
204 | * |
||
205 | * @example: if the last two digits before the decimal point are insignificant, |
||
206 | * this returns 2. |
||
207 | * |
||
208 | * Note that this calculation assumes a symmetric uncertainty interval, |
||
209 | * and can be misleading. |
||
210 | * |
||
211 | * @since 0.1 |
||
212 | * |
||
213 | * @return int |
||
214 | */ |
||
215 | public function getOrderOfUncertainty() { |
||
237 | |||
238 | /** |
||
239 | * Returns the number of significant figures in the amount-string, |
||
240 | * counting the decimal point, but not counting the leading sign. |
||
241 | * |
||
242 | * Note that this calculation assumes a symmetric uncertainty interval, and can be misleading |
||
243 | * |
||
244 | * @since 0.1 |
||
245 | * |
||
246 | * @return int |
||
247 | */ |
||
248 | public function getSignificantFigures() { |
||
259 | |||
260 | /** |
||
261 | * Returns a transformed value derived from this QuantityValue by applying |
||
262 | * the given transformation to the amount and the upper and lower bounds. |
||
263 | * The resulting amount and bounds are rounded to the significant number of |
||
264 | * digits. Note that for exact quantities (with at least one bound equal to |
||
265 | * the amount), no rounding is applied (since they are considered to have |
||
266 | * infinite precision). |
||
267 | * |
||
268 | * The transformation is provided as a callback, which must implement a |
||
269 | * monotonously increasing, fully differentiable function mapping a DecimalValue |
||
270 | * to a DecimalValue. Typically, it will be a linear transformation applying a |
||
271 | * factor and an offset. |
||
272 | * |
||
273 | * @param string $newUnit The unit of the transformed quantity. |
||
274 | * |
||
275 | * @param callable $transformation A callback that implements the desired transformation. |
||
276 | * The transformation will be called three times, once for the amount, once |
||
277 | * for the lower bound, and once for the upper bound. It must return a DecimalValue. |
||
278 | * The first parameter passed to $transformation is the DecimalValue to transform |
||
279 | * In addition, any extra parameters passed to transform() will be passed through |
||
280 | * to the transformation callback. |
||
281 | * |
||
282 | * @param mixed ... Any extra parameters will be passed to the $transformation function. |
||
283 | * |
||
284 | * @throws InvalidArgumentException |
||
285 | * @return self |
||
286 | */ |
||
287 | public function transform( $newUnit, $transformation ) { |
||
334 | |||
335 | public function __toString() { |
||
342 | |||
343 | /** |
||
344 | * @see DataValue::getArrayValue |
||
345 | * |
||
346 | * @since 0.1 |
||
347 | * |
||
348 | * @return array |
||
349 | */ |
||
350 | public function getArrayValue() { |
||
358 | |||
359 | /** |
||
360 | * Constructs a new instance of the DataValue from the provided data. |
||
361 | * This can round-trip with @see getArrayValue |
||
362 | * |
||
363 | * @since 0.1 |
||
364 | * |
||
365 | * @param mixed $data |
||
366 | * |
||
367 | * @return self |
||
368 | * @throws IllegalValueException |
||
369 | */ |
||
370 | public static function newFromArray( $data ) { |
||
380 | |||
381 | } |
||
382 |
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: