Passed
Push — master ( 6a4583...107afa )
by Jean
02:44
created
src/Arrays.php 3 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         $excluded_columns = isset($options['excluded_columns'])
243 243
                           ? $options['excluded_columns']
244 244
                           : []
245
-                          ;
245
+                            ;
246 246
 
247 247
         foreach ($row as $column => &$values) {
248 248
             if ( ! $values instanceof MergeBucket)
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         $excluded_columns = isset($options['excluded_columns'])
276 276
                           ? $options['excluded_columns']
277 277
                           : []
278
-                          ;
278
+                            ;
279 279
 
280 280
         foreach ($row as $column => &$values) {
281 281
             if (in_array($column, $excluded_columns))
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
             elseif (is_object($value)) {
372 372
                 if ( ! method_exists($value, 'toNumber')) {
373 373
                     throw new \InvalidArgumentEXception(
374
-                         "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
374
+                            "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
375 375
                         ."Please add a toNumber() method."
376 376
                     );
377 377
                 }
@@ -555,12 +555,12 @@  discard block
 block discarded – undo
555 555
         $key_value_separator = ! empty($options['key_value_separator'])
556 556
                              ? $options['key_value_separator']
557 557
                              : ':'
558
-                             ;
558
+                                ;
559 559
 
560 560
         $groups_separator    = ! empty($options['groups_separator'])
561 561
                              ? $options['groups_separator']
562 562
                              : '-'
563
-                             ;
563
+                                ;
564 564
 
565 565
         $group_parts = [];
566 566
         foreach ($groups_definitions as $group_definition_key => $group_definition_value) {
@@ -618,8 +618,8 @@  discard block
 block discarded – undo
618 618
         foreach ($group_parts as $group_name => $group_value) {
619 619
             if (is_object($group_value)) {
620 620
                 $group_value = get_class($group_value)
621
-                             . '_'
622
-                             . hash( 'crc32b', var_export($group_value, true) );
621
+                                . '_'
622
+                                . hash( 'crc32b', var_export($group_value, true) );
623 623
             }
624 624
             elseif (is_array($group_value)) {
625 625
                 $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) );
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -134,16 +134,16 @@  discard block
 block discarded – undo
134 134
     public static function mergeRecursiveCustom(
135 135
         $existing_row,
136 136
         $conflict_row,
137
-        callable $merge_resolver=null,
138
-        $max_depth=null
139
-    ){
137
+        callable $merge_resolver = null,
138
+        $max_depth = null
139
+    ) {
140 140
         static::mustBeCountable($existing_row);
141 141
         static::mustBeCountable($conflict_row);
142 142
 
143 143
         foreach ($conflict_row as $column => $conflict_value) {
144 144
 
145 145
             // not existing in first array
146
-            if (!isset($existing_row[$column])) {
146
+            if ( ! isset($existing_row[$column])) {
147 147
                 $existing_row[$column] = $conflict_value;
148 148
                 continue;
149 149
             }
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
             }
177 177
             else {
178 178
                 // same resolution as array_merge_recursive
179
-                if (!is_array($existing_value)) {
179
+                if ( ! is_array($existing_value)) {
180 180
                     $existing_row[$column] = [$existing_value];
181 181
                 }
182 182
 
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
     public static function mergePreservingDistincts(
200 200
         $existing_row,
201 201
         $conflict_row
202
-    ){
202
+    ) {
203 203
         static::mustBeCountable($existing_row);
204 204
         static::mustBeCountable($conflict_row);
205 205
 
206 206
         $merge = static::mergeRecursiveCustom(
207 207
             $existing_row,
208 208
             $conflict_row,
209
-            function ($existing_value, $conflict_value, $column) {
209
+            function($existing_value, $conflict_value, $column) {
210 210
 
211 211
                 if ( ! $existing_value instanceof MergeBucket) {
212 212
                     $existing_value = MergeBucket::from()->push($existing_value);
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      * @param  array|Countable   $row
236 236
      * @param  array             $options : 'excluded_columns'
237 237
      */
238
-    public static function cleanMergeDuplicates($row, array $options=[])
238
+    public static function cleanMergeDuplicates($row, array $options = [])
239 239
     {
240 240
         static::mustBeCountable($row);
241 241
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      * @see mergePreservingDistincts()
269 269
      * @see cleanMergeDuplicates()
270 270
      */
271
-    public static function cleanMergeBuckets($row, array $options=[])
271
+    public static function cleanMergeBuckets($row, array $options = [])
272 272
     {
273 273
         static::mustBeCountable($row);
274 274
 
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
                 $id = serialize($value);
310 310
             }
311 311
 
312
-            if (isset($ids[ $id ])) {
313
-                unset($array[ $key ]);
314
-                $ids[ $id ][] = $key;
312
+            if (isset($ids[$id])) {
313
+                unset($array[$key]);
314
+                $ids[$id][] = $key;
315 315
                 continue;
316 316
             }
317 317
 
318
-            $ids[ $id ] = [$key];
318
+            $ids[$id] = [$key];
319 319
         }
320 320
 
321 321
         return $array;
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
         }
336 336
         else {
337 337
             throw new \InvalidArgumentException(
338
-                "keyExists() method missing on :\n". var_export($array, true)
338
+                "keyExists() method missing on :\n".var_export($array, true)
339 339
             );
340 340
         }
341 341
 
@@ -411,16 +411,16 @@  discard block
 block discarded – undo
411 411
             throw new \InvalidArgumentException(
412 412
                 "Different number of "
413 413
                 ." values and weights for weight mean calculation: \n"
414
-                .var_export($values,  true)."\n\n"
414
+                .var_export($values, true)."\n\n"
415 415
                 .var_export($weights, true)
416 416
             );
417 417
         }
418 418
 
419
-        if (!$values)
419
+        if ( ! $values)
420 420
             return null;
421 421
 
422
-        $weights_sum  = array_sum($weights);
423
-        if (!$weights_sum)
422
+        $weights_sum = array_sum($weights);
423
+        if ( ! $weights_sum)
424 424
             return 0;
425 425
 
426 426
         $weighted_sum = 0;
@@ -469,8 +469,8 @@  discard block
 block discarded – undo
469 469
         );
470 470
 
471 471
         // The true location of the throw is still available through the backtrace
472
-        $trace_location  = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
473
-        $reflectionClass = new \ReflectionClass( get_class($exception) );
472
+        $trace_location  = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
473
+        $reflectionClass = new \ReflectionClass(get_class($exception));
474 474
 
475 475
         // file
476 476
         if (isset($trace_location['file'])) {
@@ -507,8 +507,8 @@  discard block
 block discarded – undo
507 507
         );
508 508
 
509 509
         // The true location of the throw is still available through the backtrace
510
-        $trace_location  = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
511
-        $reflectionClass = new \ReflectionClass( get_class($exception) );
510
+        $trace_location  = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
511
+        $reflectionClass = new \ReflectionClass(get_class($exception));
512 512
 
513 513
         // file
514 514
         if (isset($trace_location['file'])) {
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
      *
549 549
      * @return string       The unique identifier of the group
550 550
      */
551
-    public static function generateGroupId($row, array $groups_definitions, array $options=[])
551
+    public static function generateGroupId($row, array $groups_definitions, array $options = [])
552 552
     {
553 553
         Arrays::mustBeCountable($row);
554 554
 
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
                              : ':'
558 558
                              ;
559 559
 
560
-        $groups_separator    = ! empty($options['groups_separator'])
560
+        $groups_separator = ! empty($options['groups_separator'])
561 561
                              ? $options['groups_separator']
562 562
                              : '-'
563 563
                              ;
@@ -572,11 +572,11 @@  discard block
 block discarded – undo
572 572
 
573 573
             if (is_string($group_definition_value) && array_key_exists($group_definition_value, $row)) {
574 574
                 $part_name         .= $group_definition_value;
575
-                $group_result_value = $row[ $group_definition_value ];
575
+                $group_result_value = $row[$group_definition_value];
576 576
             }
577 577
             elseif (is_int($group_definition_value)) {
578
-                $part_name         .= $group_definition_value ? : '0';
579
-                $group_result_value = $row[ $group_definition_value ];
578
+                $part_name         .= $group_definition_value ?: '0';
579
+                $group_result_value = $row[$group_definition_value];
580 580
             }
581 581
             /* TODO check this is not just dead code * /
582 582
             elseif (is_callable($group_definition_value)) {
@@ -602,12 +602,12 @@  discard block
 block discarded – undo
602 602
                 self::throwUsageException(
603 603
                     'Bad value provided for groupBy id generation: '
604 604
                     .var_export($group_definition_value, true)
605
-                    ."\n" . var_export($row, true)
605
+                    ."\n".var_export($row, true)
606 606
                 );
607 607
             }
608 608
 
609
-            if (!is_null($part_name))
610
-                $group_parts[ $part_name ] = $group_result_value;
609
+            if ( ! is_null($part_name))
610
+                $group_parts[$part_name] = $group_result_value;
611 611
         }
612 612
 
613 613
         // sort the groups by names (without it the same group could have multiple ids)
@@ -619,13 +619,13 @@  discard block
 block discarded – undo
619 619
             if (is_object($group_value)) {
620 620
                 $group_value = get_class($group_value)
621 621
                              . '_'
622
-                             . hash( 'crc32b', var_export($group_value, true) );
622
+                             . hash('crc32b', var_export($group_value, true));
623 623
             }
624 624
             elseif (is_array($group_value)) {
625
-                $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) );
625
+                $group_value = 'array_'.hash('crc32b', var_export($group_value, true));
626 626
             }
627 627
 
628
-            $out[] = $group_name . $key_value_separator . $group_value;
628
+            $out[] = $group_name.$key_value_separator.$group_value;
629 629
         }
630 630
 
631 631
         return implode($groups_separator, $out);
Please login to merge, or discard this patch.
Braces   +55 added lines, -54 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) {
@@ -460,8 +460,9 @@  discard block
 block discarded – undo
460 460
      */
461 461
     public static function mustBeCountable($value)
462 462
     {
463
-        if (static::isCountable($value))
464
-            return true;
463
+        if (static::isCountable($value)) {
464
+                    return true;
465
+        }
465 466
 
466 467
         $exception = new \InvalidArgumentException(
467 468
             "A value must be Countable instead of: \n"
@@ -498,8 +499,9 @@  discard block
 block discarded – undo
498 499
      */
499 500
     public static function mustBeTraversable($value)
500 501
     {
501
-        if (static::isTraversable($value))
502
-            return true;
502
+        if (static::isTraversable($value)) {
503
+                    return true;
504
+        }
503 505
 
504 506
         $exception = new \InvalidArgumentException(
505 507
             "A value must be Traversable instead of: \n"
@@ -573,8 +575,7 @@  discard block
 block discarded – undo
573 575
             if (is_string($group_definition_value) && array_key_exists($group_definition_value, $row)) {
574 576
                 $part_name         .= $group_definition_value;
575 577
                 $group_result_value = $row[ $group_definition_value ];
576
-            }
577
-            elseif (is_int($group_definition_value)) {
578
+            } elseif (is_int($group_definition_value)) {
578 579
                 $part_name         .= $group_definition_value ? : '0';
579 580
                 $group_result_value = $row[ $group_definition_value ];
580 581
             }
@@ -606,8 +607,9 @@  discard block
 block discarded – undo
606 607
                 );
607 608
             }
608 609
 
609
-            if (!is_null($part_name))
610
-                $group_parts[ $part_name ] = $group_result_value;
610
+            if (!is_null($part_name)) {
611
+                            $group_parts[ $part_name ] = $group_result_value;
612
+            }
611 613
         }
612 614
 
613 615
         // sort the groups by names (without it the same group could have multiple ids)
@@ -620,8 +622,7 @@  discard block
 block discarded – undo
620 622
                 $group_value = get_class($group_value)
621 623
                              . '_'
622 624
                              . hash( 'crc32b', var_export($group_value, true) );
623
-            }
624
-            elseif (is_array($group_value)) {
625
+            } elseif (is_array($group_value)) {
625 626
                 $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) );
626 627
             }
627 628
 
Please login to merge, or discard this patch.
src/ChainableArray_Utils_Trait.php 2 patches
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
      *
19 19
      * @return array The array containing the grouped rows.
20 20
      */
21
-    public function groupBy( callable $indexGenerator, callable $conflictResolver=null )
21
+    public function groupBy(callable $indexGenerator, callable $conflictResolver = null)
22 22
     {
23 23
         // todo : this doesn't work
24 24
         // return $this->groupByTransformed($indexGenerator, null, $conflictResolver);
@@ -26,15 +26,15 @@  discard block
 block discarded – undo
26 26
         $out = [];
27 27
         foreach ($this->data as $key => $row) {
28 28
 
29
-            if (!$row)
29
+            if ( ! $row)
30 30
                 continue;
31 31
 
32 32
             $newIndexes     = call_user_func($indexGenerator, $key, $row);
33
-            if (!is_array($newIndexes))
33
+            if ( ! is_array($newIndexes))
34 34
                 $newIndexes = [$newIndexes];
35 35
 
36 36
             foreach ($newIndexes as $newIndex) {
37
-                if (!isset($out[$newIndex])) {
37
+                if ( ! isset($out[$newIndex])) {
38 38
                     $out[$newIndex] = $row;
39 39
                 }
40 40
                 else {
@@ -69,26 +69,26 @@  discard block
 block discarded – undo
69 69
      *
70 70
      * @return array The array containing the grouped rows.
71 71
      */
72
-    public function groupInArrays( callable $indexGenerator )
72
+    public function groupInArrays(callable $indexGenerator)
73 73
     {
74 74
         $out = [];
75 75
         foreach ($this->data as $key => $row) {
76 76
 
77
-            if (!$row)
77
+            if ( ! $row)
78 78
                 continue;
79 79
 
80 80
             $new_keys = call_user_func($indexGenerator, $row, $key);
81
-            if (!is_array($new_keys))
81
+            if ( ! is_array($new_keys))
82 82
                 $new_keys = [$new_keys];
83 83
 
84 84
             foreach ($new_keys as $new_key) {
85
-                if (!isset($out[ $new_key ])) {
86
-                    $out[ $new_key ] = [
85
+                if ( ! isset($out[$new_key])) {
86
+                    $out[$new_key] = [
87 87
                         $key => $row
88 88
                     ];
89 89
                 }
90 90
                 else {
91
-                    $out[ $new_key ][ $key ] = $row;
91
+                    $out[$new_key][$key] = $row;
92 92
                 }
93 93
             }
94 94
         }
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      */
113 113
     public function groupByTransformed(
114 114
         callable $indexGenerator,
115
-        callable $rowTransformer,      // todo check this behavior
115
+        callable $rowTransformer, // todo check this behavior
116 116
         callable $conflictResolver )
117 117
     {
118 118
         // The goal here is to remove the second parameter has it makes the
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
         $out = [];
126 126
         foreach ($this->data as $key => $row) {
127 127
 
128
-            if (!$row)
128
+            if ( ! $row)
129 129
                 continue;
130 130
 
131 131
             $newIndex       = call_user_func($indexGenerator, $key, $row);
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                             ? call_user_func($rowTransformer, $row)
135 135
                             : $row;
136 136
 
137
-            if (!isset($out[$newIndex])) {
137
+            if ( ! isset($out[$newIndex])) {
138 138
                 $out[$newIndex] = $transformedRow;
139 139
             }
140 140
             else {
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
      *                                       rows have the same index.
160 160
      * @return static
161 161
      */
162
-    public function mergeWith( $otherTable, callable $conflictResolver=null )
162
+    public function mergeWith($otherTable, callable $conflictResolver = null)
163 163
     {
164 164
         if (is_array($otherTable))
165 165
             $otherTable = new static($otherTable);
166 166
 
167
-        if (!$otherTable instanceof static) {
167
+        if ( ! $otherTable instanceof static) {
168 168
             self::throwUsageException(
169 169
                 '$otherTable must be an array or an instance of '.static::class.' instead of: '
170 170
                 .var_export($otherTable, true)
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
         $out = $this->data;
175 175
         foreach ($otherTable->getArray() as $key => $row) {
176 176
 
177
-            if (!isset($out[$key])) {
177
+            if ( ! isset($out[$key])) {
178 178
                 $out[$key] = $row;
179 179
             }
180 180
             else {
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
      * (same as self::mergeWith with the other table as $this)
203 203
      * @return static
204 204
      */
205
-    public function mergeIn( $otherTable, callable $conflictResolver=null )
205
+    public function mergeIn($otherTable, callable $conflictResolver = null)
206 206
     {
207 207
         $otherTable->mergeWith($this, $conflictResolver);
208 208
         return $this;
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
      */
229 229
     public function each(callable $rowTransformer)
230 230
     {
231
-        $out  = [];
231
+        $out = [];
232 232
         foreach ($this->data as $key => $row) {
233 233
             $out[$key] = call_user_func_array(
234 234
                 $rowTransformer,
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      */
259 259
     public function renameColumns(array $old_to_new_names)
260 260
     {
261
-        $out  = [];
261
+        $out = [];
262 262
         foreach ($this->data as $key => $row) {
263 263
             try {
264 264
                 foreach ($old_to_new_names as $old_name => $new_name) {
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
                 }
268 268
             }
269 269
             catch (\Exception $e) {
270
-                self::throwUsageException( $e->getMessage() );
270
+                self::throwUsageException($e->getMessage());
271 271
             }
272 272
 
273 273
             $out[$key] = $row;
@@ -319,20 +319,20 @@  discard block
 block discarded – undo
319 319
      *                            nor a static.
320 320
      * @return static       $this
321 321
      */
322
-    public function append($new_rows, callable $conflict_resolver=null)
322
+    public function append($new_rows, callable $conflict_resolver = null)
323 323
     {
324 324
         if ($new_rows instanceof static)
325 325
             $new_rows = $new_rows->getArray();
326 326
 
327
-        if (!is_array($new_rows)) {
327
+        if ( ! is_array($new_rows)) {
328 328
             $this->throwUsageException(
329
-                "\$new_rows parameter must be an array or an instance of " . __CLASS__
329
+                "\$new_rows parameter must be an array or an instance of ".__CLASS__
330 330
             );
331 331
         }
332 332
 
333
-        if (!$conflict_resolver) {
333
+        if ( ! $conflict_resolver) {
334 334
             // default conflict resolver: append with numeric key
335
-            $conflict_resolver = function (&$data, $existing_row, $confliuct_row, $key) {
335
+            $conflict_resolver = function(&$data, $existing_row, $confliuct_row, $key) {
336 336
                 $data[] = $confliuct_row;
337 337
             };
338 338
         }
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
      *
365 365
      * @return static
366 366
      */
367
-    public function dimensionsAsColumns(array $columnNames, array $options=null)
367
+    public function dimensionsAsColumns(array $columnNames, array $options = null)
368 368
     {
369 369
         $out = $this->dimensionsAsColumns_recurser($this->data, $columnNames);
370 370
         return $this->returnConstant($out);
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
      *      ],
402 402
      * ]
403 403
      */
404
-    protected function dimensionsAsColumns_recurser(array $data, $columnNames, $rowIdParts=[])
404
+    protected function dimensionsAsColumns_recurser(array $data, $columnNames, $rowIdParts = [])
405 405
     {
406 406
         $out = [];
407 407
         // if (!$columnNames)
408 408
             // return $data;
409
-        $no_more_column = !(bool) $columnNames;
409
+        $no_more_column = ! (bool) $columnNames;
410 410
 
411 411
         // If all the names have been given to the dimensions
412 412
         // we compile the index key of the row at the current level
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
                     self::throwUsageException(
431 431
                          "Trying to populate a column '$name' that "
432 432
                         ."already exists with a different value "
433
-                        .var_export($data[$name], true). " => '$value'"
433
+                        .var_export($data[$name], true)." => '$value'"
434 434
                     );
435 435
                 }
436 436
                 $data[$name] = $value;
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
             }
462 462
             else {
463 463
 
464
-                if (!isset($rows)) {
464
+                if ( ! isset($rows)) {
465 465
                     echo json_encode([
466 466
                         '$rowIdParts' => $rowIdParts,
467 467
                         '$row' => $row,
@@ -489,9 +489,9 @@  discard block
 block discarded – undo
489 489
     /**
490 490
      * Returns the first element of the array
491 491
      */
492
-    public function first($strict=false)
492
+    public function first($strict = false)
493 493
     {
494
-        if (!$this->count()) {
494
+        if ( ! $this->count()) {
495 495
             if ($strict)
496 496
                 throw new \ErrorException("No first element found in this array");
497 497
             else
@@ -511,9 +511,9 @@  discard block
 block discarded – undo
511 511
      *
512 512
      * @todo Preserve the offset
513 513
      */
514
-    public function last($strict=false)
514
+    public function last($strict = false)
515 515
     {
516
-        if (!$this->count()) {
516
+        if ( ! $this->count()) {
517 517
             if ($strict)
518 518
                 throw new \ErrorException("No last element found in this array");
519 519
             else
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
     /**
532 532
      *
533 533
      */
534
-    public function firstKey($strict=false)
534
+    public function firstKey($strict = false)
535 535
     {
536
-        if (!$this->count()) {
536
+        if ( ! $this->count()) {
537 537
             if ($strict)
538 538
                 throw new \ErrorException("No last element found in this array");
539 539
             else
@@ -552,16 +552,16 @@  discard block
 block discarded – undo
552 552
     /**
553 553
      *
554 554
      */
555
-    public function lastKey($strict=false)
555
+    public function lastKey($strict = false)
556 556
     {
557
-        if (!$this->count()) {
557
+        if ( ! $this->count()) {
558 558
             if ($strict)
559 559
                 throw new \ErrorException("No last element found in this array");
560 560
             else
561 561
                 $lastKey = null;
562 562
         }
563 563
         else {
564
-            $key  = key($this->data);
564
+            $key = key($this->data);
565 565
             end($this->data);
566 566
             $lastKey = key($this->data);
567 567
             $this->move($key);
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
     /**
574 574
      * Move the internal pointer of the array to the key given as parameter
575 575
      */
576
-    public function move($key, $strict=true)
576
+    public function move($key, $strict = true)
577 577
     {
578 578
         if (array_key_exists($key, $this->data)) {
579 579
             foreach ($this->data as $i => &$value) {
@@ -640,13 +640,13 @@  discard block
 block discarded – undo
640 640
      * @see http://php.net/manual/fr/function.var-dump.php
641 641
      * @todo Handle xdebug dump formatting
642 642
      */
643
-    public function dump($exit=false)
643
+    public function dump($exit = false)
644 644
     {
645 645
         $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
646 646
         $caller = $bt[0];
647 647
 
648 648
         var_export([
649
-            'location' => $caller['file'] . ':' . $caller['line'],
649
+            'location' => $caller['file'].':'.$caller['line'],
650 650
             'data'     => $this->data,
651 651
         ]);
652 652
 
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
      * @todo move it to an Arrays class storing static methods
664 664
      */
665 665
     public static function replaceEntries(
666
-        array $array, callable $replacer, $max_depth=null
666
+        array $array, callable $replacer, $max_depth = null
667 667
     ) {
668 668
         foreach ($array as $key => &$row) {
669 669
             $arguments = [&$row, $key];
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
 
672 672
             if (is_array($row) && $max_depth !== 0) { // allowing null to have no depth limit
673 673
                 $row = self::replaceEntries(
674
-                    $row, $replacer, $max_depth ? $max_depth-1 : $max_depth
674
+                    $row, $replacer, $max_depth ? $max_depth - 1 : $max_depth
675 675
                 );
676 676
             }
677 677
         }
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
      *
688 688
      * @return static $this or a new static.
689 689
      */
690
-    public function extract($callback=null)
690
+    public function extract($callback = null)
691 691
     {
692 692
         if ($callback) {
693 693
 
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
                 $callback = new \JClaveau\LogicalFilter\LogicalFilter($callback);
696 696
             }
697 697
 
698
-            if (!is_callable($callback)) {
698
+            if ( ! is_callable($callback)) {
699 699
                 $this->throwUsageException(
700 700
                     "\$callback must be a logical filter description array or a callable"
701 701
                     ." instead of "
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
             foreach ($this->data as $key => $value) {
708 708
                 if ($callback($value, $key)) {
709 709
                     $out[$key] = $value;
710
-                    unset( $this->data[$key] );
710
+                    unset($this->data[$key]);
711 711
                 }
712 712
             }
713 713
         }
Please login to merge, or discard this patch.
Braces   +70 added lines, -66 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) {
@@ -492,12 +496,12 @@  discard block
 block discarded – undo
492 496
     public function first($strict=false)
493 497
     {
494 498
         if (!$this->count()) {
495
-            if ($strict)
496
-                throw new \ErrorException("No first element found in this array");
497
-            else
498
-                $first = null;
499
-        }
500
-        else {
499
+            if ($strict) {
500
+                            throw new \ErrorException("No first element found in this array");
501
+            } else {
502
+                            $first = null;
503
+            }
504
+        } else {
501 505
             $key   = key($this->data);
502 506
             $first = reset($this->data);
503 507
             $this->move($key);
@@ -514,12 +518,12 @@  discard block
 block discarded – undo
514 518
     public function last($strict=false)
515 519
     {
516 520
         if (!$this->count()) {
517
-            if ($strict)
518
-                throw new \ErrorException("No last element found in this array");
519
-            else
520
-                $last = null;
521
-        }
522
-        else {
521
+            if ($strict) {
522
+                            throw new \ErrorException("No last element found in this array");
523
+            } else {
524
+                            $last = null;
525
+            }
526
+        } else {
523 527
             $key  = key($this->data);
524 528
             $last = end($this->data);
525 529
             $this->move($key);
@@ -534,12 +538,12 @@  discard block
 block discarded – undo
534 538
     public function firstKey($strict=false)
535 539
     {
536 540
         if (!$this->count()) {
537
-            if ($strict)
538
-                throw new \ErrorException("No last element found in this array");
539
-            else
540
-                $firstKey = null;
541
-        }
542
-        else {
541
+            if ($strict) {
542
+                            throw new \ErrorException("No last element found in this array");
543
+            } else {
544
+                            $firstKey = null;
545
+            }
546
+        } else {
543 547
             $key      = key($this->data);
544 548
             reset($this->data);
545 549
             $firstKey = key($this->data);
@@ -555,12 +559,12 @@  discard block
 block discarded – undo
555 559
     public function lastKey($strict=false)
556 560
     {
557 561
         if (!$this->count()) {
558
-            if ($strict)
559
-                throw new \ErrorException("No last element found in this array");
560
-            else
561
-                $lastKey = null;
562
-        }
563
-        else {
562
+            if ($strict) {
563
+                            throw new \ErrorException("No last element found in this array");
564
+            } else {
565
+                            $lastKey = null;
566
+            }
567
+        } else {
564 568
             $key  = key($this->data);
565 569
             end($this->data);
566 570
             $lastKey = key($this->data);
@@ -582,8 +586,7 @@  discard block
 block discarded – undo
582 586
                     break;
583 587
                 }
584 588
             }
585
-        }
586
-        elseif ($strict) {
589
+        } elseif ($strict) {
587 590
             throw new \ErrorException("Unable to move the internal pointer to a key that doesn't exist.");
588 591
         }
589 592
 
@@ -650,8 +653,9 @@  discard block
 block discarded – undo
650 653
             'data'     => $this->data,
651 654
         ]);
652 655
 
653
-        if ($exit)
654
-            exit;
656
+        if ($exit) {
657
+                    exit;
658
+        }
655 659
 
656 660
         return $this;
657 661
     }
Please login to merge, or discard this patch.