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