1 | <?php |
||
23 | class BoundedQuantityValue extends QuantityValue { |
||
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 | * Constructs a new QuantityValue object, representing the given value. |
||
41 | * |
||
42 | * @since 0.1 |
||
43 | * |
||
44 | * @param DecimalValue $amount |
||
45 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
46 | * @param DecimalValue $upperBound The upper bound of the quantity, inclusive. |
||
47 | * @param DecimalValue $lowerBound The lower bound of the quantity, inclusive. |
||
48 | * |
||
49 | * @throws IllegalValueException |
||
50 | */ |
||
51 | public function __construct( DecimalValue $amount, $unit, DecimalValue $upperBound, DecimalValue $lowerBound ) { |
||
65 | |||
66 | /** |
||
67 | * Returns a QuantityValue representing the given amount. |
||
68 | * If no upper or lower bound is given, the amount is assumed to be absolutely exact, |
||
69 | * that is, the amount itself will be used as the upper and lower bound. |
||
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|QuantityValue $number |
||
80 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
81 | * @param string|int|float|DecimalValue|null $upperBound |
||
82 | * @param string|int|float|DecimalValue|null $lowerBound |
||
83 | * |
||
84 | * @return self |
||
85 | * @throws IllegalValueException |
||
86 | */ |
||
87 | 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 ) { |
||
110 | |||
111 | /** |
||
112 | * @see Serializable::unserialize |
||
113 | * |
||
114 | * @since 0.1 |
||
115 | * |
||
116 | * @param string $data |
||
117 | */ |
||
118 | public function unserialize( $data ) { |
||
125 | |||
126 | /** |
||
127 | * Returns this quantity's upper bound. |
||
128 | * |
||
129 | * @since 0.1 |
||
130 | * |
||
131 | * @return DecimalValue |
||
132 | */ |
||
133 | public function getUpperBound() { |
||
136 | |||
137 | /** |
||
138 | * Returns this quantity's lower bound. |
||
139 | * |
||
140 | * @since 0.1 |
||
141 | * |
||
142 | * @return DecimalValue |
||
143 | */ |
||
144 | public function getLowerBound() { |
||
147 | |||
148 | /** |
||
149 | * Returns the size of the uncertainty interval. |
||
150 | * This can roughly be interpreted as "amount +/- uncertainty/2". |
||
151 | * |
||
152 | * The exact interpretation of the uncertainty interval is left to the concrete application or |
||
153 | * data point. For example, the uncertainty interval may be defined to be that part of a |
||
154 | * normal distribution that is required to cover the 95th percentile. |
||
155 | * |
||
156 | * @since 0.1 |
||
157 | * |
||
158 | * @return float |
||
159 | */ |
||
160 | public function getUncertainty() { |
||
163 | |||
164 | /** |
||
165 | * Returns a DecimalValue representing the symmetrical offset to be applied |
||
166 | * to the raw amount for a rough representation of the uncertainty interval, |
||
167 | * as in "amount +/- offset". |
||
168 | * |
||
169 | * The offset is calculated as max( amount - lowerBound, upperBound - amount ). |
||
170 | * |
||
171 | * @since 0.1 |
||
172 | * |
||
173 | * @return DecimalValue |
||
174 | */ |
||
175 | public function getUncertaintyMargin() { |
||
184 | |||
185 | /** |
||
186 | * Returns the order of magnitude of the uncertainty as the exponent of |
||
187 | * last significant digit in the amount-string. The value returned by this |
||
188 | * is suitable for use with @see DecimalMath::roundToExponent(). |
||
189 | * |
||
190 | * @example: if two digits after the decimal point are significant, this |
||
191 | * returns -2. |
||
192 | * |
||
193 | * @example: if the last two digits before the decimal point are insignificant, |
||
194 | * this returns 2. |
||
195 | * |
||
196 | * Note that this calculation assumes a symmetric uncertainty interval, |
||
197 | * and can be misleading. |
||
198 | * |
||
199 | * @since 0.1 |
||
200 | * |
||
201 | * @return int |
||
202 | */ |
||
203 | public function getOrderOfUncertainty() { |
||
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 ) { |
||
300 | |||
301 | public function __toString() { |
||
308 | |||
309 | /** |
||
310 | * @see DataValue::getArrayValue |
||
311 | * |
||
312 | * @since 0.1 |
||
313 | * |
||
314 | * @return array |
||
315 | */ |
||
316 | public function getArrayValue() { |
||
324 | |||
325 | /** |
||
326 | * Constructs a new instance of the DataValue from the provided data. |
||
327 | * This can round-trip with @see getArrayValue |
||
328 | * |
||
329 | * @since 0.1 |
||
330 | * |
||
331 | * @param mixed $data |
||
332 | * |
||
333 | * @return self |
||
334 | * @throws IllegalValueException |
||
335 | */ |
||
336 | public static function newFromArray( $data ) { |
||
351 | |||
352 | } |
||
353 |
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: