Passed
Push — master ( 8e7423...f25c73 )
by Jean
02:38
created
src/polyfills.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!function_exists('spl_object_id')) {
2
+if ( ! function_exists('spl_object_id')) {
3 3
     /**
4 4
      * @see https://secure.php.net/manual/en/function.spl-object-id.php
5 5
      * This method doesn't exist before PHP 7.2.0
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     }
13 13
 }
14 14
 
15
-if (!function_exists('is_iterable')) {
15
+if ( ! function_exists('is_iterable')) {
16 16
     /**
17 17
      * @see https://github.com/symfony/polyfill-php71/commit/36004d119352f4506398032259a08e4ca9607285
18 18
      * This method doesn't exist before PHP 7.1.0
Please login to merge, or discard this patch.
src/Arrays/ChainableArray.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
     /**
29 29
      */
30
-    public static function from($data=[], $isConstant=false)
30
+    public static function from($data = [], $isConstant = false)
31 31
     {
32 32
         Arrays::mustBeCountable($data);
33 33
 
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 
40 40
     /**
41 41
      */
42
-    public function __construct(array $data=[], $isConstant=false)
42
+    public function __construct(array $data = [], $isConstant = false)
43 43
     {
44 44
         $this->data       = $data;
45 45
         $this->isConstant = $isConstant;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      *
84 84
      * @return ChainableArray $this
85 85
      */
86
-    public function setConstant($state=true)
86
+    public function setConstant($state = true)
87 87
     {
88 88
         $this->isConstant = $state;
89 89
         return $this;
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
     /**
163 163
      * Checks if an argument is an array or a ChainableArray
164 164
      */
165
-    private function argumentIsArrayOrArrayObject( $argument )
165
+    private function argumentIsArrayOrArrayObject($argument)
166 166
     {
167 167
         return is_array($argument)
168 168
             || $argument instanceof ChainableArray;
@@ -177,15 +177,15 @@  discard block
 block discarded – undo
177 177
         $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20);
178 178
         $i      = 1;
179 179
         $caller = $backtrace[$i];
180
-        while (     isset($backtrace[$i]['class'])
181
-                &&  $backtrace[$i]['class'] == __CLASS__ ) {
180
+        while (isset($backtrace[$i]['class'])
181
+                &&  $backtrace[$i]['class'] == __CLASS__) {
182 182
             $caller = $backtrace[$i];
183 183
             $i++;
184 184
         }
185 185
 
186 186
         $exception = new \ErrorException($message);
187 187
 
188
-        $reflectionClass = new \ReflectionClass( get_class($exception) );
188
+        $reflectionClass = new \ReflectionClass(get_class($exception));
189 189
 
190 190
         //file
191 191
         $reflectionProperty = $reflectionClass->getProperty('file');
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -31,8 +31,9 @@  discard block
 block discarded – undo
31 31
     {
32 32
         Arrays::mustBeCountable($data);
33 33
 
34
-        if ($data instanceof self)
35
-            return $data;
34
+        if ($data instanceof self) {
35
+                    return $data;
36
+        }
36 37
 
37 38
         return new static($data, $isConstant);
38 39
     }
@@ -101,8 +102,7 @@  discard block
 block discarded – undo
101 102
     {
102 103
         if ($this->isConstant) {
103 104
             return new static($out);
104
-        }
105
-        else {
105
+        } else {
106 106
             $this->data = $out;
107 107
             return $this;
108 108
         }
Please login to merge, or discard this patch.
src/Arrays/ChainableArray_NativeFunctions_Trait.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
                 foreach ($column_names as $column_name) {
35 35
                     if (!array_key_exists($column_name, $row)) {
36 36
                         self::throwUsageException(
37
-                             "Trying to extract a column from a row which"
37
+                                "Trying to extract a column from a row which"
38 38
                             ." doesn't contain it : '$column_name' \n"
39 39
                             .var_export($row, true)
40 40
                         );
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      *                              The current key we be kept if null.
22 22
      * @return $this
23 23
      */
24
-    public function columns($column_names, $index_key=null)
24
+    public function columns($column_names, $index_key = null)
25 25
     {
26 26
         $out = [];
27 27
         foreach ($this->data as $key => &$row) {
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
             if (is_array($column_names)) {
33 33
                 $out[$key] = [];
34 34
                 foreach ($column_names as $column_name) {
35
-                    if (!array_key_exists($column_name, $row)) {
35
+                    if ( ! array_key_exists($column_name, $row)) {
36 36
                         self::throwUsageException(
37 37
                              "Trying to extract a column from a row which"
38 38
                             ." doesn't contain it : '$column_name' \n"
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
                     $keys = [];
61 61
                 }
62 62
 
63
-                if (!in_array($column_names, $keys)) {
63
+                if ( ! in_array($column_names, $keys)) {
64 64
                     self::throwUsageException('A row have no index to '
65 65
                         .'fill the column: '.$column_names."\n"
66 66
                         .$key.' => '.var_export($row, true));
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
      *
79 79
      * @deprecated Use columns() instead
80 80
      */
81
-    public function column($column_names, $index_key=null)
81
+    public function column($column_names, $index_key = null)
82 82
     {
83 83
         return $this->columns($column_names, $index_key);
84 84
     }
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
      * @param  $default_value To use if the array is empty
100 100
      * @return array The min.
101 101
      */
102
-    public function min($default_value=null)
102
+    public function min($default_value = null)
103 103
     {
104 104
         if ($this->isEmpty() && $default_value !== null)
105 105
             return $default_value;
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      * @param  $default_value To use if the array is empty
123 123
      * @return array The max.
124 124
      */
125
-    public function max($default_value=null)
125
+    public function max($default_value = null)
126 126
     {
127 127
         if ($this->isEmpty() && $default_value !== null)
128 128
             return $default_value;
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
      *
180 180
      * @return static $this or a new static.
181 181
      */
182
-    public function filter($callback=null)
182
+    public function filter($callback = null)
183 183
     {
184 184
         if ($callback) {
185 185
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
                 $callback = new \JClaveau\LogicalFilter\LogicalFilter($callback);
188 188
             }
189 189
 
190
-            if (!is_callable($callback)) {
190
+            if ( ! is_callable($callback)) {
191 191
                 $this->throwUsageException(
192 192
                     "\$callback must be a logical filter description array or a callable"
193 193
                     ." instead of "
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
             else {
205 205
                 $out = $this->data;
206 206
                 foreach ($out as $key => $value) {
207
-                    if (!$callback($value, $key))
208
-                        unset( $out[$key] );
207
+                    if ( ! $callback($value, $key))
208
+                        unset($out[$key]);
209 209
                 }
210 210
             }
211 211
         }
@@ -224,10 +224,10 @@  discard block
 block discarded – undo
224 224
      *
225 225
      * @return static $this or a new static.
226 226
      */
227
-    public function filterKey(callable $callback=null)
227
+    public function filterKey(callable $callback = null)
228 228
     {
229 229
         throw new \ErrorException('This method is replaced by '
230
-            . __TRAIT__ . '::filtr()');
230
+            . __TRAIT__.'::filtr()');
231 231
     }
232 232
 
233 233
     /**
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      */
259 259
     public function intersectKey($intersect_with)
260 260
     {
261
-        if (!$this->argumentIsArrayOrArrayObject($intersect_with))
261
+        if ( ! $this->argumentIsArrayOrArrayObject($intersect_with))
262 262
             self::throwUsageException("First argument must be an array or a ".static::class.".");
263 263
 
264 264
         if ($intersect_with instanceof static)
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
     public function unshift()
299 299
     {
300 300
         $data = $this->data;
301
-        $arguments = Arrays::merge( [&$data], func_get_args() );
301
+        $arguments = Arrays::merge([&$data], func_get_args());
302 302
 
303 303
         call_user_func_array('array_unshift', $arguments);
304 304
         return $this->returnConstant($data);
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
     public function push()
313 313
     {
314 314
         $data = $this->data;
315
-        $arguments = Arrays::merge( [&$data], func_get_args() );
315
+        $arguments = Arrays::merge([&$data], func_get_args());
316 316
 
317 317
         call_user_func_array('array_push', $arguments);
318 318
         return $this->returnConstant($data);
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
      *
324 324
      * @return static $this or a new static.
325 325
      */
326
-    public function unique($flags=SORT_STRING)
326
+    public function unique($flags = SORT_STRING)
327 327
     {
328 328
         $out = array_unique($this->data, $flags);
329 329
         return $this->returnConstant($out);
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
      *
350 350
      * @return static $this or a new static.
351 351
      */
352
-    public function diff($compare_with, $check_keys=false, $strict_comparison=false)
352
+    public function diff($compare_with, $check_keys = false, $strict_comparison = false)
353 353
     {
354
-        if (!$this->argumentIsArrayOrArrayObject($compare_with))
354
+        if ( ! $this->argumentIsArrayOrArrayObject($compare_with))
355 355
             self::throwUsageException("First argument must be an iterable");
356 356
 
357 357
         $kept_values = $this->data;
@@ -364,14 +364,14 @@  discard block
 block discarded – undo
364 364
                 if ($check_keys) {
365 365
 
366 366
                     if ($strict_comparison) {
367
-                        if (    $kept_key   === $compared_key
368
-                            &&  $kept_value === $compared_value ) {
367
+                        if ($kept_key === $compared_key
368
+                            &&  $kept_value === $compared_value) {
369 369
                             $is_equal = true;
370 370
                         }
371 371
                     }
372 372
                     else {
373
-                        if (    $kept_key   == $compared_key
374
-                            &&  $kept_value == $compared_value ) {
373
+                        if ($kept_key == $compared_key
374
+                            &&  $kept_value == $compared_value) {
375 375
                             $is_equal = true;
376 376
                         }
377 377
                     }
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 
392 392
                 if ($is_equal) {
393 393
                     // Debug::dumpJson($kept_key, !true);
394
-                    unset($kept_values[ $kept_key ]);
394
+                    unset($kept_values[$kept_key]);
395 395
                     break;
396 396
                 }
397 397
             }
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
      */
422 422
     public function fillKeys($keys, $value)
423 423
     {
424
-        if (!$this->argumentIsArrayOrArrayObject($keys))
424
+        if ( ! $this->argumentIsArrayOrArrayObject($keys))
425 425
             self::throwUsageException("First argument must be an array or a ".static::class.".");
426 426
 
427 427
         if ($keys instanceof static)
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
      *
439 439
      * @return static The filled array.
440 440
      */
441
-    public function fill($start, $number, $value, $interval=1)
441
+    public function fill($start, $number, $value, $interval = 1)
442 442
     {
443 443
         $out = [];
444 444
         while ($number >= 0) {
@@ -468,8 +468,8 @@  discard block
 block discarded – undo
468 468
         $zero_key,
469 469
         $end_key,
470 470
         callable $step_generator,
471
-        $max_interations_count=1000
472
-    ){
471
+        $max_interations_count = 1000
472
+    ) {
473 473
         if ($max_interations_count < 0)
474 474
             throw new \InvalidArgumentException("$maximum_interations_count must be positive");
475 475
 
@@ -479,17 +479,17 @@  discard block
 block discarded – undo
479 479
         $iterations_count    = 0;
480 480
 
481 481
         while ($iterations_count <= $max_interations_count) {
482
-            $current_step_value = call_user_func_array( $step_generator, [
483
-                &$current_step_key,   // param by reference
482
+            $current_step_value = call_user_func_array($step_generator, [
483
+                &$current_step_key, // param by reference
484 484
                 $previous_step_value,
485
-                $current_step_key,   // not passed by ref
485
+                $current_step_key, // not passed by ref
486 486
                 $out
487 487
             ]);
488 488
 
489 489
             if ($current_step_key === null) {
490 490
                 $out[] = $current_step_value;
491 491
             }
492
-            elseif (!is_int($current_step_key)) {
492
+            elseif ( ! is_int($current_step_key)) {
493 493
                 // Set the local as en_US tu have floats formatted with
494 494
                 // "." as separator
495 495
                 // TODO : could it be useful for dates to?
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
      *
528 528
      * @return array The keys.
529 529
      */
530
-    public function keys($search_value=null, $strict=false)
530
+    public function keys($search_value = null, $strict = false)
531 531
     {
532 532
         if ($search_value)
533 533
             return array_keys($this->data, $search_value, $strict);
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
      *
560 560
      * @return string The array written in PHP code.
561 561
      */
562
-    public function export($return=true)
562
+    public function export($return = true)
563 563
     {
564 564
         return var_export($this->data, $return);
565 565
     }
@@ -572,9 +572,9 @@  discard block
 block discarded – undo
572 572
      * @param  bool $return Should we print it or return it?
573 573
      * @return string The printed array
574 574
      */
575
-    public function print_($return=false)
575
+    public function print_($return = false)
576 576
     {
577
-        if (!$return) {
577
+        if ( ! $return) {
578 578
 
579 579
             echo '<pre>';
580 580
             print_r($this->data);
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
      *
635 635
      * @see http://php.net/manual/fr/function.prev.php
636 636
      */
637
-    public function usort(callable $callback=null)
637
+    public function usort(callable $callback = null)
638 638
     {
639 639
         $data = $this->data;
640 640
 
@@ -647,9 +647,9 @@  discard block
 block discarded – undo
647 647
             };
648 648
         }
649 649
 
650
-        $arguments = Arrays::merge( [&$data], [$callback] );
650
+        $arguments = Arrays::merge([&$data], [$callback]);
651 651
 
652
-        if ( ! call_user_func_array('uasort', $arguments) )
652
+        if ( ! call_user_func_array('uasort', $arguments))
653 653
             throw new \ErrorException('Unable to apply usort');
654 654
 
655 655
         return $this->returnConstant($data);
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
      *
661 661
      * @see http://php.net/manual/fr/function.uksort.php
662 662
      */
663
-    public function uksort(callable $callback=null)
663
+    public function uksort(callable $callback = null)
664 664
     {
665 665
         $data = $this->data;
666 666
 
@@ -670,9 +670,9 @@  discard block
 block discarded – undo
670 670
             };
671 671
         }
672 672
 
673
-        $arguments = Arrays::merge( [&$data], [$callback] );
673
+        $arguments = Arrays::merge([&$data], [$callback]);
674 674
 
675
-        if ( ! call_user_func_array('uksort', $arguments) )
675
+        if ( ! call_user_func_array('uksort', $arguments))
676 676
             throw new \ErrorException('Unable to apply uksort');
677 677
 
678 678
         return $this->returnConstant($data);
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
      */
687 687
     public function intersect($intersect_with)
688 688
     {
689
-        if (!$this->argumentIsArrayOrArrayObject($intersect_with)) {
689
+        if ( ! $this->argumentIsArrayOrArrayObject($intersect_with)) {
690 690
             $this->throwUsageException("First argument must be an array or a ".static::class.".");
691 691
         }
692 692
 
Please login to merge, or discard this patch.
Braces   +67 added lines, -64 removed lines patch added patch discarded remove patch
@@ -26,8 +26,9 @@  discard block
 block discarded – undo
26 26
         $out = [];
27 27
         foreach ($this->data as $key => &$row) {
28 28
 
29
-            if ($index_key)
30
-                $key = $row[$index_key];
29
+            if ($index_key) {
30
+                            $key = $row[$index_key];
31
+            }
31 32
 
32 33
             if (is_array($column_names)) {
33 34
                 $out[$key] = [];
@@ -42,20 +43,16 @@  discard block
 block discarded – undo
42 43
 
43 44
                     $out[$key][$column_name] = $row[$column_name];
44 45
                 }
45
-            }
46
-            else {
46
+            } else {
47 47
                 // This avoids issues with isset, array_key_exists and
48 48
                 // null entries on objects and arrays.
49 49
                 if ($row instanceof static) {
50 50
                     $keys = $row->copy()->keys();
51
-                }
52
-                elseif (is_array($row)) {
51
+                } elseif (is_array($row)) {
53 52
                     $keys = array_keys($row);
54
-                }
55
-                elseif (is_scalar($row)) {
53
+                } elseif (is_scalar($row)) {
56 54
                     $keys = [];
57
-                }
58
-                else {
55
+                } else {
59 56
                     // todo : handle other classes supporting ArrayAccess?
60 57
                     $keys = [];
61 58
                 }
@@ -101,16 +98,17 @@  discard block
 block discarded – undo
101 98
      */
102 99
     public function min($default_value=null)
103 100
     {
104
-        if ($this->isEmpty() && $default_value !== null)
105
-            return $default_value;
101
+        if ($this->isEmpty() && $default_value !== null) {
102
+                    return $default_value;
103
+        }
106 104
 
107 105
         try {
108 106
             return min($this->data);
109
-        }
110
-        catch (\Exception $e) {
107
+        } catch (\Exception $e) {
111 108
             $message = $e->getMessage();
112
-            if ($e->getMessage() == 'min(): Array must contain at least one element')
113
-                $message .= ' or you can set a default value as parameter';
109
+            if ($e->getMessage() == 'min(): Array must contain at least one element') {
110
+                            $message .= ' or you can set a default value as parameter';
111
+            }
114 112
 
115 113
             $this->throwUsageException($message);
116 114
         }
@@ -124,16 +122,17 @@  discard block
 block discarded – undo
124 122
      */
125 123
     public function max($default_value=null)
126 124
     {
127
-        if ($this->isEmpty() && $default_value !== null)
128
-            return $default_value;
125
+        if ($this->isEmpty() && $default_value !== null) {
126
+                    return $default_value;
127
+        }
129 128
 
130 129
         try {
131 130
             return max($this->data);
132
-        }
133
-        catch (\Exception $e) {
131
+        } catch (\Exception $e) {
134 132
             $message = $e->getMessage();
135
-            if ($e->getMessage() == 'max(): Array must contain at least one element')
136
-                $message .= ' or you can set a default value as parameter';
133
+            if ($e->getMessage() == 'max(): Array must contain at least one element') {
134
+                            $message .= ' or you can set a default value as parameter';
135
+            }
137 136
 
138 137
             $this->throwUsageException($message);
139 138
         }
@@ -200,16 +199,15 @@  discard block
 block discarded – undo
200 199
             if (PHP_VERSION_ID >= 50600) {
201 200
                 $out = array_filter($this->data, $callback,
202 201
                     ARRAY_FILTER_USE_BOTH);
203
-            }
204
-            else {
202
+            } else {
205 203
                 $out = $this->data;
206 204
                 foreach ($out as $key => $value) {
207
-                    if (!$callback($value, $key))
208
-                        unset( $out[$key] );
205
+                    if (!$callback($value, $key)) {
206
+                                            unset( $out[$key] );
207
+                    }
209 208
                 }
210 209
             }
211
-        }
212
-        else {
210
+        } else {
213 211
             $out = array_filter($this->data);
214 212
         }
215 213
 
@@ -242,8 +240,9 @@  discard block
 block discarded – undo
242 240
         $out = [];
243 241
         foreach ($this->data as $i => $data_item) {
244 242
 
245
-            if ($data_item == $item_to_remove)
246
-                continue;
243
+            if ($data_item == $item_to_remove) {
244
+                            continue;
245
+            }
247 246
 
248 247
             $out[$i] = $data_item;
249 248
         }
@@ -258,11 +257,13 @@  discard block
 block discarded – undo
258 257
      */
259 258
     public function intersectKey($intersect_with)
260 259
     {
261
-        if (!$this->argumentIsArrayOrArrayObject($intersect_with))
262
-            self::throwUsageException("First argument must be an array or a ".static::class.".");
260
+        if (!$this->argumentIsArrayOrArrayObject($intersect_with)) {
261
+                    self::throwUsageException("First argument must be an array or a ".static::class.".");
262
+        }
263 263
 
264
-        if ($intersect_with instanceof static)
265
-            $intersect_with = $intersect_with->getArray();
264
+        if ($intersect_with instanceof static) {
265
+                    $intersect_with = $intersect_with->getArray();
266
+        }
266 267
 
267 268
         $out = array_intersect_key($this->data, $intersect_with);
268 269
 
@@ -351,8 +352,9 @@  discard block
 block discarded – undo
351 352
      */
352 353
     public function diff($compare_with, $check_keys=false, $strict_comparison=false)
353 354
     {
354
-        if (!$this->argumentIsArrayOrArrayObject($compare_with))
355
-            self::throwUsageException("First argument must be an iterable");
355
+        if (!$this->argumentIsArrayOrArrayObject($compare_with)) {
356
+                    self::throwUsageException("First argument must be an iterable");
357
+        }
356 358
 
357 359
         $kept_values = $this->data;
358 360
 
@@ -368,21 +370,18 @@  discard block
 block discarded – undo
368 370
                             &&  $kept_value === $compared_value ) {
369 371
                             $is_equal = true;
370 372
                         }
371
-                    }
372
-                    else {
373
+                    } else {
373 374
                         if (    $kept_key   == $compared_key
374 375
                             &&  $kept_value == $compared_value ) {
375 376
                             $is_equal = true;
376 377
                         }
377 378
                     }
378
-                }
379
-                else {
379
+                } else {
380 380
                     if ($strict_comparison) {
381 381
                         if ($kept_value === $compared_value) {
382 382
                             $is_equal = true;
383 383
                         }
384
-                    }
385
-                    else {
384
+                    } else {
386 385
                         if ($kept_value == $compared_value) {
387 386
                             $is_equal = true;
388 387
                         }
@@ -421,11 +420,13 @@  discard block
 block discarded – undo
421 420
      */
422 421
     public function fillKeys($keys, $value)
423 422
     {
424
-        if (!$this->argumentIsArrayOrArrayObject($keys))
425
-            self::throwUsageException("First argument must be an array or a ".static::class.".");
423
+        if (!$this->argumentIsArrayOrArrayObject($keys)) {
424
+                    self::throwUsageException("First argument must be an array or a ".static::class.".");
425
+        }
426 426
 
427
-        if ($keys instanceof static)
428
-            $keys = $keys->getArray();
427
+        if ($keys instanceof static) {
428
+                    $keys = $keys->getArray();
429
+        }
429 430
 
430 431
         $out = array_fill_keys($keys, $value);
431 432
         return $this->returnConstant($out);
@@ -470,8 +471,9 @@  discard block
 block discarded – undo
470 471
         callable $step_generator,
471 472
         $max_interations_count=1000
472 473
     ){
473
-        if ($max_interations_count < 0)
474
-            throw new \InvalidArgumentException("$maximum_interations_count must be positive");
474
+        if ($max_interations_count < 0) {
475
+                    throw new \InvalidArgumentException("$maximum_interations_count must be positive");
476
+        }
475 477
 
476 478
         $out                 = [];
477 479
         $previous_step_value = null;
@@ -488,16 +490,14 @@  discard block
 block discarded – undo
488 490
 
489 491
             if ($current_step_key === null) {
490 492
                 $out[] = $current_step_value;
491
-            }
492
-            elseif (!is_int($current_step_key)) {
493
+            } elseif (!is_int($current_step_key)) {
493 494
                 // Set the local as en_US tu have floats formatted with
494 495
                 // "." as separator
495 496
                 // TODO : could it be useful for dates to?
496 497
                 $current_locale = setlocale(LC_NUMERIC, 'en_US');
497 498
                 $out[(string) $current_step_key] = $current_step_value;
498 499
                 setlocale(LC_NUMERIC, $current_locale);
499
-            }
500
-            else {
500
+            } else {
501 501
                 $out[$current_step_key] = $current_step_value;
502 502
             }
503 503
 
@@ -508,8 +508,7 @@  discard block
 block discarded – undo
508 508
                 if ((string) $current_step_key == (string) $end_key) {
509 509
                     break;
510 510
                 }
511
-            }
512
-            elseif ($current_step_key == $end_key) {
511
+            } elseif ($current_step_key == $end_key) {
513 512
                 break;
514 513
             }
515 514
 
@@ -529,10 +528,11 @@  discard block
 block discarded – undo
529 528
      */
530 529
     public function keys($search_value=null, $strict=false)
531 530
     {
532
-        if ($search_value)
533
-            return array_keys($this->data, $search_value, $strict);
534
-        else
535
-            return array_keys($this->data);
531
+        if ($search_value) {
532
+                    return array_keys($this->data, $search_value, $strict);
533
+        } else {
534
+                    return array_keys($this->data);
535
+        }
536 536
     }
537 537
 
538 538
     /**
@@ -640,8 +640,9 @@  discard block
 block discarded – undo
640 640
 
641 641
         if ($callback === null) {
642 642
             $callback = function($a, $b) {
643
-                if ($a == $b)
644
-                    return 0;
643
+                if ($a == $b) {
644
+                                    return 0;
645
+                }
645 646
 
646 647
                 return $a > $b ? -1 : 1;
647 648
             };
@@ -649,8 +650,9 @@  discard block
 block discarded – undo
649 650
 
650 651
         $arguments = Arrays::merge( [&$data], [$callback] );
651 652
 
652
-        if ( ! call_user_func_array('uasort', $arguments) )
653
-            throw new \ErrorException('Unable to apply usort');
653
+        if ( ! call_user_func_array('uasort', $arguments) ) {
654
+                    throw new \ErrorException('Unable to apply usort');
655
+        }
654 656
 
655 657
         return $this->returnConstant($data);
656 658
     }
@@ -672,8 +674,9 @@  discard block
 block discarded – undo
672 674
 
673 675
         $arguments = Arrays::merge( [&$data], [$callback] );
674 676
 
675
-        if ( ! call_user_func_array('uksort', $arguments) )
676
-            throw new \ErrorException('Unable to apply uksort');
677
+        if ( ! call_user_func_array('uksort', $arguments) ) {
678
+                    throw new \ErrorException('Unable to apply uksort');
679
+        }
677 680
 
678 681
         return $this->returnConstant($data);
679 682
     }
Please login to merge, or discard this patch.
src/Arrays/ChainableArray_ArrayAccess_Trait.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@
 block discarded – undo
86 86
             // The true location of the throw is still available through
87 87
             // $e->getTrace()
88 88
             $trace_location  = $e->getTrace()[1];
89
-            $reflectionClass = new \ReflectionClass( get_class($e) );
89
+            $reflectionClass = new \ReflectionClass(get_class($e));
90 90
 
91 91
             //file
92 92
             if (isset($trace_location['file'])) {
Please login to merge, or discard this patch.
Braces   +8 added lines, -10 removed lines patch added patch discarded remove patch
@@ -18,8 +18,7 @@  discard block
 block discarded – undo
18 18
     {
19 19
         if (is_null($offset)) {
20 20
             $this->data[] = $value;
21
-        }
22
-        else {
21
+        } else {
23 22
             $this->data[$offset] = $value;
24 23
         }
25 24
     }
@@ -31,8 +30,7 @@  discard block
 block discarded – undo
31 30
     {
32 31
         try {
33 32
             return isset($this->data[$offset]);
34
-        }
35
-        catch (\Exception $e) {
33
+        } catch (\Exception $e) {
36 34
             if (property_exists($this, 'defaultRowGenerator')) {
37 35
                 return true;
38 36
             }
@@ -77,8 +75,7 @@  discard block
 block discarded – undo
77 75
             // support but wouldn't throw exception if it doesn't exist
78 76
             $returnValue = &$this->data[$offset];
79 77
             return $returnValue;
80
-        }
81
-        catch (\Exception $e) {
78
+        } catch (\Exception $e) {
82 79
             // here we simply move the Exception location at the one
83 80
             // of the caller as the isset() method is called at its
84 81
             // location.
@@ -158,10 +155,11 @@  discard block
 block discarded – undo
158 155
      */
159 156
     protected function generateDefaultRow($offset)
160 157
     {
161
-        if (property_exists($this, 'defaultRow'))
162
-            return $this->defaultRow;
163
-        elseif (property_exists($this, 'defaultRowGenerator'))
164
-            return call_user_func($this->defaultRowGenerator, $offset);
158
+        if (property_exists($this, 'defaultRow')) {
159
+                    return $this->defaultRow;
160
+        } elseif (property_exists($this, 'defaultRowGenerator')) {
161
+                    return call_user_func($this->defaultRowGenerator, $offset);
162
+        }
165 163
     }
166 164
 
167 165
     /**/
Please login to merge, or discard this patch.
src/Arrays/ChainableArray_Wip_Trait.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             },
61 61
             formatted_values: [ ]
62 62
         }
63
-        *
63
+     *
64 64
         =>
65 65
      *  action_calculate_paid_impressions: {
66 66
             values: [ ],
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
             },
70 70
             formatted_values: [ ]
71 71
         }
72
-        *
73
-        *
74
-        *data: [
72
+     *
73
+     *
74
+     *data: [
75 75
             {
76 76
             paidImpressions: {
77 77
                 value: 246367,
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
     {
92 92
         $column_name = $key_column_names->shift();
93 93
 
94
-        if (!$column_name)
94
+        if ( ! $column_name)
95 95
             return $rows;
96 96
 
97 97
         // $out = new static;
@@ -212,85 +212,85 @@  discard block
 block discarded – undo
212 212
             '3rd'
213 213
         ]);
214 214
 
215
-        $expected = array (
216
-            0 => array (
215
+        $expected = array(
216
+            0 => array(
217 217
                 'a3' => 1,
218 218
                 'b3' => 1,
219 219
                 '3rd' => 'a2',
220 220
                 '2nd' => 'a1',
221 221
                 '1st' => 'a',
222 222
             ),
223
-            1 => array (
223
+            1 => array(
224 224
                 'a3' => 1,
225 225
                 'b3' => 1,
226 226
                 '3rd' => 'b2',
227 227
                 '2nd' => 'a1',
228 228
                 '1st' => 'a',
229 229
             ),
230
-            2 => array (
230
+            2 => array(
231 231
                 'a3' => 1,
232 232
                 'b3' => 1,
233 233
                 '3rd' => 'c2',
234 234
                 '2nd' => 'a1',
235 235
                 '1st' => 'a',
236 236
             ),
237
-            3 => array (
237
+            3 => array(
238 238
                 'a3' => 1,
239 239
                 'b3' => 1,
240 240
                 '3rd' => 'a2',
241 241
                 '2nd' => 'b1',
242 242
                 '1st' => 'a',
243 243
             ),
244
-            4 => array (
244
+            4 => array(
245 245
                 'a3' => 1,
246 246
                 'b3' => 1,
247 247
                 '3rd' => 'b2',
248 248
                 '2nd' => 'b1',
249 249
                 '1st' => 'a',
250 250
             ),
251
-            5 => array (
251
+            5 => array(
252 252
                 'a3' => 1,
253 253
                 'b3' => 1,
254 254
                 '3rd' => 'c2',
255 255
                 '2nd' => 'b1',
256 256
                 '1st' => 'a',
257 257
             ),
258
-            6 => array (
258
+            6 => array(
259 259
                 'a3' => 1,
260 260
                 'b3' => 1,
261 261
                 '3rd' => 'a2',
262 262
                 '2nd' => 'a1',
263 263
                 '1st' => 'b',
264 264
             ),
265
-            7 => array (
265
+            7 => array(
266 266
                 'a3' => 1,
267 267
                 'b3' => 1,
268 268
                 '3rd' => 'b2',
269 269
                 '2nd' => 'a1',
270 270
                 '1st' => 'b',
271 271
             ),
272
-            8 => array (
272
+            8 => array(
273 273
                 'a3' => 1,
274 274
                 'b3' => 1,
275 275
                 '3rd' => 'c2',
276 276
                 '2nd' => 'a1',
277 277
                 '1st' => 'b',
278 278
             ),
279
-            9 => array (
279
+            9 => array(
280 280
                 'a3' => 1,
281 281
                 'b3' => 1,
282 282
                 '3rd' => 'a2',
283 283
                 '2nd' => 'b1',
284 284
                 '1st' => 'b',
285 285
             ),
286
-            10 => array (
286
+            10 => array(
287 287
                 'a3' => 1,
288 288
                 'b3' => 1,
289 289
                 '3rd' => 'b2',
290 290
                 '2nd' => 'b1',
291 291
                 '1st' => 'b',
292 292
             ),
293
-            11 => array (
293
+            11 => array(
294 294
                 'a3' => 1,
295 295
                 'b3' => 1,
296 296
                 '3rd' => 'c2',
@@ -327,19 +327,19 @@  discard block
 block discarded – undo
327 327
      */
328 328
     private function piramidize_aux($key_column_names, $rows)
329 329
     {
330
-        if (!is_array($rows))
330
+        if ( ! is_array($rows))
331 331
             return $rows;
332 332
 
333 333
         $column_name = $key_column_names->shift();
334 334
 
335
-        if (!$column_name)
335
+        if ( ! $column_name)
336 336
             return $rows;
337 337
 
338 338
         // $out = new static;
339 339
         $out = [];
340 340
         foreach ($rows as $key => $row) {
341 341
 
342
-            if (!isset($row[$column_name])) {
342
+            if ( ! isset($row[$column_name])) {
343 343
                 throw new \ErrorException("No value found for column"
344 344
                     ." name '$column_name' in the row: ".var_export($row, true));
345 345
             }
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
             unset($row[$column_name]);
349 349
 
350 350
             if ($key_column_names->count()) {
351
-                if (!isset($out[$key]))
351
+                if ( ! isset($out[$key]))
352 352
                     $out[$key] = [];
353 353
 
354 354
                 $out[$key][] = $row;
@@ -456,68 +456,68 @@  discard block
 block discarded – undo
456 456
             '1st',
457 457
         ]);
458 458
 
459
-        $expected = array (
460
-            'a2' => array (
461
-                'a1' => array (
462
-                    'a' => array (
459
+        $expected = array(
460
+            'a2' => array(
461
+                'a1' => array(
462
+                    'a' => array(
463 463
                         'a3' => 1,
464 464
                         'b3' => 1,
465 465
                     ),
466
-                    'b' => array (
466
+                    'b' => array(
467 467
                         'a3' => 1,
468 468
                         'b3' => 1,
469 469
                     ),
470 470
                 ),
471
-                'b1' => array (
472
-                    'a' => array (
471
+                'b1' => array(
472
+                    'a' => array(
473 473
                         'a3' => 1,
474 474
                         'b3' => 1,
475 475
                     ),
476
-                    'b' => array (
476
+                    'b' => array(
477 477
                         'a3' => 1,
478 478
                         'b3' => 1,
479 479
                     ),
480 480
                 ),
481 481
             ),
482
-            'b2' => array (
483
-                'a1' => array (
484
-                    'a' => array (
482
+            'b2' => array(
483
+                'a1' => array(
484
+                    'a' => array(
485 485
                         'a3' => 2,
486 486
                         'b3' => 2,
487 487
                     ),
488
-                    'b' => array (
488
+                    'b' => array(
489 489
                         'a3' => 2,
490 490
                         'b3' => 2,
491 491
                     ),
492 492
                 ),
493
-                'b1' => array (
494
-                    'a' => array (
493
+                'b1' => array(
494
+                    'a' => array(
495 495
                         'a3' => 2,
496 496
                         'b3' => 2,
497 497
                     ),
498
-                    'b' => array (
498
+                    'b' => array(
499 499
                         'a3' => 2,
500 500
                         'b3' => 2,
501 501
                     ),
502 502
                 ),
503 503
             ),
504
-            'c2' => array (
505
-                'a1' => array (
506
-                    'a' => array (
504
+            'c2' => array(
505
+                'a1' => array(
506
+                    'a' => array(
507 507
                         'a3' => 3,
508 508
                         'b3' => 3,
509 509
                     ),
510
-                    'b' => array (
510
+                    'b' => array(
511 511
                         'a3' => 3,
512 512
                         'b3' => 3,
513 513
                     ),
514 514
                 ),
515
-                'b1' => array (
516
-                    'a' => array (
515
+                'b1' => array(
516
+                    'a' => array(
517 517
                         'a3' => 3,
518 518
                         'b3' => 3,
519 519
                     ),
520
-                    'b' => array (
520
+                    'b' => array(
521 521
                         'a3' => 3,
522 522
                         'b3' => 3,
523 523
                     ),
Please login to merge, or discard this patch.
Braces   +28 added lines, -24 removed lines patch added patch discarded remove patch
@@ -91,8 +91,9 @@  discard block
 block discarded – undo
91 91
     {
92 92
         $column_name = $key_column_names->shift();
93 93
 
94
-        if (!$column_name)
95
-            return $rows;
94
+        if (!$column_name) {
95
+                    return $rows;
96
+        }
96 97
 
97 98
         // $out = new static;
98 99
         $out = [];
@@ -107,10 +108,10 @@  discard block
 block discarded – undo
107 108
 
108 109
                 foreach ($sub_rows as $row) {
109 110
                     try {
110
-                        if (is_array($row))
111
-                            $row[$column_name] = $key;
112
-                    }
113
-                    catch (\Exception $e) {
111
+                        if (is_array($row)) {
112
+                                                    $row[$column_name] = $key;
113
+                        }
114
+                    } catch (\Exception $e) {
114 115
                         echo json_encode($column_name);
115 116
                         echo json_encode($key);
116 117
                         echo json_encode($e);
@@ -118,13 +119,12 @@  discard block
 block discarded – undo
118 119
                     }
119 120
                     $out[] = $row;
120 121
                 }
121
-            }
122
-            else {
122
+            } else {
123 123
                 try {
124
-                    if (is_array($sub_rows))
125
-                        $sub_rows[$column_name] = $key;
126
-                }
127
-                catch (\Exception $e) {
124
+                    if (is_array($sub_rows)) {
125
+                                            $sub_rows[$column_name] = $key;
126
+                    }
127
+                } catch (\Exception $e) {
128 128
                     echo json_encode($sub_rows);
129 129
                     echo json_encode($column_name);
130 130
                     echo json_encode($key);
@@ -299,8 +299,9 @@  discard block
 block discarded – undo
299 299
             ),
300 300
         );
301 301
 
302
-        if ($expected != $tableized->getArray())
303
-            throw new \Exception("test failed");
302
+        if ($expected != $tableized->getArray()) {
303
+                    throw new \Exception("test failed");
304
+        }
304 305
 
305 306
         echo 'Helper_Tabe->tableize tested successfully';
306 307
     }
@@ -327,13 +328,15 @@  discard block
 block discarded – undo
327 328
      */
328 329
     private function piramidize_aux($key_column_names, $rows)
329 330
     {
330
-        if (!is_array($rows))
331
-            return $rows;
331
+        if (!is_array($rows)) {
332
+                    return $rows;
333
+        }
332 334
 
333 335
         $column_name = $key_column_names->shift();
334 336
 
335
-        if (!$column_name)
336
-            return $rows;
337
+        if (!$column_name) {
338
+                    return $rows;
339
+        }
337 340
 
338 341
         // $out = new static;
339 342
         $out = [];
@@ -348,12 +351,12 @@  discard block
 block discarded – undo
348 351
             unset($row[$column_name]);
349 352
 
350 353
             if ($key_column_names->count()) {
351
-                if (!isset($out[$key]))
352
-                    $out[$key] = [];
354
+                if (!isset($out[$key])) {
355
+                                    $out[$key] = [];
356
+                }
353 357
 
354 358
                 $out[$key][] = $row;
355
-            }
356
-            else {
359
+            } else {
357 360
                 $out[$key] = $row;
358 361
             }
359 362
         }
@@ -529,8 +532,9 @@  discard block
 block discarded – undo
529 532
         // echo var_export($values->getArray());
530 533
         // $values->dumpJson(true);
531 534
 
532
-        if ($expected != $values->getArray())
533
-            throw new \Exception("test failed");
535
+        if ($expected != $values->getArray()) {
536
+                    throw new \Exception("test failed");
537
+        }
534 538
 
535 539
         echo 'Helper_Tabe->piramidize tested successfully';
536 540
     }
Please login to merge, or discard this patch.
src/Arrays/ChainableArray_Utils_Trait.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -553,7 +553,7 @@
 block discarded – undo
553 553
             foreach ($rowIdParts as $name => $value) {
554 554
                 if (isset($data[$name]) && $data[$name] !== $value) {
555 555
                     self::throwUsageException(
556
-                         "Trying to populate a column '$name' that "
556
+                            "Trying to populate a column '$name' that "
557 557
                         ."already exists with a different value "
558 558
                         .var_export($data[$name], true). " => '$value'"
559 559
                     );
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 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,14 +174,14 @@  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 {
181 181
                 if ($conflictResolver === null) {
182 182
                     self::throwUsageException(
183 183
                         "No conflict resolver for a merge provoking one: $key \n\n"
184
-                        .var_export($row, true) . "\n\n"
184
+                        .var_export($row, true)."\n\n"
185 185
                         .var_export($out[$key], true)
186 186
                     );
187 187
                 }
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
      * (same as self::mergeWith with the other table as $this)
208 208
      * @return static
209 209
      */
210
-    public function mergeIn( $otherTable, callable $conflictResolver=null )
210
+    public function mergeIn($otherTable, callable $conflictResolver = null)
211 211
     {
212 212
         $otherTable->mergeWith($this, $conflictResolver);
213 213
         return $this;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
      */
234 234
     public function each(callable $rowTransformer)
235 235
     {
236
-        $out  = [];
236
+        $out = [];
237 237
         foreach ($this->data as $key => $row) {
238 238
             $out[$key] = call_user_func_array(
239 239
                 $rowTransformer,
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      */
264 264
     public function renameColumns(array $old_to_new_names)
265 265
     {
266
-        $out  = [];
266
+        $out = [];
267 267
         foreach ($this->data as $key => $row) {
268 268
             try {
269 269
                 foreach ($old_to_new_names as $old_name => $new_name) {
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                 }
273 273
             }
274 274
             catch (\Exception $e) {
275
-                self::throwUsageException( $e->getMessage() );
275
+                self::throwUsageException($e->getMessage());
276 276
             }
277 277
 
278 278
             $out[$key] = $row;
@@ -324,20 +324,20 @@  discard block
 block discarded – undo
324 324
      *                            nor a static.
325 325
      * @return static       $this
326 326
      */
327
-    public function append($new_rows, callable $conflict_resolver=null)
327
+    public function append($new_rows, callable $conflict_resolver = null)
328 328
     {
329 329
         if ($new_rows instanceof static)
330 330
             $new_rows = $new_rows->getArray();
331 331
 
332
-        if (!is_array($new_rows)) {
332
+        if ( ! is_array($new_rows)) {
333 333
             $this->throwUsageException(
334
-                "\$new_rows parameter must be an array or an instance of " . __CLASS__
334
+                "\$new_rows parameter must be an array or an instance of ".__CLASS__
335 335
             );
336 336
         }
337 337
 
338
-        if (!$conflict_resolver) {
338
+        if ( ! $conflict_resolver) {
339 339
             // default conflict resolver: append with numeric key
340
-            $conflict_resolver = function (&$data, $existing_row, $confliuct_row, $key) {
340
+            $conflict_resolver = function(&$data, $existing_row, $confliuct_row, $key) {
341 341
                 $data[] = $confliuct_row;
342 342
             };
343 343
         }
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
      *
370 370
      * @return static
371 371
      */
372
-    public function dimensionsAsColumns(array $columnNames, array $options=null)
372
+    public function dimensionsAsColumns(array $columnNames, array $options = null)
373 373
     {
374 374
         $out = $this->dimensionsAsColumns_recurser($this->data, $columnNames);
375 375
         return $this->returnConstant($out);
@@ -406,12 +406,12 @@  discard block
 block discarded – undo
406 406
      *      ],
407 407
      * ]
408 408
      */
409
-    protected function dimensionsAsColumns_recurser(array $data, $columnNames, $rowIdParts=[])
409
+    protected function dimensionsAsColumns_recurser(array $data, $columnNames, $rowIdParts = [])
410 410
     {
411 411
         $out = [];
412 412
         // if (!$columnNames)
413 413
             // return $data;
414
-        $no_more_column = !(bool) $columnNames;
414
+        $no_more_column = ! (bool) $columnNames;
415 415
 
416 416
         // If all the names have been given to the dimensions
417 417
         // we compile the index key of the row at the current level
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
                     self::throwUsageException(
436 436
                          "Trying to populate a column '$name' that "
437 437
                         ."already exists with a different value "
438
-                        .var_export($data[$name], true). " => '$value'"
438
+                        .var_export($data[$name], true)." => '$value'"
439 439
                     );
440 440
                 }
441 441
                 $data[$name] = $value;
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
             }
467 467
             else {
468 468
 
469
-                if (!isset($rows)) {
469
+                if ( ! isset($rows)) {
470 470
                     echo json_encode([
471 471
                         '$rowIdParts' => $rowIdParts,
472 472
                         '$row' => $row,
@@ -494,9 +494,9 @@  discard block
 block discarded – undo
494 494
     /**
495 495
      * Returns the first element of the array
496 496
      */
497
-    public function first($strict=false)
497
+    public function first($strict = false)
498 498
     {
499
-        if (!$this->count()) {
499
+        if ( ! $this->count()) {
500 500
             if ($strict)
501 501
                 throw new \ErrorException("No first element found in this array");
502 502
             else
@@ -516,9 +516,9 @@  discard block
 block discarded – undo
516 516
      *
517 517
      * @todo Preserve the offset
518 518
      */
519
-    public function last($strict=false)
519
+    public function last($strict = false)
520 520
     {
521
-        if (!$this->count()) {
521
+        if ( ! $this->count()) {
522 522
             if ($strict)
523 523
                 throw new \ErrorException("No last element found in this array");
524 524
             else
@@ -536,9 +536,9 @@  discard block
 block discarded – undo
536 536
     /**
537 537
      *
538 538
      */
539
-    public function firstKey($strict=false)
539
+    public function firstKey($strict = false)
540 540
     {
541
-        if (!$this->count()) {
541
+        if ( ! $this->count()) {
542 542
             if ($strict)
543 543
                 throw new \ErrorException("No last element found in this array");
544 544
             else
@@ -557,16 +557,16 @@  discard block
 block discarded – undo
557 557
     /**
558 558
      *
559 559
      */
560
-    public function lastKey($strict=false)
560
+    public function lastKey($strict = false)
561 561
     {
562
-        if (!$this->count()) {
562
+        if ( ! $this->count()) {
563 563
             if ($strict)
564 564
                 throw new \ErrorException("No last element found in this array");
565 565
             else
566 566
                 $lastKey = null;
567 567
         }
568 568
         else {
569
-            $key  = key($this->data);
569
+            $key = key($this->data);
570 570
             end($this->data);
571 571
             $lastKey = key($this->data);
572 572
             $this->move($key);
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
     /**
579 579
      * Move the internal pointer of the array to the key given as parameter
580 580
      */
581
-    public function move($key, $strict=true)
581
+    public function move($key, $strict = true)
582 582
     {
583 583
         if (array_key_exists($key, $this->data)) {
584 584
             foreach ($this->data as $i => &$value) {
@@ -645,13 +645,13 @@  discard block
 block discarded – undo
645 645
      * @see http://php.net/manual/fr/function.var-dump.php
646 646
      * @todo Handle xdebug dump formatting
647 647
      */
648
-    public function dump($exit=false)
648
+    public function dump($exit = false)
649 649
     {
650 650
         $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
651 651
         $caller = $bt[0];
652 652
 
653 653
         var_export([
654
-            'location' => $caller['file'] . ':' . $caller['line'],
654
+            'location' => $caller['file'].':'.$caller['line'],
655 655
             'data'     => $this->data,
656 656
         ]);
657 657
 
@@ -668,7 +668,7 @@  discard block
 block discarded – undo
668 668
      * @todo move it to an Arrays class storing static methods
669 669
      */
670 670
     public static function replaceEntries(
671
-        array $array, callable $replacer, $max_depth=null
671
+        array $array, callable $replacer, $max_depth = null
672 672
     ) {
673 673
         foreach ($array as $key => &$row) {
674 674
             $arguments = [&$row, $key];
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 
677 677
             if (is_array($row) && $max_depth !== 0) { // allowing null to have no depth limit
678 678
                 $row = self::replaceEntries(
679
-                    $row, $replacer, $max_depth ? $max_depth-1 : $max_depth
679
+                    $row, $replacer, $max_depth ? $max_depth - 1 : $max_depth
680 680
                 );
681 681
             }
682 682
         }
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
      *
693 693
      * @return static $this or a new static.
694 694
      */
695
-    public function extract($callback=null)
695
+    public function extract($callback = null)
696 696
     {
697 697
         if ($callback) {
698 698
 
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
                 $callback = new \JClaveau\LogicalFilter\LogicalFilter($callback);
701 701
             }
702 702
 
703
-            if (!is_callable($callback)) {
703
+            if ( ! is_callable($callback)) {
704 704
                 $this->throwUsageException(
705 705
                     "\$callback must be a logical filter description array or a callable"
706 706
                     ." instead of "
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
             foreach ($this->data as $key => $value) {
713 713
                 if ($callback($value, $key)) {
714 714
                     $out[$key] = $value;
715
-                    unset( $this->data[$key] );
715
+                    unset($this->data[$key]);
716 716
                 }
717 717
             }
718 718
         }
Please login to merge, or discard this patch.
Braces   +67 added lines, -64 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,8 +179,7 @@  discard block
 block discarded – undo
176 179
 
177 180
             if (!isset($out[$key])) {
178 181
                 $out[$key] = $row;
179
-            }
180
-            else {
182
+            } else {
181 183
                 if ($conflictResolver === null) {
182 184
                     self::throwUsageException(
183 185
                         "No conflict resolver for a merge provoking one: $key \n\n"
@@ -270,8 +272,7 @@  discard block
 block discarded – undo
270 272
                     $row[$new_name] = $row[$old_name];
271 273
                     unset($row[$old_name]);
272 274
                 }
273
-            }
274
-            catch (\Exception $e) {
275
+            } catch (\Exception $e) {
275 276
                 self::throwUsageException( $e->getMessage() );
276 277
             }
277 278
 
@@ -292,17 +293,19 @@  discard block
 block discarded – undo
292 293
     public function limit()
293 294
     {
294 295
         $arguments = func_get_args();
295
-        if (count($arguments) == 1 && is_numeric($arguments[0]))
296
-            $max = $arguments[0];
297
-        else
298
-            self::throwUsageException("Bad arguments type and count for limit()");
296
+        if (count($arguments) == 1 && is_numeric($arguments[0])) {
297
+                    $max = $arguments[0];
298
+        } else {
299
+                    self::throwUsageException("Bad arguments type and count for limit()");
300
+        }
299 301
 
300 302
         $out   = [];
301 303
         $count = 0;
302 304
         foreach ($this->data as $key => $row) {
303 305
 
304
-            if ($max <= $count)
305
-                break;
306
+            if ($max <= $count) {
307
+                            break;
308
+            }
306 309
 
307 310
             $out[$key] = $row;
308 311
 
@@ -326,8 +329,9 @@  discard block
 block discarded – undo
326 329
      */
327 330
     public function append($new_rows, callable $conflict_resolver=null)
328 331
     {
329
-        if ($new_rows instanceof static)
330
-            $new_rows = $new_rows->getArray();
332
+        if ($new_rows instanceof static) {
333
+                    $new_rows = $new_rows->getArray();
334
+        }
331 335
 
332 336
         if (!is_array($new_rows)) {
333 337
             $this->throwUsageException(
@@ -352,8 +356,7 @@  discard block
 block discarded – undo
352 356
                 ];
353 357
 
354 358
                 call_user_func_array($conflict_resolver, $arguments);
355
-            }
356
-            else {
359
+            } else {
357 360
                 $this->data[$key] = $new_row;
358 361
             }
359 362
         }
@@ -463,8 +466,7 @@  discard block
 block discarded – undo
463 466
                 foreach ($rows as $row_id => $joined_row) {
464 467
                     $out[$row_id] = $joined_row;
465 468
                 }
466
-            }
467
-            else {
469
+            } else {
468 470
 
469 471
                 if (!isset($rows)) {
470 472
                     echo json_encode([
@@ -474,8 +476,9 @@  discard block
 block discarded – undo
474 476
                     exit;
475 477
                 }
476 478
 
477
-                foreach ($rowIdParts as $rowIdPartName => $rowIdPartValue)
478
-                    $row[$rowIdPartName] = $rowIdPartValue;
479
+                foreach ($rowIdParts as $rowIdPartName => $rowIdPartValue) {
480
+                                    $row[$rowIdPartName] = $rowIdPartValue;
481
+                }
479 482
 
480 483
                 $indexParts = [];
481 484
                 foreach ($rowIdParts as $name => $value) {
@@ -497,12 +500,12 @@  discard block
 block discarded – undo
497 500
     public function first($strict=false)
498 501
     {
499 502
         if (!$this->count()) {
500
-            if ($strict)
501
-                throw new \ErrorException("No first element found in this array");
502
-            else
503
-                $first = null;
504
-        }
505
-        else {
503
+            if ($strict) {
504
+                            throw new \ErrorException("No first element found in this array");
505
+            } else {
506
+                            $first = null;
507
+            }
508
+        } else {
506 509
             $key   = key($this->data);
507 510
             $first = reset($this->data);
508 511
             $this->move($key);
@@ -519,12 +522,12 @@  discard block
 block discarded – undo
519 522
     public function last($strict=false)
520 523
     {
521 524
         if (!$this->count()) {
522
-            if ($strict)
523
-                throw new \ErrorException("No last element found in this array");
524
-            else
525
-                $last = null;
526
-        }
527
-        else {
525
+            if ($strict) {
526
+                            throw new \ErrorException("No last element found in this array");
527
+            } else {
528
+                            $last = null;
529
+            }
530
+        } else {
528 531
             $key  = key($this->data);
529 532
             $last = end($this->data);
530 533
             $this->move($key);
@@ -539,12 +542,12 @@  discard block
 block discarded – undo
539 542
     public function firstKey($strict=false)
540 543
     {
541 544
         if (!$this->count()) {
542
-            if ($strict)
543
-                throw new \ErrorException("No last element found in this array");
544
-            else
545
-                $firstKey = null;
546
-        }
547
-        else {
545
+            if ($strict) {
546
+                            throw new \ErrorException("No last element found in this array");
547
+            } else {
548
+                            $firstKey = null;
549
+            }
550
+        } else {
548 551
             $key      = key($this->data);
549 552
             reset($this->data);
550 553
             $firstKey = key($this->data);
@@ -560,12 +563,12 @@  discard block
 block discarded – undo
560 563
     public function lastKey($strict=false)
561 564
     {
562 565
         if (!$this->count()) {
563
-            if ($strict)
564
-                throw new \ErrorException("No last element found in this array");
565
-            else
566
-                $lastKey = null;
567
-        }
568
-        else {
566
+            if ($strict) {
567
+                            throw new \ErrorException("No last element found in this array");
568
+            } else {
569
+                            $lastKey = null;
570
+            }
571
+        } else {
569 572
             $key  = key($this->data);
570 573
             end($this->data);
571 574
             $lastKey = key($this->data);
@@ -587,8 +590,7 @@  discard block
 block discarded – undo
587 590
                     break;
588 591
                 }
589 592
             }
590
-        }
591
-        elseif ($strict) {
593
+        } elseif ($strict) {
592 594
             throw new \ErrorException("Unable to move the internal pointer to a key that doesn't exist.");
593 595
         }
594 596
 
@@ -655,8 +657,9 @@  discard block
 block discarded – undo
655 657
             'data'     => $this->data,
656 658
         ]);
657 659
 
658
-        if ($exit)
659
-            exit;
660
+        if ($exit) {
661
+                    exit;
662
+        }
660 663
 
661 664
         return $this;
662 665
     }
Please login to merge, or discard this patch.
src/Exceptions/UsageException.php 2 patches
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -54,11 +54,13 @@
 block discarded – undo
54 54
         // var_export($caller);
55 55
 
56 56
         // TODO How to handle perfectly the missing fields of the backtrace?
57
-        if (isset($caller['file']))
58
-            $this->file = $caller['file'];
57
+        if (isset($caller['file'])) {
58
+                    $this->file = $caller['file'];
59
+        }
59 60
 
60
-        if (isset($caller['line']))
61
-            $this->line = $caller['line'];
61
+        if (isset($caller['line'])) {
62
+                    $this->line = $caller['line'];
63
+        }
62 64
 
63 65
         // var_export($this->stack);
64 66
     }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,35 +18,35 @@
 block discarded – undo
18 18
     {
19 19
         parent::__construct(...func_get_args());
20 20
 
21
-        $this->rewindStackWhile( function($backtrace, $level) {
21
+        $this->rewindStackWhile(function($backtrace, $level) {
22 22
             // Finds the closest caller
23 23
             // TODO get the class of the caller instead of comparing
24 24
             // with UsageException
25
-            return  isset($backtrace[ $level ]['class'])
26
-                &&  $backtrace[ $level ]['class'] == __CLASS__;
27
-        }, 0 );
25
+            return  isset($backtrace[$level]['class'])
26
+                &&  $backtrace[$level]['class'] == __CLASS__;
27
+        }, 0);
28 28
     }
29 29
 
30 30
     /**
31 31
      */
32 32
     public function setStackLocationHere()
33 33
     {
34
-        $this->rewindStackWhile( function($backtrace, $level) {
34
+        $this->rewindStackWhile(function($backtrace, $level) {
35 35
             // Finds the closest caller
36 36
             return $level < 2;
37
-        }, 4 );
37
+        }, 4);
38 38
 
39 39
         return $this;
40 40
     }
41 41
 
42 42
     /**
43 43
      */
44
-    protected function rewindStackWhile(callable $scope_checker, $stack_max_depth=20)
44
+    protected function rewindStackWhile(callable $scope_checker, $stack_max_depth = 20)
45 45
     {
46
-        $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, $stack_max_depth);
46
+        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $stack_max_depth);
47 47
         $i         = 1;
48 48
         $caller    = $backtrace[$i];
49
-        while ( $scope_checker( $backtrace, $i ) ) {
49
+        while ($scope_checker($backtrace, $i)) {
50 50
             $i++;
51 51
             $caller = $backtrace[$i];
52 52
             // TODO remove the previous levels of the stack?
Please login to merge, or discard this patch.
src/Arrays/MergeBucket.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
     public function reduceIfUnique()
13 13
     {
14 14
         if ($this->unique()->count() == 1)
15
-            return reset( $this->data );
15
+            return reset($this->data);
16 16
     }
17 17
     /**/
18 18
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@
 block discarded – undo
11 11
      */
12 12
     public function reduceIfUnique()
13 13
     {
14
-        if ($this->unique()->count() == 1)
15
-            return reset( $this->data );
14
+        if ($this->unique()->count() == 1) {
15
+                    return reset( $this->data );
16
+        }
16 17
     }
17 18
     /**/
18 19
 }
Please login to merge, or discard this patch.
src/Arrays/Arrays.php 3 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
         $excluded_columns = isset($options['excluded_columns'])
281 281
                           ? $options['excluded_columns']
282 282
                           : []
283
-                          ;
283
+                            ;
284 284
 
285 285
         foreach ($row as $column => &$values) {
286 286
             if ( ! $values instanceof MergeBucket)
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
         $excluded_columns = isset($options['excluded_columns'])
314 314
                           ? $options['excluded_columns']
315 315
                           : []
316
-                          ;
316
+                            ;
317 317
 
318 318
         foreach ($row as $column => &$values) {
319 319
             if (in_array($column, $excluded_columns)) {
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
             elseif (is_object($value)) {
412 412
                 if ( ! method_exists($value, 'toNumber')) {
413 413
                     throw new \InvalidArgumentEXception(
414
-                         "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
414
+                            "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
415 415
                         ."Please add a toNumber() method."
416 416
                     );
417 417
                 }
@@ -595,12 +595,12 @@  discard block
 block discarded – undo
595 595
         $key_value_separator = ! empty($options['key_value_separator'])
596 596
                              ? $options['key_value_separator']
597 597
                              : ':'
598
-                             ;
598
+                                ;
599 599
 
600 600
         $groups_separator    = ! empty($options['groups_separator'])
601 601
                              ? $options['groups_separator']
602 602
                              : '-'
603
-                             ;
603
+                                ;
604 604
 
605 605
         $group_parts = [];
606 606
         foreach ($groups_definitions as $group_definition_key => $group_definition_value) {
@@ -676,8 +676,8 @@  discard block
 block discarded – undo
676 676
         foreach ($group_parts as $group_name => $group_value) {
677 677
             if (is_object($group_value)) {
678 678
                 $group_value = get_class($group_value)
679
-                             . '_'
680
-                             . hash( 'crc32b', var_export($group_value, true) );
679
+                                . '_'
680
+                                . hash( 'crc32b', var_export($group_value, true) );
681 681
             }
682 682
             elseif (is_array($group_value)) {
683 683
                 $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) );
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -135,16 +135,16 @@  discard block
 block discarded – undo
135 135
     public static function mergeRecursiveCustom(
136 136
         $existing_row,
137 137
         $conflict_row,
138
-        callable $merge_resolver=null,
139
-        $max_depth=null
140
-    ){
138
+        callable $merge_resolver = null,
139
+        $max_depth = null
140
+    ) {
141 141
         static::mustBeCountable($existing_row);
142 142
         static::mustBeCountable($conflict_row);
143 143
 
144 144
         foreach ($conflict_row as $column => $conflict_value) {
145 145
 
146 146
             // not existing in first array
147
-            if (!isset($existing_row[$column])) {
147
+            if ( ! isset($existing_row[$column])) {
148 148
                 $existing_row[$column] = $conflict_value;
149 149
                 continue;
150 150
             }
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
             }
178 178
             else {
179 179
                 // same resolution as array_merge_recursive
180
-                if (!is_array($existing_value)) {
180
+                if ( ! is_array($existing_value)) {
181 181
                     $existing_row[$column] = [$existing_value];
182 182
                 }
183 183
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     public static function mergePreservingDistincts(
203 203
         $existing_row,
204 204
         $conflict_row
205
-    ){
205
+    ) {
206 206
         return self::mergeInColumnBuckets($existing_row, $conflict_row);
207 207
     }
208 208
 
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
     public static function mergeInColumnBuckets(
220 220
         $existing_row,
221 221
         $conflict_row,
222
-        $existing_key=null,
223
-        $conflict_key=null
222
+        $existing_key = null,
223
+        $conflict_key = null
224 224
     ) {
225 225
         static::mustBeCountable($existing_row);
226 226
         static::mustBeCountable($conflict_row);
@@ -228,16 +228,16 @@  discard block
 block discarded – undo
228 228
         $merged_row = [];
229 229
         foreach ($existing_row as $existing_column => $existing_value) {
230 230
             if ($existing_value instanceof MergeBucket) {
231
-                $merged_row[ $existing_column ] = $existing_value;
231
+                $merged_row[$existing_column] = $existing_value;
232 232
             }
233 233
             else {
234 234
                 if (isset($existing_key)) {
235
-                    $merged_row[ $existing_column ] = MergeBucket::from([
235
+                    $merged_row[$existing_column] = MergeBucket::from([
236 236
                         $existing_key => $existing_value
237 237
                     ]);
238 238
                 }
239 239
                 else {
240
-                    $merged_row[ $existing_column ] = MergeBucket::from([
240
+                    $merged_row[$existing_column] = MergeBucket::from([
241 241
                         $existing_value
242 242
                     ]);
243 243
                 }
@@ -245,26 +245,26 @@  discard block
 block discarded – undo
245 245
         }
246 246
         
247 247
         foreach ($conflict_row as $conflict_column => $conflict_value) {
248
-            if (! isset($merged_row[ $conflict_column ])) {
249
-                $merged_row[ $conflict_column ] = new MergeBucket;
248
+            if ( ! isset($merged_row[$conflict_column])) {
249
+                $merged_row[$conflict_column] = new MergeBucket;
250 250
             }
251 251
             
252 252
             if ($conflict_value instanceof MergeBucket) {
253 253
                 foreach ($conflict_value as $conflict_bucket_value) {
254 254
                     if (isset($conflict_key)) {
255
-                        $merged_row[ $conflict_column ][$conflict_key] = $conflict_bucket_value;
255
+                        $merged_row[$conflict_column][$conflict_key] = $conflict_bucket_value;
256 256
                     }
257 257
                     else {
258
-                        $merged_row[ $conflict_column ][] = $conflict_bucket_value;
258
+                        $merged_row[$conflict_column][] = $conflict_bucket_value;
259 259
                     }
260 260
                 }
261 261
             }
262 262
             else {
263 263
                 if (isset($conflict_key)) {
264
-                    $merged_row[ $conflict_column ][$conflict_key] = $conflict_value;
264
+                    $merged_row[$conflict_column][$conflict_key] = $conflict_value;
265 265
                 }
266 266
                 else {
267
-                    $merged_row[ $conflict_column ][] = $conflict_value;
267
+                    $merged_row[$conflict_column][] = $conflict_value;
268 268
                 }
269 269
             }
270 270
         }
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      * @param  array|Countable   $row
279 279
      * @param  array             $options : 'excluded_columns'
280 280
      */
281
-    public static function cleanMergeDuplicates($row, array $options=[])
281
+    public static function cleanMergeDuplicates($row, array $options = [])
282 282
     {
283 283
         static::mustBeCountable($row);
284 284
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
      * @see mergePreservingDistincts()
312 312
      * @see cleanMergeDuplicates()
313 313
      */
314
-    public static function cleanMergeBuckets($row, array $options=[])
314
+    public static function cleanMergeBuckets($row, array $options = [])
315 315
     {
316 316
         static::mustBeCountable($row);
317 317
 
@@ -354,13 +354,13 @@  discard block
 block discarded – undo
354 354
                 $id = serialize($value);
355 355
             }
356 356
 
357
-            if (isset($ids[ $id ])) {
358
-                unset($array[ $key ]);
359
-                $ids[ $id ][] = $key;
357
+            if (isset($ids[$id])) {
358
+                unset($array[$key]);
359
+                $ids[$id][] = $key;
360 360
                 continue;
361 361
             }
362 362
 
363
-            $ids[ $id ] = [$key];
363
+            $ids[$id] = [$key];
364 364
         }
365 365
 
366 366
         return $array;
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
         }
381 381
         else {
382 382
             throw new \InvalidArgumentException(
383
-                "keyExists() method missing on :\n". var_export($array, true)
383
+                "keyExists() method missing on :\n".var_export($array, true)
384 384
             );
385 385
         }
386 386
 
@@ -456,16 +456,16 @@  discard block
 block discarded – undo
456 456
             throw new \InvalidArgumentException(
457 457
                 "Different number of "
458 458
                 ." values and weights for weight mean calculation: \n"
459
-                .var_export($values,  true)."\n\n"
459
+                .var_export($values, true)."\n\n"
460 460
                 .var_export($weights, true)
461 461
             );
462 462
         }
463 463
 
464
-        if (!$values)
464
+        if ( ! $values)
465 465
             return null;
466 466
 
467
-        $weights_sum  = array_sum($weights);
468
-        if (!$weights_sum)
467
+        $weights_sum = array_sum($weights);
468
+        if ( ! $weights_sum)
469 469
             return 0;
470 470
 
471 471
         $weighted_sum = 0;
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
         );
515 515
 
516 516
         // The true location of the throw is still available through the backtrace
517
-        $trace_location  = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
518
-        $reflectionClass = new \ReflectionClass( get_class($exception) );
517
+        $trace_location  = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
518
+        $reflectionClass = new \ReflectionClass(get_class($exception));
519 519
 
520 520
         // file
521 521
         if (isset($trace_location['file'])) {
@@ -552,8 +552,8 @@  discard block
 block discarded – undo
552 552
         );
553 553
 
554 554
         // The true location of the throw is still available through the backtrace
555
-        $trace_location  = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
556
-        $reflectionClass = new \ReflectionClass( get_class($exception) );
555
+        $trace_location  = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
556
+        $reflectionClass = new \ReflectionClass(get_class($exception));
557 557
 
558 558
         // file
559 559
         if (isset($trace_location['file'])) {
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
      *
594 594
      * @return string       The unique identifier of the group
595 595
      */
596
-    public static function generateGroupId($row, array $groups_definitions, array $options=[])
596
+    public static function generateGroupId($row, array $groups_definitions, array $options = [])
597 597
     {
598 598
         Arrays::mustBeCountable($row);
599 599
 
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
                              : ':'
603 603
                              ;
604 604
 
605
-        $groups_separator    = ! empty($options['groups_separator'])
605
+        $groups_separator = ! empty($options['groups_separator'])
606 606
                              ? $options['groups_separator']
607 607
                              : '-'
608 608
                              ;
@@ -616,32 +616,32 @@  discard block
 block discarded – undo
616 616
             }
617 617
 
618 618
             if (is_string($group_definition_value)) {
619
-                if (    (is_array($row)              && ! array_key_exists($group_definition_value, $row))
619
+                if ((is_array($row) && ! array_key_exists($group_definition_value, $row))
620 620
                     ||  ($row instanceof \ArrayAcces && ! $row->offsetExists($group_definition_value))
621 621
                 ) {
622 622
                     throw new UsageException(
623 623
                         'Unset column for group id generation: '
624 624
                         .var_export($group_definition_value, true)
625
-                        ."\n" . var_export($row, true)
625
+                        ."\n".var_export($row, true)
626 626
                     );
627 627
                 }
628 628
 
629 629
                 $part_name         .= $group_definition_value;
630
-                $group_result_value = $row[ $group_definition_value ];
630
+                $group_result_value = $row[$group_definition_value];
631 631
             }
632 632
             elseif (is_int($group_definition_value)) {
633
-                if (    (is_array($row)              && ! array_key_exists($group_definition_value, $row))
633
+                if ((is_array($row) && ! array_key_exists($group_definition_value, $row))
634 634
                     ||  ($row instanceof \ArrayAcces && ! $row->offsetExists($group_definition_value))
635 635
                 ) {
636 636
                     throw new UsageException(
637 637
                         'Unset column for group id generation: '
638 638
                         .var_export($group_definition_value, true)
639
-                        ."\n" . var_export($row, true)
639
+                        ."\n".var_export($row, true)
640 640
                     );
641 641
                 }
642 642
 
643
-                $part_name         .= $group_definition_value ? : '0';
644
-                $group_result_value = $row[ $group_definition_value ];
643
+                $part_name         .= $group_definition_value ?: '0';
644
+                $group_result_value = $row[$group_definition_value];
645 645
             }
646 646
             elseif (is_callable($group_definition_value)) {
647 647
 
@@ -665,12 +665,12 @@  discard block
 block discarded – undo
665 665
                 throw new UsageException(
666 666
                     'Bad value provided for group id generation: '
667 667
                     .var_export($group_definition_value, true)
668
-                    ."\n" . var_export($row, true)
668
+                    ."\n".var_export($row, true)
669 669
                 );
670 670
             }
671 671
 
672
-            if (!is_null($part_name))
673
-                $group_parts[ $part_name ] = $group_result_value;
672
+            if ( ! is_null($part_name))
673
+                $group_parts[$part_name] = $group_result_value;
674 674
         }
675 675
 
676 676
         // sort the groups by names (without it the same group could have multiple ids)
@@ -682,13 +682,13 @@  discard block
 block discarded – undo
682 682
             if (is_object($group_value)) {
683 683
                 $group_value = get_class($group_value)
684 684
                              . '_'
685
-                             . hash( 'crc32b', var_export($group_value, true) );
685
+                             . hash('crc32b', var_export($group_value, true));
686 686
             }
687 687
             elseif (is_array($group_value)) {
688
-                $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) );
688
+                $group_value = 'array_'.hash('crc32b', var_export($group_value, true));
689 689
             }
690 690
 
691
-            $out[] = $group_name . $key_value_separator . $group_value;
691
+            $out[] = $group_name.$key_value_separator.$group_value;
692 692
         }
693 693
 
694 694
         return implode($groups_separator, $out);
Please login to merge, or discard this patch.
Braces   +57 added lines, -66 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,17 +246,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.