@@ -65,14 +65,12 @@ discard block |
||
65 | 65 | ) |
66 | 66 | { |
67 | 67 | $array1[$key] = self::merge($array1[$key], $value); |
68 | - } |
|
69 | - else |
|
68 | + } else |
|
70 | 69 | { |
71 | 70 | $array1[$key] = $value; |
72 | 71 | } |
73 | 72 | } |
74 | - } |
|
75 | - else |
|
73 | + } else |
|
76 | 74 | { |
77 | 75 | foreach ($array2 as $value) |
78 | 76 | { |
@@ -97,14 +95,12 @@ discard block |
||
97 | 95 | ) |
98 | 96 | { |
99 | 97 | $array1[$key] = self::merge($array1[$key], $value); |
100 | - } |
|
101 | - else |
|
98 | + } else |
|
102 | 99 | { |
103 | 100 | $array1[$key] = $value; |
104 | 101 | } |
105 | 102 | } |
106 | - } |
|
107 | - else |
|
103 | + } else |
|
108 | 104 | { |
109 | 105 | foreach ($array2 as $value) |
110 | 106 | { |
@@ -174,8 +170,7 @@ discard block |
||
174 | 170 | $column, |
175 | 171 | ] |
176 | 172 | ); |
177 | - } |
|
178 | - else { |
|
173 | + } else { |
|
179 | 174 | // same resolution as array_merge_recursive |
180 | 175 | if (!is_array($existing_value)) { |
181 | 176 | $existing_row[$column] = [$existing_value]; |
@@ -229,14 +224,12 @@ discard block |
||
229 | 224 | foreach ($existing_row as $existing_column => $existing_value) { |
230 | 225 | if ($existing_value instanceof MergeBucket) { |
231 | 226 | $merged_row[ $existing_column ] = $existing_value; |
232 | - } |
|
233 | - else { |
|
227 | + } else { |
|
234 | 228 | if (isset($existing_key)) { |
235 | 229 | $merged_row[ $existing_column ] = MergeBucket::from([ |
236 | 230 | $existing_key => $existing_value |
237 | 231 | ]); |
238 | - } |
|
239 | - else { |
|
232 | + } else { |
|
240 | 233 | $merged_row[ $existing_column ] = MergeBucket::from([ |
241 | 234 | $existing_value |
242 | 235 | ]); |
@@ -253,17 +246,14 @@ discard block |
||
253 | 246 | foreach ($conflict_value as $conflict_bucket_value) { |
254 | 247 | if (isset($conflict_key)) { |
255 | 248 | $merged_row[ $conflict_column ][$conflict_key] = $conflict_bucket_value; |
256 | - } |
|
257 | - else { |
|
249 | + } else { |
|
258 | 250 | $merged_row[ $conflict_column ][] = $conflict_bucket_value; |
259 | 251 | } |
260 | 252 | } |
261 | - } |
|
262 | - else { |
|
253 | + } else { |
|
263 | 254 | if (isset($conflict_key)) { |
264 | 255 | $merged_row[ $conflict_column ][$conflict_key] = $conflict_value; |
265 | - } |
|
266 | - else { |
|
256 | + } else { |
|
267 | 257 | $merged_row[ $conflict_column ][] = $conflict_value; |
268 | 258 | } |
269 | 259 | } |
@@ -288,15 +278,18 @@ discard block |
||
288 | 278 | ; |
289 | 279 | |
290 | 280 | foreach ($row as $column => &$values) { |
291 | - if ( ! $values instanceof MergeBucket) |
|
292 | - continue; |
|
281 | + if ( ! $values instanceof MergeBucket) { |
|
282 | + continue; |
|
283 | + } |
|
293 | 284 | |
294 | - if (in_array($column, $excluded_columns)) |
|
295 | - continue; |
|
285 | + if (in_array($column, $excluded_columns)) { |
|
286 | + continue; |
|
287 | + } |
|
296 | 288 | |
297 | 289 | $values = Arrays::unique($values); |
298 | - if (count($values) == 1) |
|
299 | - $values = $values[0]; |
|
290 | + if (count($values) == 1) { |
|
291 | + $values = $values[0]; |
|
292 | + } |
|
300 | 293 | } |
301 | 294 | |
302 | 295 | return $row; |
@@ -349,8 +342,7 @@ discard block |
||
349 | 342 | foreach ($array as $key => $value) { |
350 | 343 | if (is_scalar($value)) { |
351 | 344 | $id = $value; |
352 | - } |
|
353 | - else { |
|
345 | + } else { |
|
354 | 346 | $id = serialize($value); |
355 | 347 | } |
356 | 348 | |
@@ -374,11 +366,9 @@ discard block |
||
374 | 366 | |
375 | 367 | if (is_array($array)) { |
376 | 368 | return array_key_exists($key, $array); |
377 | - } |
|
378 | - elseif ($array instanceof ChainableArray || method_exists($array, 'keyExists')) { |
|
369 | + } elseif ($array instanceof ChainableArray || method_exists($array, 'keyExists')) { |
|
379 | 370 | return $array->keyExists($key); |
380 | - } |
|
381 | - else { |
|
371 | + } else { |
|
382 | 372 | throw new \InvalidArgumentException( |
383 | 373 | "keyExists() method missing on :\n". var_export($array, true) |
384 | 374 | ); |
@@ -404,16 +394,13 @@ discard block |
||
404 | 394 | foreach ($array as $key => &$value) { // &for optimization |
405 | 395 | if (is_scalar($value)) { |
406 | 396 | $sum += $value; |
407 | - } |
|
408 | - elseif (is_null($value)) { |
|
397 | + } elseif (is_null($value)) { |
|
409 | 398 | continue; |
410 | - } |
|
411 | - elseif (is_array($value)) { |
|
399 | + } elseif (is_array($value)) { |
|
412 | 400 | throw new \InvalidArgumentException( |
413 | 401 | "Trying to sum an array with '$sum': ".var_export($value, true) |
414 | 402 | ); |
415 | - } |
|
416 | - elseif (is_object($value)) { |
|
403 | + } elseif (is_object($value)) { |
|
417 | 404 | if ( ! method_exists($value, 'toNumber')) { |
418 | 405 | throw new \InvalidArgumentEXception( |
419 | 406 | "Trying to sum a ".get_class($value)." object which cannot be casted as a number. " |
@@ -440,17 +427,21 @@ discard block |
||
440 | 427 | */ |
441 | 428 | public static function weightedMean($values, $weights) |
442 | 429 | { |
443 | - if ($values instanceof ChainableArray) |
|
444 | - $values = $values->toArray(); |
|
430 | + if ($values instanceof ChainableArray) { |
|
431 | + $values = $values->toArray(); |
|
432 | + } |
|
445 | 433 | |
446 | - if ($weights instanceof ChainableArray) |
|
447 | - $weights = $weights->toArray(); |
|
434 | + if ($weights instanceof ChainableArray) { |
|
435 | + $weights = $weights->toArray(); |
|
436 | + } |
|
448 | 437 | |
449 | - if ( ! is_array($values)) |
|
450 | - $values = [$values]; |
|
438 | + if ( ! is_array($values)) { |
|
439 | + $values = [$values]; |
|
440 | + } |
|
451 | 441 | |
452 | - if ( ! is_array($weights)) |
|
453 | - $weights = [$weights]; |
|
442 | + if ( ! is_array($weights)) { |
|
443 | + $weights = [$weights]; |
|
444 | + } |
|
454 | 445 | |
455 | 446 | if (count($values) != count($weights)) { |
456 | 447 | throw new \InvalidArgumentException( |
@@ -461,12 +452,14 @@ discard block |
||
461 | 452 | ); |
462 | 453 | } |
463 | 454 | |
464 | - if (!$values) |
|
465 | - return null; |
|
455 | + if (!$values) { |
|
456 | + return null; |
|
457 | + } |
|
466 | 458 | |
467 | 459 | $weights_sum = array_sum($weights); |
468 | - if (!$weights_sum) |
|
469 | - return 0; |
|
460 | + if (!$weights_sum) { |
|
461 | + return 0; |
|
462 | + } |
|
470 | 463 | |
471 | 464 | $weighted_sum = 0; |
472 | 465 | foreach ($values as $i => $value) { |
@@ -505,8 +498,9 @@ discard block |
||
505 | 498 | */ |
506 | 499 | public static function mustBeCountable($value) |
507 | 500 | { |
508 | - if (static::isCountable($value)) |
|
509 | - return true; |
|
501 | + if (static::isCountable($value)) { |
|
502 | + return true; |
|
503 | + } |
|
510 | 504 | |
511 | 505 | $exception = new \InvalidArgumentException( |
512 | 506 | "A value must be Countable instead of: \n" |
@@ -543,8 +537,9 @@ discard block |
||
543 | 537 | */ |
544 | 538 | public static function mustBeTraversable($value) |
545 | 539 | { |
546 | - if (static::isTraversable($value)) |
|
547 | - return true; |
|
540 | + if (static::isTraversable($value)) { |
|
541 | + return true; |
|
542 | + } |
|
548 | 543 | |
549 | 544 | $exception = new \InvalidArgumentException( |
550 | 545 | "A value must be Traversable instead of: \n" |
@@ -628,8 +623,7 @@ discard block |
||
628 | 623 | |
629 | 624 | $part_name .= $group_definition_value; |
630 | 625 | $group_result_value = $row[ $group_definition_value ]; |
631 | - } |
|
632 | - elseif (is_int($group_definition_value)) { |
|
626 | + } elseif (is_int($group_definition_value)) { |
|
633 | 627 | if ( (is_array($row) && ! array_key_exists($group_definition_value, $row)) |
634 | 628 | || ($row instanceof \ArrayAcces && ! $row->offsetExists($group_definition_value)) |
635 | 629 | ) { |
@@ -642,8 +636,7 @@ discard block |
||
642 | 636 | |
643 | 637 | $part_name .= $group_definition_value ? : '0'; |
644 | 638 | $group_result_value = $row[ $group_definition_value ]; |
645 | - } |
|
646 | - elseif (is_callable($group_definition_value)) { |
|
639 | + } elseif (is_callable($group_definition_value)) { |
|
647 | 640 | |
648 | 641 | if (is_string($group_definition_value)) { |
649 | 642 | $part_name .= $group_definition_value; |
@@ -652,16 +645,14 @@ discard block |
||
652 | 645 | elseif (is_object($group_definition_value) && ($group_definition_value instanceof \Closure)) { |
653 | 646 | $part_name .= 'unnamed-closure-' |
654 | 647 | . hash('crc32b', var_export($group_definition_value, true)); |
655 | - } |
|
656 | - elseif (is_array($group_definition_value)) { |
|
648 | + } elseif (is_array($group_definition_value)) { |
|
657 | 649 | $part_name .= implode('::', $group_definition_value); |
658 | 650 | } |
659 | 651 | |
660 | 652 | $group_result_value = call_user_func_array($group_definition_value, [ |
661 | 653 | $row, &$part_name |
662 | 654 | ]); |
663 | - } |
|
664 | - else { |
|
655 | + } else { |
|
665 | 656 | throw new UsageException( |
666 | 657 | 'Bad value provided for group id generation: ' |
667 | 658 | .var_export($group_definition_value, true) |
@@ -669,8 +660,9 @@ discard block |
||
669 | 660 | ); |
670 | 661 | } |
671 | 662 | |
672 | - if (!is_null($part_name)) |
|
673 | - $group_parts[ $part_name ] = $group_result_value; |
|
663 | + if (!is_null($part_name)) { |
|
664 | + $group_parts[ $part_name ] = $group_result_value; |
|
665 | + } |
|
674 | 666 | } |
675 | 667 | |
676 | 668 | // sort the groups by names (without it the same group could have multiple ids) |
@@ -683,8 +675,7 @@ discard block |
||
683 | 675 | $group_value = get_class($group_value) |
684 | 676 | . '_' |
685 | 677 | . hash( 'crc32b', var_export($group_value, true) ); |
686 | - } |
|
687 | - elseif (is_array($group_value)) { |
|
678 | + } elseif (is_array($group_value)) { |
|
688 | 679 | $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) ); |
689 | 680 | } |
690 | 681 |