Passed
Push — master ( f2bc5a...8e7423 )
by Jean
04:25
created
src/Arrays/Arrays.php 1 patch
Braces   +56 added lines, -64 removed lines patch added patch discarded remove patch
@@ -65,14 +65,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,12 +246,10 @@  discard block
 block discarded – undo
253 246
                 foreach ($conflict_value as $conflict_bucket_value) {
254 247
                     $merged_row[ $existing_column ] = $conflict_bucket_value;
255 248
                 }
256
-            }
257
-            else {
249
+            } else {
258 250
                 if (isset($conflict_key)) {
259 251
                     $merged_row[ $conflict_column ][$conflict_key] = $conflict_value;
260
-                }
261
-                else {
252
+                } else {
262 253
                     $merged_row[ $conflict_column ][] = $conflict_value;
263 254
                 }
264 255
             }
@@ -283,15 +274,18 @@  discard block
 block discarded – undo
283 274
                           ;
284 275
 
285 276
         foreach ($row as $column => &$values) {
286
-            if ( ! $values instanceof MergeBucket)
287
-                continue;
277
+            if ( ! $values instanceof MergeBucket) {
278
+                            continue;
279
+            }
288 280
 
289
-            if (in_array($column, $excluded_columns))
290
-                continue;
281
+            if (in_array($column, $excluded_columns)) {
282
+                            continue;
283
+            }
291 284
 
292 285
             $values = Arrays::unique($values);
293
-            if (count($values) == 1)
294
-                $values = $values[0];
286
+            if (count($values) == 1) {
287
+                            $values = $values[0];
288
+            }
295 289
         }
296 290
 
297 291
         return $row;
@@ -344,8 +338,7 @@  discard block
 block discarded – undo
344 338
         foreach ($array as $key => $value) {
345 339
             if (is_scalar($value)) {
346 340
                 $id = $value;
347
-            }
348
-            else {
341
+            } else {
349 342
                 $id = serialize($value);
350 343
             }
351 344
 
@@ -369,11 +362,9 @@  discard block
 block discarded – undo
369 362
 
370 363
         if (is_array($array)) {
371 364
             return array_key_exists($key, $array);
372
-        }
373
-        elseif ($array instanceof ChainableArray || method_exists($array, 'keyExists')) {
365
+        } elseif ($array instanceof ChainableArray || method_exists($array, 'keyExists')) {
374 366
             return $array->keyExists($key);
375
-        }
376
-        else {
367
+        } else {
377 368
             throw new \InvalidArgumentException(
378 369
                 "keyExists() method missing on :\n". var_export($array, true)
379 370
             );
@@ -399,16 +390,13 @@  discard block
 block discarded – undo
399 390
         foreach ($array as $key => &$value) { // &for optimization
400 391
             if (is_scalar($value)) {
401 392
                 $sum += $value;
402
-            }
403
-            elseif (is_null($value)) {
393
+            } elseif (is_null($value)) {
404 394
                 continue;
405
-            }
406
-            elseif (is_array($value)) {
395
+            } elseif (is_array($value)) {
407 396
                 throw new \InvalidArgumentException(
408 397
                     "Trying to sum an array with '$sum': ".var_export($value, true)
409 398
                 );
410
-            }
411
-            elseif (is_object($value)) {
399
+            } elseif (is_object($value)) {
412 400
                 if ( ! method_exists($value, 'toNumber')) {
413 401
                     throw new \InvalidArgumentEXception(
414 402
                          "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
@@ -435,17 +423,21 @@  discard block
 block discarded – undo
435 423
      */
436 424
     public static function weightedMean($values, $weights)
437 425
     {
438
-        if ($values instanceof ChainableArray)
439
-            $values = $values->toArray();
426
+        if ($values instanceof ChainableArray) {
427
+                    $values = $values->toArray();
428
+        }
440 429
 
441
-        if ($weights instanceof ChainableArray)
442
-            $weights = $weights->toArray();
430
+        if ($weights instanceof ChainableArray) {
431
+                    $weights = $weights->toArray();
432
+        }
443 433
 
444
-        if ( ! is_array($values))
445
-            $values = [$values];
434
+        if ( ! is_array($values)) {
435
+                    $values = [$values];
436
+        }
446 437
 
447
-        if ( ! is_array($weights))
448
-            $weights = [$weights];
438
+        if ( ! is_array($weights)) {
439
+                    $weights = [$weights];
440
+        }
449 441
 
450 442
         if (count($values) != count($weights)) {
451 443
             throw new \InvalidArgumentException(
@@ -456,12 +448,14 @@  discard block
 block discarded – undo
456 448
             );
457 449
         }
458 450
 
459
-        if (!$values)
460
-            return null;
451
+        if (!$values) {
452
+                    return null;
453
+        }
461 454
 
462 455
         $weights_sum  = array_sum($weights);
463
-        if (!$weights_sum)
464
-            return 0;
456
+        if (!$weights_sum) {
457
+                    return 0;
458
+        }
465 459
 
466 460
         $weighted_sum = 0;
467 461
         foreach ($values as $i => $value) {
@@ -500,8 +494,9 @@  discard block
 block discarded – undo
500 494
      */
501 495
     public static function mustBeCountable($value)
502 496
     {
503
-        if (static::isCountable($value))
504
-            return true;
497
+        if (static::isCountable($value)) {
498
+                    return true;
499
+        }
505 500
 
506 501
         $exception = new \InvalidArgumentException(
507 502
             "A value must be Countable instead of: \n"
@@ -538,8 +533,9 @@  discard block
 block discarded – undo
538 533
      */
539 534
     public static function mustBeTraversable($value)
540 535
     {
541
-        if (static::isTraversable($value))
542
-            return true;
536
+        if (static::isTraversable($value)) {
537
+                    return true;
538
+        }
543 539
 
544 540
         $exception = new \InvalidArgumentException(
545 541
             "A value must be Traversable instead of: \n"
@@ -623,8 +619,7 @@  discard block
 block discarded – undo
623 619
 
624 620
                 $part_name         .= $group_definition_value;
625 621
                 $group_result_value = $row[ $group_definition_value ];
626
-            }
627
-            elseif (is_int($group_definition_value)) {
622
+            } elseif (is_int($group_definition_value)) {
628 623
                 if (    (is_array($row)              && ! array_key_exists($group_definition_value, $row))
629 624
                     ||  ($row instanceof \ArrayAcces && ! $row->offsetExists($group_definition_value))
630 625
                 ) {
@@ -637,8 +632,7 @@  discard block
 block discarded – undo
637 632
 
638 633
                 $part_name         .= $group_definition_value ? : '0';
639 634
                 $group_result_value = $row[ $group_definition_value ];
640
-            }
641
-            elseif (is_callable($group_definition_value)) {
635
+            } elseif (is_callable($group_definition_value)) {
642 636
 
643 637
                 if (is_string($group_definition_value)) {
644 638
                     $part_name .= $group_definition_value;
@@ -647,16 +641,14 @@  discard block
 block discarded – undo
647 641
                 elseif (is_object($group_definition_value) && ($group_definition_value instanceof \Closure)) {
648 642
                     $part_name .= 'unnamed-closure-'
649 643
                                 . hash('crc32b', var_export($group_definition_value, true));
650
-                }
651
-                elseif (is_array($group_definition_value)) {
644
+                } elseif (is_array($group_definition_value)) {
652 645
                     $part_name .= implode('::', $group_definition_value);
653 646
                 }
654 647
 
655 648
                 $group_result_value = call_user_func_array($group_definition_value, [
656 649
                     $row, &$part_name
657 650
                 ]);
658
-            }
659
-            else {
651
+            } else {
660 652
                 throw new UsageException(
661 653
                     'Bad value provided for group id generation: '
662 654
                     .var_export($group_definition_value, true)
@@ -664,8 +656,9 @@  discard block
 block discarded – undo
664 656
                 );
665 657
             }
666 658
 
667
-            if (!is_null($part_name))
668
-                $group_parts[ $part_name ] = $group_result_value;
659
+            if (!is_null($part_name)) {
660
+                            $group_parts[ $part_name ] = $group_result_value;
661
+            }
669 662
         }
670 663
 
671 664
         // sort the groups by names (without it the same group could have multiple ids)
@@ -678,8 +671,7 @@  discard block
 block discarded – undo
678 671
                 $group_value = get_class($group_value)
679 672
                              . '_'
680 673
                              . hash( 'crc32b', var_export($group_value, true) );
681
-            }
682
-            elseif (is_array($group_value)) {
674
+            } elseif (is_array($group_value)) {
683 675
                 $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) );
684 676
             }
685 677
 
Please login to merge, or discard this patch.