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 | * @since 0.1 |
||
41 | * |
||
42 | * @param DecimalValue $amount |
||
43 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
44 | * @param DecimalValue $upperBound The upper bound of the quantity, inclusive. |
||
45 | * @param DecimalValue $lowerBound The lower bound of the quantity, inclusive. |
||
46 | * |
||
47 | * @throws IllegalValueException |
||
48 | */ |
||
49 | 34 | public function __construct( DecimalValue $amount, $unit, DecimalValue $upperBound, DecimalValue $lowerBound ) { |
|
63 | |||
64 | /** |
||
65 | * Returns a QuantityValue representing the given amount. |
||
66 | * If no upper or lower bound is given, the amount is assumed to be absolutely exact, |
||
67 | * that is, the amount itself will be used as the upper and lower bound. |
||
68 | * |
||
69 | * This is a convenience wrapper around the constructor that accepts native values |
||
70 | * instead of DecimalValue objects. |
||
71 | * |
||
72 | * @note: if the amount or a bound is given as a string, the string must conform |
||
73 | * to the rules defined by @see DecimalValue. |
||
74 | * |
||
75 | * @since 0.1 |
||
76 | * |
||
77 | * @param string|int|float|DecimalValue $amount |
||
78 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
79 | * @param string|int|float|DecimalValue|null $upperBound |
||
80 | * @param string|int|float|DecimalValue|null $lowerBound |
||
81 | * |
||
82 | * @return self |
||
83 | * @throws IllegalValueException |
||
84 | */ |
||
85 | 7 | public static function newFromNumber( $amount, $unit = '1', $upperBound = null, $lowerBound = null ) { |
|
92 | |||
93 | /** |
||
94 | * @see Serializable::serialize |
||
95 | * |
||
96 | * @since 0.1 |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | 9 | public function serialize() { |
|
108 | |||
109 | /** |
||
110 | * @see Serializable::unserialize |
||
111 | * |
||
112 | * @since 0.1 |
||
113 | * |
||
114 | * @param string $data |
||
115 | */ |
||
116 | 9 | public function unserialize( $data ) { |
|
120 | |||
121 | /** |
||
122 | * Returns this quantity's upper bound. |
||
123 | * |
||
124 | * @since 0.1 |
||
125 | * |
||
126 | * @return DecimalValue |
||
127 | */ |
||
128 | 19 | public function getUpperBound() { |
|
131 | |||
132 | /** |
||
133 | * Returns this quantity's lower bound. |
||
134 | * |
||
135 | * @since 0.1 |
||
136 | * |
||
137 | * @return DecimalValue |
||
138 | */ |
||
139 | 19 | public function getLowerBound() { |
|
142 | |||
143 | /** |
||
144 | * Returns the size of the uncertainty interval. |
||
145 | * This can roughly be interpreted as "amount +/- uncertainty/2". |
||
146 | * |
||
147 | * The exact interpretation of the uncertainty interval is left to the concrete application or |
||
148 | * data point. For example, the uncertainty interval may be defined to be that part of a |
||
149 | * normal distribution that is required to cover the 95th percentile. |
||
150 | * |
||
151 | * @since 0.1 |
||
152 | * |
||
153 | * @return float |
||
154 | */ |
||
155 | 8 | public function getUncertainty() { |
|
158 | |||
159 | /** |
||
160 | * Returns a DecimalValue representing the symmetrical offset to be applied |
||
161 | * to the raw amount for a rough representation of the uncertainty interval, |
||
162 | * as in "amount +/- offset". |
||
163 | * |
||
164 | * The offset is calculated as max( amount - lowerBound, upperBound - amount ). |
||
165 | * |
||
166 | * @since 0.1 |
||
167 | * |
||
168 | * @return DecimalValue |
||
169 | */ |
||
170 | 6 | public function getUncertaintyMargin() { |
|
179 | |||
180 | /** |
||
181 | * Returns the order of magnitude of the uncertainty as the exponent of |
||
182 | * last significant digit in the amount-string. The value returned by this |
||
183 | * is suitable for use with @see DecimalMath::roundToExponent(). |
||
184 | * |
||
185 | * @example: if two digits after the decimal point are significant, this |
||
186 | * returns -2. |
||
187 | * |
||
188 | * @example: if the last two digits before the decimal point are insignificant, |
||
189 | * this returns 2. |
||
190 | * |
||
191 | * Note that this calculation assumes a symmetric uncertainty interval, |
||
192 | * and can be misleading. |
||
193 | * |
||
194 | * @since 0.1 |
||
195 | * |
||
196 | * @return int |
||
197 | */ |
||
198 | 22 | public function getOrderOfUncertainty() { |
|
220 | |||
221 | /** |
||
222 | * @see UnboundedQuantityValue::transform |
||
223 | * |
||
224 | * @param string $newUnit |
||
225 | * @param callable $transformation |
||
226 | * @param mixed [$args,...] |
||
227 | * |
||
228 | * @todo Should be factored out into a separate QuantityMath class. |
||
229 | * |
||
230 | * @throws InvalidArgumentException |
||
231 | * @return self |
||
232 | */ |
||
233 | 9 | public function transform( $newUnit, $transformation ) { |
|
270 | |||
271 | 1 | public function __toString() { |
|
278 | |||
279 | /** |
||
280 | * @see DataValue::getArrayValue |
||
281 | * |
||
282 | * @since 0.1 |
||
283 | * |
||
284 | * @return array |
||
285 | */ |
||
286 | 14 | public function getArrayValue() { |
|
294 | |||
295 | } |
||
296 |
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: