Test Failed
Push — master ( 79d7ec...6a4583 )
by Jean
02:12
created
src/ChainableArray_Utils_Trait.php 1 patch
Braces   +77 added lines, -76 removed lines patch added patch discarded remove patch
@@ -26,18 +26,19 @@  discard block
 block discarded – undo
26 26
         $out = [];
27 27
         foreach ($this->data as $key => $row) {
28 28
 
29
-            if (!$row)
30
-                continue;
29
+            if (!$row) {
30
+                            continue;
31
+            }
31 32
 
32 33
             $newIndexes     = call_user_func($indexGenerator, $key, $row);
33
-            if (!is_array($newIndexes))
34
-                $newIndexes = [$newIndexes];
34
+            if (!is_array($newIndexes)) {
35
+                            $newIndexes = [$newIndexes];
36
+            }
35 37
 
36 38
             foreach ($newIndexes as $newIndex) {
37 39
                 if (!isset($out[$newIndex])) {
38 40
                     $out[$newIndex] = $row;
39
-                }
40
-                else {
41
+                } else {
41 42
                     if ($conflictResolver === null) {
42 43
                         self::throwUsageException(
43 44
                             "A 'group by' provoking a conflict"
@@ -74,20 +75,21 @@  discard block
 block discarded – undo
74 75
         $out = [];
75 76
         foreach ($this->data as $key => $row) {
76 77
 
77
-            if (!$row)
78
-                continue;
78
+            if (!$row) {
79
+                            continue;
80
+            }
79 81
 
80 82
             $new_keys = call_user_func($indexGenerator, $row, $key);
81
-            if (!is_array($new_keys))
82
-                $new_keys = [$new_keys];
83
+            if (!is_array($new_keys)) {
84
+                            $new_keys = [$new_keys];
85
+            }
83 86
 
84 87
             foreach ($new_keys as $new_key) {
85 88
                 if (!isset($out[ $new_key ])) {
86 89
                     $out[ $new_key ] = [
87 90
                         $key => $row
88 91
                     ];
89
-                }
90
-                else {
92
+                } else {
91 93
                     $out[ $new_key ][ $key ] = $row;
92 94
                 }
93 95
             }
@@ -125,8 +127,9 @@  discard block
 block discarded – undo
125 127
         $out = [];
126 128
         foreach ($this->data as $key => $row) {
127 129
 
128
-            if (!$row)
129
-                continue;
130
+            if (!$row) {
131
+                            continue;
132
+            }
130 133
 
131 134
             $newIndex       = call_user_func($indexGenerator, $key, $row);
132 135
 
@@ -136,8 +139,7 @@  discard block
 block discarded – undo
136 139
 
137 140
             if (!isset($out[$newIndex])) {
138 141
                 $out[$newIndex] = $transformedRow;
139
-            }
140
-            else {
142
+            } else {
141 143
                 $out[$newIndex] = call_user_func(
142 144
                     $conflictResolver,
143 145
                     $newIndex,
@@ -161,8 +163,9 @@  discard block
 block discarded – undo
161 163
      */
162 164
     public function mergeWith( $otherTable, callable $conflictResolver=null )
163 165
     {
164
-        if (is_array($otherTable))
165
-            $otherTable = new static($otherTable);
166
+        if (is_array($otherTable)) {
167
+                    $otherTable = new static($otherTable);
168
+        }
166 169
 
167 170
         if (!$otherTable instanceof static) {
168 171
             self::throwUsageException(
@@ -176,10 +179,10 @@  discard block
 block discarded – undo
176 179
 
177 180
             if (!isset($out[$key])) {
178 181
                 $out[$key] = $row;
179
-            }
180
-            else {
181
-                if ($conflictResolver === null)
182
-                    self::throwUsageException('No conflict resolver for a merge provoking one');
182
+            } else {
183
+                if ($conflictResolver === null) {
184
+                                    self::throwUsageException('No conflict resolver for a merge provoking one');
185
+                }
183 186
 
184 187
                 $arguments = [
185 188
                     &$key,
@@ -265,8 +268,7 @@  discard block
 block discarded – undo
265 268
                     $row[$new_name] = $row[$old_name];
266 269
                     unset($row[$old_name]);
267 270
                 }
268
-            }
269
-            catch (\Exception $e) {
271
+            } catch (\Exception $e) {
270 272
                 self::throwUsageException( $e->getMessage() );
271 273
             }
272 274
 
@@ -287,17 +289,19 @@  discard block
 block discarded – undo
287 289
     public function limit()
288 290
     {
289 291
         $arguments = func_get_args();
290
-        if (count($arguments) == 1 && is_numeric($arguments[0]))
291
-            $max = $arguments[0];
292
-        else
293
-            self::throwUsageException("Bad arguments type and count for limit()");
292
+        if (count($arguments) == 1 && is_numeric($arguments[0])) {
293
+                    $max = $arguments[0];
294
+        } else {
295
+                    self::throwUsageException("Bad arguments type and count for limit()");
296
+        }
294 297
 
295 298
         $out   = [];
296 299
         $count = 0;
297 300
         foreach ($this->data as $key => $row) {
298 301
 
299
-            if ($max <= $count)
300
-                break;
302
+            if ($max <= $count) {
303
+                            break;
304
+            }
301 305
 
302 306
             $out[$key] = $row;
303 307
 
@@ -321,8 +325,9 @@  discard block
 block discarded – undo
321 325
      */
322 326
     public function append($new_rows, callable $conflict_resolver=null)
323 327
     {
324
-        if ($new_rows instanceof static)
325
-            $new_rows = $new_rows->getArray();
328
+        if ($new_rows instanceof static) {
329
+                    $new_rows = $new_rows->getArray();
330
+        }
326 331
 
327 332
         if (!is_array($new_rows)) {
328 333
             $this->throwUsageException(
@@ -347,8 +352,7 @@  discard block
 block discarded – undo
347 352
                 ];
348 353
 
349 354
                 call_user_func_array($conflict_resolver, $arguments);
350
-            }
351
-            else {
355
+            } else {
352 356
                 $this->data[$key] = $new_row;
353 357
             }
354 358
         }
@@ -458,8 +462,7 @@  discard block
 block discarded – undo
458 462
                 foreach ($rows as $row_id => $joined_row) {
459 463
                     $out[$row_id] = $joined_row;
460 464
                 }
461
-            }
462
-            else {
465
+            } else {
463 466
 
464 467
                 if (!isset($rows)) {
465 468
                     echo json_encode([
@@ -469,8 +472,9 @@  discard block
 block discarded – undo
469 472
                     exit;
470 473
                 }
471 474
 
472
-                foreach ($rowIdParts as $rowIdPartName => $rowIdPartValue)
473
-                    $row[$rowIdPartName] = $rowIdPartValue;
475
+                foreach ($rowIdParts as $rowIdPartName => $rowIdPartValue) {
476
+                                    $row[$rowIdPartName] = $rowIdPartValue;
477
+                }
474 478
 
475 479
                 $indexParts = [];
476 480
                 foreach ($rowIdParts as $name => $value) {
@@ -523,8 +527,7 @@  discard block
 block discarded – undo
523 527
             if (is_string($value) && array_key_exists($value, $row)) {
524 528
                 $part_name  .= $value;
525 529
                 $group_value = $row[ $value ];
526
-            }
527
-            elseif (is_callable($value)) {
530
+            } elseif (is_callable($value)) {
528 531
 
529 532
                 if (is_string($value)) {
530 533
                     $part_name  .= $value;
@@ -533,20 +536,17 @@  discard block
 block discarded – undo
533 536
                 elseif (is_object($value) && ($value instanceof \Closure)) {
534 537
                     $part_name .= 'unnamed-closure-'
535 538
                                 . hash('crc32b', var_export($value, true));
536
-                }
537
-                elseif (is_array($value)) {
539
+                } elseif (is_array($value)) {
538 540
                     $part_name .= implode('::', $value);
539 541
                 }
540 542
 
541 543
                 $group_value = call_user_func_array($value, [
542 544
                     $row, &$part_name
543 545
                 ]);
544
-            }
545
-            elseif (is_int($value)) {
546
+            } elseif (is_int($value)) {
546 547
                 $part_name  .= $value ? : '0';
547 548
                 $group_value = $row[ $value ];
548
-            }
549
-            else {
549
+            } else {
550 550
                 self::throwUsageException(
551 551
                     'Bad value provided for groupBy id generation: '
552 552
                     .var_export($value, true)
@@ -554,8 +554,9 @@  discard block
 block discarded – undo
554 554
                 );
555 555
             }
556 556
 
557
-            if (!is_null($part_name))
558
-                $group_parts[ $part_name ] = $group_value;
557
+            if (!is_null($part_name)) {
558
+                            $group_parts[ $part_name ] = $group_value;
559
+            }
559 560
         }
560 561
 
561 562
         // sort the groups by names (without it the same group could have multiple ids)
@@ -576,12 +577,12 @@  discard block
 block discarded – undo
576 577
     public function first($strict=false)
577 578
     {
578 579
         if (!$this->count()) {
579
-            if ($strict)
580
-                throw new \ErrorException("No first element found in this array");
581
-            else
582
-                $first = null;
583
-        }
584
-        else {
580
+            if ($strict) {
581
+                            throw new \ErrorException("No first element found in this array");
582
+            } else {
583
+                            $first = null;
584
+            }
585
+        } else {
585 586
             $key   = key($this->data);
586 587
             $first = reset($this->data);
587 588
             $this->move($key);
@@ -598,12 +599,12 @@  discard block
 block discarded – undo
598 599
     public function last($strict=false)
599 600
     {
600 601
         if (!$this->count()) {
601
-            if ($strict)
602
-                throw new \ErrorException("No last element found in this array");
603
-            else
604
-                $last = null;
605
-        }
606
-        else {
602
+            if ($strict) {
603
+                            throw new \ErrorException("No last element found in this array");
604
+            } else {
605
+                            $last = null;
606
+            }
607
+        } else {
607 608
             $key  = key($this->data);
608 609
             $last = end($this->data);
609 610
             $this->move($key);
@@ -618,12 +619,12 @@  discard block
 block discarded – undo
618 619
     public function firstKey($strict=false)
619 620
     {
620 621
         if (!$this->count()) {
621
-            if ($strict)
622
-                throw new \ErrorException("No last element found in this array");
623
-            else
624
-                $firstKey = null;
625
-        }
626
-        else {
622
+            if ($strict) {
623
+                            throw new \ErrorException("No last element found in this array");
624
+            } else {
625
+                            $firstKey = null;
626
+            }
627
+        } else {
627 628
             $key      = key($this->data);
628 629
             reset($this->data);
629 630
             $firstKey = key($this->data);
@@ -639,12 +640,12 @@  discard block
 block discarded – undo
639 640
     public function lastKey($strict=false)
640 641
     {
641 642
         if (!$this->count()) {
642
-            if ($strict)
643
-                throw new \ErrorException("No last element found in this array");
644
-            else
645
-                $lastKey = null;
646
-        }
647
-        else {
643
+            if ($strict) {
644
+                            throw new \ErrorException("No last element found in this array");
645
+            } else {
646
+                            $lastKey = null;
647
+            }
648
+        } else {
648 649
             $key  = key($this->data);
649 650
             end($this->data);
650 651
             $lastKey = key($this->data);
@@ -666,8 +667,7 @@  discard block
 block discarded – undo
666 667
                     break;
667 668
                 }
668 669
             }
669
-        }
670
-        elseif ($strict) {
670
+        } elseif ($strict) {
671 671
             throw new \ErrorException("Unable to move the internal pointer to a key that doesn't exist.");
672 672
         }
673 673
 
@@ -734,8 +734,9 @@  discard block
 block discarded – undo
734 734
             'data'     => $this->data,
735 735
         ]);
736 736
 
737
-        if ($exit)
738
-            exit;
737
+        if ($exit) {
738
+                    exit;
739
+        }
739 740
 
740 741
         return $this;
741 742
     }
Please login to merge, or discard this patch.
src/Arrays.php 1 patch
Braces   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -64,14 +64,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
                     {
@@ -173,8 +169,7 @@  discard block
 block discarded – undo
173 169
                         $column,
174 170
                     ]
175 171
                 );
176
-            }
177
-            else {
172
+            } else {
178 173
                 // same resolution as array_merge_recursive
179 174
                 if (!is_array($existing_value)) {
180 175
                     $existing_row[$column] = [$existing_value];
@@ -245,15 +240,18 @@  discard block
 block discarded – undo
245 240
                           ;
246 241
 
247 242
         foreach ($row as $column => &$values) {
248
-            if ( ! $values instanceof MergeBucket)
249
-                continue;
243
+            if ( ! $values instanceof MergeBucket) {
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 = Arrays::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;
@@ -278,11 +276,13 @@  discard block
 block discarded – undo
278 276
                           ;
279 277
 
280 278
         foreach ($row as $column => &$values) {
281
-            if (in_array($column, $excluded_columns))
282
-                continue;
279
+            if (in_array($column, $excluded_columns)) {
280
+                            continue;
281
+            }
283 282
 
284
-            if ($values instanceof MergeBucket)
285
-                $values = $values->toArray();
283
+            if ($values instanceof MergeBucket) {
284
+                            $values = $values->toArray();
285
+            }
286 286
         }
287 287
 
288 288
         return $row;
@@ -304,8 +304,7 @@  discard block
 block discarded – undo
304 304
         foreach ($array as $key => $value) {
305 305
             if (is_scalar($value)) {
306 306
                 $id = $value;
307
-            }
308
-            else {
307
+            } else {
309 308
                 $id = serialize($value);
310 309
             }
311 310
 
@@ -329,11 +328,9 @@  discard block
 block discarded – undo
329 328
 
330 329
         if (is_array($array)) {
331 330
             return array_key_exists($key, $array);
332
-        }
333
-        elseif ($array instanceof ChainableArray || method_exists($array, 'keyExists')) {
331
+        } elseif ($array instanceof ChainableArray || method_exists($array, 'keyExists')) {
334 332
             return $array->keyExists($key);
335
-        }
336
-        else {
333
+        } else {
337 334
             throw new \InvalidArgumentException(
338 335
                 "keyExists() method missing on :\n". var_export($array, true)
339 336
             );
@@ -359,16 +356,13 @@  discard block
 block discarded – undo
359 356
         foreach ($array as $key => &$value) { // &for optimization
360 357
             if (is_scalar($value)) {
361 358
                 $sum += $value;
362
-            }
363
-            elseif (is_null($value)) {
359
+            } elseif (is_null($value)) {
364 360
                 continue;
365
-            }
366
-            elseif (is_array($value)) {
361
+            } elseif (is_array($value)) {
367 362
                 throw new \InvalidArgumentException(
368 363
                     "Trying to sum an array with '$sum': ".var_export($value, true)
369 364
                 );
370
-            }
371
-            elseif (is_object($value)) {
365
+            } elseif (is_object($value)) {
372 366
                 if ( ! method_exists($value, 'toNumber')) {
373 367
                     throw new \InvalidArgumentEXception(
374 368
                          "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
@@ -395,17 +389,21 @@  discard block
 block discarded – undo
395 389
      */
396 390
     public static function weightedMean($values, $weights)
397 391
     {
398
-        if ($values instanceof ChainableArray)
399
-            $values = $values->toArray();
392
+        if ($values instanceof ChainableArray) {
393
+                    $values = $values->toArray();
394
+        }
400 395
 
401
-        if ($weights instanceof ChainableArray)
402
-            $weights = $weights->toArray();
396
+        if ($weights instanceof ChainableArray) {
397
+                    $weights = $weights->toArray();
398
+        }
403 399
 
404
-        if ( ! is_array($values))
405
-            $values = [$values];
400
+        if ( ! is_array($values)) {
401
+                    $values = [$values];
402
+        }
406 403
 
407
-        if ( ! is_array($weights))
408
-            $weights = [$weights];
404
+        if ( ! is_array($weights)) {
405
+                    $weights = [$weights];
406
+        }
409 407
 
410 408
         if (count($values) != count($weights)) {
411 409
             throw new \InvalidArgumentException(
@@ -416,12 +414,14 @@  discard block
 block discarded – undo
416 414
             );
417 415
         }
418 416
 
419
-        if (!$values)
420
-            return null;
417
+        if (!$values) {
418
+                    return null;
419
+        }
421 420
 
422 421
         $weights_sum  = array_sum($weights);
423
-        if (!$weights_sum)
424
-            return 0;
422
+        if (!$weights_sum) {
423
+                    return 0;
424
+        }
425 425
 
426 426
         $weighted_sum = 0;
427 427
         foreach ($values as $i => $value) {
Please login to merge, or discard this patch.