@@ -331,7 +331,7 @@ |
||
331 | 331 | elseif (is_object($value)) { |
332 | 332 | if ( ! method_exists($value, 'toNumber')) { |
333 | 333 | throw new \InvalidArgumentEXception( |
334 | - "Trying to sum a ".get_class($value)." object which cannot be casted as a number. " |
|
334 | + "Trying to sum a ".get_class($value)." object which cannot be casted as a number. " |
|
335 | 335 | ."Please add a toNumber() method." |
336 | 336 | ); |
337 | 337 | } |
@@ -64,14 +64,12 @@ discard block |
||
64 | 64 | ) |
65 | 65 | { |
66 | 66 | $array1[$key] = self::merge($array1[$key], $value); |
67 | - } |
|
68 | - else |
|
67 | + } else |
|
69 | 68 | { |
70 | 69 | $array1[$key] = $value; |
71 | 70 | } |
72 | 71 | } |
73 | - } |
|
74 | - else |
|
72 | + } else |
|
75 | 73 | { |
76 | 74 | foreach ($array2 as $value) |
77 | 75 | { |
@@ -96,14 +94,12 @@ discard block |
||
96 | 94 | ) |
97 | 95 | { |
98 | 96 | $array1[$key] = self::merge($array1[$key], $value); |
99 | - } |
|
100 | - else |
|
97 | + } else |
|
101 | 98 | { |
102 | 99 | $array1[$key] = $value; |
103 | 100 | } |
104 | 101 | } |
105 | - } |
|
106 | - else |
|
102 | + } else |
|
107 | 103 | { |
108 | 104 | foreach ($array2 as $value) |
109 | 105 | { |
@@ -170,8 +166,7 @@ discard block |
||
170 | 166 | $column, |
171 | 167 | ] |
172 | 168 | ); |
173 | - } |
|
174 | - else { |
|
169 | + } else { |
|
175 | 170 | // same resolution as array_merge_recursive |
176 | 171 | if (!is_array($existing_value)) { |
177 | 172 | $existing_row[$column] = [$existing_value]; |
@@ -245,15 +240,18 @@ discard block |
||
245 | 240 | public static function keepUniqueColumnValues(array $row, array $excluded_columns=[]) |
246 | 241 | { |
247 | 242 | foreach ($row as $column => &$values) { |
248 | - if (!is_array($values)) |
|
249 | - continue; |
|
243 | + if (!is_array($values)) { |
|
244 | + continue; |
|
245 | + } |
|
250 | 246 | |
251 | - if (in_array($column, $excluded_columns)) |
|
252 | - continue; |
|
247 | + if (in_array($column, $excluded_columns)) { |
|
248 | + continue; |
|
249 | + } |
|
253 | 250 | |
254 | 251 | $values = array_unique($values); |
255 | - if (count($values) == 1) |
|
256 | - $values = $values[0]; |
|
252 | + if (count($values) == 1) { |
|
253 | + $values = $values[0]; |
|
254 | + } |
|
257 | 255 | } |
258 | 256 | |
259 | 257 | return $row; |
@@ -280,8 +278,7 @@ discard block |
||
280 | 278 | foreach ($array as $key => $value) { |
281 | 279 | if (is_scalar($value)) { |
282 | 280 | $id = $value; |
283 | - } |
|
284 | - else { |
|
281 | + } else { |
|
285 | 282 | $id = serialize($value); |
286 | 283 | } |
287 | 284 | |
@@ -319,16 +316,13 @@ discard block |
||
319 | 316 | foreach ($array as $key => &$value) { // &for optimization |
320 | 317 | if (is_scalar($value)) { |
321 | 318 | $sum += $value; |
322 | - } |
|
323 | - elseif (is_null($value)) { |
|
319 | + } elseif (is_null($value)) { |
|
324 | 320 | continue; |
325 | - } |
|
326 | - elseif (is_array($value)) { |
|
321 | + } elseif (is_array($value)) { |
|
327 | 322 | throw new \InvalidArgumentException( |
328 | 323 | "Trying to sum an array with '$sum': ".var_export($value, true) |
329 | 324 | ); |
330 | - } |
|
331 | - elseif (is_object($value)) { |
|
325 | + } elseif (is_object($value)) { |
|
332 | 326 | if ( ! method_exists($value, 'toNumber')) { |
333 | 327 | throw new \InvalidArgumentEXception( |
334 | 328 | "Trying to sum a ".get_class($value)." object which cannot be casted as a number. " |
@@ -355,17 +349,21 @@ discard block |
||
355 | 349 | */ |
356 | 350 | public static function weightedMean($values, $weights) |
357 | 351 | { |
358 | - if ($values instanceof ChainableArray) |
|
359 | - $values = $values->toArray(); |
|
352 | + if ($values instanceof ChainableArray) { |
|
353 | + $values = $values->toArray(); |
|
354 | + } |
|
360 | 355 | |
361 | - if ($weights instanceof ChainableArray) |
|
362 | - $weights = $weights->toArray(); |
|
356 | + if ($weights instanceof ChainableArray) { |
|
357 | + $weights = $weights->toArray(); |
|
358 | + } |
|
363 | 359 | |
364 | - if ( ! is_array($values)) |
|
365 | - $values = [$values]; |
|
360 | + if ( ! is_array($values)) { |
|
361 | + $values = [$values]; |
|
362 | + } |
|
366 | 363 | |
367 | - if ( ! is_array($weights)) |
|
368 | - $weights = [$weights]; |
|
364 | + if ( ! is_array($weights)) { |
|
365 | + $weights = [$weights]; |
|
366 | + } |
|
369 | 367 | |
370 | 368 | if (count($values) != count($weights)) { |
371 | 369 | throw new \InvalidArgumentException( |
@@ -376,12 +374,14 @@ discard block |
||
376 | 374 | ); |
377 | 375 | } |
378 | 376 | |
379 | - if (!$values) |
|
380 | - return null; |
|
377 | + if (!$values) { |
|
378 | + return null; |
|
379 | + } |
|
381 | 380 | |
382 | 381 | $weights_sum = array_sum($weights); |
383 | - if (!$weights_sum) |
|
384 | - return 0; |
|
382 | + if (!$weights_sum) { |
|
383 | + return 0; |
|
384 | + } |
|
385 | 385 | |
386 | 386 | $weighted_sum = 0; |
387 | 387 | foreach ($values as $i => $value) { |