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 ) { |
|
67 | |||
68 | /** |
||
69 | * Returns a QuantityValue representing the given amount. |
||
70 | * If no upper or lower bound is given, the amount is assumed to be absolutely exact, |
||
71 | * that is, the amount itself will be used as the upper and lower bound. |
||
72 | * |
||
73 | * This is a convenience wrapper around the constructor that accepts native values |
||
74 | * instead of DecimalValue objects. |
||
75 | * |
||
76 | * @note if the amount or a bound is given as a string, the string must conform |
||
77 | * to the rules defined by @see DecimalValue. |
||
78 | * |
||
79 | * @since 0.1 |
||
80 | * |
||
81 | * @param string|int|float|DecimalValue $amount |
||
82 | * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities. |
||
83 | * @param string|int|float|DecimalValue|null $upperBound |
||
84 | * @param string|int|float|DecimalValue|null $lowerBound |
||
85 | * |
||
86 | * @return self |
||
87 | * @throws IllegalValueException |
||
88 | */ |
||
89 | 7 | public static function newFromNumber( $amount, $unit = '1', $upperBound = null, $lowerBound = null ) { |
|
96 | |||
97 | /** |
||
98 | * @see Serializable::serialize |
||
99 | * |
||
100 | * @since 0.1 |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 9 | public function serialize() { |
|
112 | |||
113 | /** |
||
114 | * @see Serializable::unserialize |
||
115 | * |
||
116 | * @since 0.1 |
||
117 | * |
||
118 | * @param string $data |
||
119 | */ |
||
120 | 9 | public function unserialize( $data ) { |
|
124 | |||
125 | /** |
||
126 | * Returns this quantity's upper bound. |
||
127 | * |
||
128 | * @since 0.1 |
||
129 | * |
||
130 | * @return DecimalValue |
||
131 | */ |
||
132 | 19 | public function getUpperBound() { |
|
135 | |||
136 | /** |
||
137 | * Returns this quantity's lower bound. |
||
138 | * |
||
139 | * @since 0.1 |
||
140 | * |
||
141 | * @return DecimalValue |
||
142 | */ |
||
143 | 19 | public function getLowerBound() { |
|
146 | |||
147 | /** |
||
148 | * Returns the size of the uncertainty interval. |
||
149 | * This can roughly be interpreted as "amount +/- uncertainty/2". |
||
150 | * |
||
151 | * The exact interpretation of the uncertainty interval is left to the concrete application or |
||
152 | * data point. For example, the uncertainty interval may be defined to be that part of a |
||
153 | * normal distribution that is required to cover the 95th percentile. |
||
154 | * |
||
155 | * @since 0.1 |
||
156 | * |
||
157 | * @return float |
||
158 | */ |
||
159 | 8 | public function getUncertainty() { |
|
162 | |||
163 | /** |
||
164 | * Returns a DecimalValue representing the symmetrical offset to be applied |
||
165 | * to the raw amount for a rough representation of the uncertainty interval, |
||
166 | * as in "amount +/- offset". |
||
167 | * |
||
168 | * The offset is calculated as max( amount - lowerBound, upperBound - amount ). |
||
169 | * |
||
170 | * @since 0.1 |
||
171 | * |
||
172 | * @return DecimalValue |
||
173 | */ |
||
174 | 6 | public function getUncertaintyMargin() { |
|
183 | |||
184 | /** |
||
185 | * Returns the order of magnitude of the uncertainty as the exponent of |
||
186 | * last significant digit in the amount-string. The value returned by this |
||
187 | * is suitable for use with @see DecimalMath::roundToExponent(). |
||
188 | * |
||
189 | * @example: if two digits after the decimal point are significant, this |
||
190 | * returns -2. |
||
191 | * |
||
192 | * @example: if the last two digits before the decimal point are insignificant, |
||
193 | * this returns 2. |
||
194 | * |
||
195 | * Note that this calculation assumes a symmetric uncertainty interval, |
||
196 | * and can be misleading. |
||
197 | * |
||
198 | * @since 0.1 |
||
199 | * |
||
200 | * @return int |
||
201 | */ |
||
202 | 22 | public function getOrderOfUncertainty() { |
|
224 | |||
225 | /** |
||
226 | * @see UnboundedQuantityValue::transform |
||
227 | * |
||
228 | * @param string $newUnit |
||
229 | * @param callable $transformation |
||
230 | * @param mixed [$args,...] |
||
231 | * |
||
232 | * @todo Should be factored out into a separate QuantityMath class. |
||
233 | * |
||
234 | * @throws InvalidArgumentException |
||
235 | * @return self |
||
236 | */ |
||
237 | 9 | public function transform( $newUnit, $transformation ) { |
|
276 | |||
277 | 1 | public function __toString() { |
|
284 | |||
285 | /** |
||
286 | * @see DataValue::getArrayValue |
||
287 | * |
||
288 | * @since 0.1 |
||
289 | * |
||
290 | * @return array |
||
291 | */ |
||
292 | 14 | public function getArrayValue() { |
|
300 | |||
301 | } |
||
302 |
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: