Completed
Push — master ( 7732b1...2a9c77 )
by Jean
02:09
created
src/Arrays.php 3 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         $excluded_columns = isset($options['excluded_columns'])
242 242
                           ? $options['excluded_columns']
243 243
                           : []
244
-                          ;
244
+                            ;
245 245
 
246 246
         foreach ($row as $column => &$values) {
247 247
             if ( ! $values instanceof MergeBucket)
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
         $excluded_columns = isset($options['excluded_columns'])
279 279
                           ? $options['excluded_columns']
280 280
                           : []
281
-                          ;
281
+                            ;
282 282
 
283 283
         foreach ($row as $column => &$values) {
284 284
             if (in_array($column, $excluded_columns))
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
             elseif (is_object($value)) {
364 364
                 if ( ! method_exists($value, 'toNumber')) {
365 365
                     throw new \InvalidArgumentEXception(
366
-                         "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
366
+                            "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
367 367
                         ."Please add a toNumber() method."
368 368
                     );
369 369
                 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
     public static function mergeRecursiveCustom(
135 135
         array $existing_row,
136 136
         array $conflict_row,
137
-        callable $merge_resolver=null,
138
-        $max_depth=null
139
-    ){
137
+        callable $merge_resolver = null,
138
+        $max_depth = null
139
+    ) {
140 140
         foreach ($conflict_row as $column => $conflict_value) {
141 141
 
142 142
             // not existing in first array
143
-            if (!isset($existing_row[$column])) {
143
+            if ( ! isset($existing_row[$column])) {
144 144
                 $existing_row[$column] = $conflict_value;
145 145
                 continue;
146 146
             }
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
             }
174 174
             else {
175 175
                 // same resolution as array_merge_recursive
176
-                if (!is_array($existing_value)) {
176
+                if ( ! is_array($existing_value)) {
177 177
                     $existing_row[$column] = [$existing_value];
178 178
                 }
179 179
 
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
     public static function mergePreservingDistincts(
197 197
         array $existing_row,
198 198
         array $conflict_row
199
-    ){
199
+    ) {
200 200
         $merge = static::mergeRecursiveCustom(
201 201
             $existing_row,
202 202
             $conflict_row,
203
-            function ($existing_value, $conflict_value, $column) {
203
+            function($existing_value, $conflict_value, $column) {
204 204
 
205 205
                 if ( ! $existing_value instanceof MergeBucket) {
206 206
                     $existing_value = MergeBucket::from()->push($existing_value);
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
      * @param  array|Traversable $row
230 230
      * @param  array             $options : 'excluded_columns'
231 231
      */
232
-    public static function cleanMergeDuplicates($row, array $options=[])
232
+    public static function cleanMergeDuplicates($row, array $options = [])
233 233
     {
234 234
         if ( ! is_array($row) && ! $row instanceof \Traversable) {
235 235
             throw new \InvalidArgumentException(
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
      *
267 267
      * @see mergePreservingDistincts()
268 268
      */
269
-    public static function cleanMergeBuckets($row, array $options=[])
269
+    public static function cleanMergeBuckets($row, array $options = [])
270 270
     {
271 271
         if ( ! is_array($row) && ! $row instanceof \Traversable) {
272 272
             throw new \InvalidArgumentException(
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      */
302 302
     public static function unique($array)
303 303
     {
304
-        if (! is_array($array) && ! $array instanceof \Traversable) {
304
+        if ( ! is_array($array) && ! $array instanceof \Traversable) {
305 305
             throw new \InvalidArgumentException(
306 306
                 "\$array must be an array or a \Traversable instead of: \n"
307 307
                 .var_export($array, true)
@@ -317,13 +317,13 @@  discard block
 block discarded – undo
317 317
                 $id = serialize($value);
318 318
             }
319 319
 
320
-            if (isset($ids[ $id ])) {
321
-                unset($array[ $key ]);
322
-                $ids[ $id ][] = $key;
320
+            if (isset($ids[$id])) {
321
+                unset($array[$key]);
322
+                $ids[$id][] = $key;
323 323
                 continue;
324 324
             }
325 325
 
326
-            $ids[ $id ] = [$key];
326
+            $ids[$id] = [$key];
327 327
         }
328 328
 
329 329
         return $array;
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
      */
341 341
     public static function sum($array)
342 342
     {
343
-        if (! is_array($array) && ! $array instanceof \Traversable) {
343
+        if ( ! is_array($array) && ! $array instanceof \Traversable) {
344 344
             throw new \InvalidArgumentException(
345 345
                 "\$array must be an array or a \Traversable instead of: \n"
346 346
                 .var_export($array, true)
@@ -403,16 +403,16 @@  discard block
 block discarded – undo
403 403
             throw new \InvalidArgumentException(
404 404
                 "Different number of "
405 405
                 ." values and weights for weight mean calculation: \n"
406
-                .var_export($values,  true)."\n\n"
406
+                .var_export($values, true)."\n\n"
407 407
                 .var_export($weights, true)
408 408
             );
409 409
         }
410 410
 
411
-        if (!$values)
411
+        if ( ! $values)
412 412
             return null;
413 413
 
414
-        $weights_sum  = array_sum($weights);
415
-        if (!$weights_sum)
414
+        $weights_sum = array_sum($weights);
415
+        if ( ! $weights_sum)
416 416
             return 0;
417 417
 
418 418
         $weighted_sum = 0;
Please login to merge, or discard this patch.
Braces   +42 added lines, -40 removed lines patch added patch discarded remove patch
@@ -64,14 +64,12 @@  discard block
 block discarded – undo
64 64
                 )
65 65
                 {
66 66
                     $array1[$key] = self::merge($array1[$key], $value);
67
-                }
68
-                else
67
+                } else
69 68
                 {
70 69
                     $array1[$key] = $value;
71 70
                 }
72 71
             }
73
-        }
74
-        else
72
+        } else
75 73
         {
76 74
             foreach ($array2 as $value)
77 75
             {
@@ -96,14 +94,12 @@  discard block
 block discarded – undo
96 94
                         )
97 95
                         {
98 96
                             $array1[$key] = self::merge($array1[$key], $value);
99
-                        }
100
-                        else
97
+                        } else
101 98
                         {
102 99
                             $array1[$key] = $value;
103 100
                         }
104 101
                     }
105
-                }
106
-                else
102
+                } else
107 103
                 {
108 104
                     foreach ($array2 as $value)
109 105
                     {
@@ -170,8 +166,7 @@  discard block
 block discarded – undo
170 166
                         $column,
171 167
                     ]
172 168
                 );
173
-            }
174
-            else {
169
+            } else {
175 170
                 // same resolution as array_merge_recursive
176 171
                 if (!is_array($existing_value)) {
177 172
                     $existing_row[$column] = [$existing_value];
@@ -244,15 +239,18 @@  discard block
 block discarded – undo
244 239
                           ;
245 240
 
246 241
         foreach ($row as $column => &$values) {
247
-            if ( ! $values instanceof MergeBucket)
248
-                continue;
242
+            if ( ! $values instanceof MergeBucket) {
243
+                            continue;
244
+            }
249 245
 
250
-            if (in_array($column, $excluded_columns))
251
-                continue;
246
+            if (in_array($column, $excluded_columns)) {
247
+                            continue;
248
+            }
252 249
 
253 250
             $values = Arrays::unique($values);
254
-            if (count($values) == 1)
255
-                $values = $values[0];
251
+            if (count($values) == 1) {
252
+                            $values = $values[0];
253
+            }
256 254
         }
257 255
 
258 256
         return $row;
@@ -281,11 +279,13 @@  discard block
 block discarded – undo
281 279
                           ;
282 280
 
283 281
         foreach ($row as $column => &$values) {
284
-            if (in_array($column, $excluded_columns))
285
-                continue;
282
+            if (in_array($column, $excluded_columns)) {
283
+                            continue;
284
+            }
286 285
 
287
-            if ($values instanceof MergeBucket)
288
-                $values = $values->toArray();
286
+            if ($values instanceof MergeBucket) {
287
+                            $values = $values->toArray();
288
+            }
289 289
         }
290 290
 
291 291
         return $row;
@@ -312,8 +312,7 @@  discard block
 block discarded – undo
312 312
         foreach ($array as $key => $value) {
313 313
             if (is_scalar($value)) {
314 314
                 $id = $value;
315
-            }
316
-            else {
315
+            } else {
317 316
                 $id = serialize($value);
318 317
             }
319 318
 
@@ -351,16 +350,13 @@  discard block
 block discarded – undo
351 350
         foreach ($array as $key => &$value) { // &for optimization
352 351
             if (is_scalar($value)) {
353 352
                 $sum += $value;
354
-            }
355
-            elseif (is_null($value)) {
353
+            } elseif (is_null($value)) {
356 354
                 continue;
357
-            }
358
-            elseif (is_array($value)) {
355
+            } elseif (is_array($value)) {
359 356
                 throw new \InvalidArgumentException(
360 357
                     "Trying to sum an array with '$sum': ".var_export($value, true)
361 358
                 );
362
-            }
363
-            elseif (is_object($value)) {
359
+            } elseif (is_object($value)) {
364 360
                 if ( ! method_exists($value, 'toNumber')) {
365 361
                     throw new \InvalidArgumentEXception(
366 362
                          "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
@@ -387,17 +383,21 @@  discard block
 block discarded – undo
387 383
      */
388 384
     public static function weightedMean($values, $weights)
389 385
     {
390
-        if ($values instanceof ChainableArray)
391
-            $values = $values->toArray();
386
+        if ($values instanceof ChainableArray) {
387
+                    $values = $values->toArray();
388
+        }
392 389
 
393
-        if ($weights instanceof ChainableArray)
394
-            $weights = $weights->toArray();
390
+        if ($weights instanceof ChainableArray) {
391
+                    $weights = $weights->toArray();
392
+        }
395 393
 
396
-        if ( ! is_array($values))
397
-            $values = [$values];
394
+        if ( ! is_array($values)) {
395
+                    $values = [$values];
396
+        }
398 397
 
399
-        if ( ! is_array($weights))
400
-            $weights = [$weights];
398
+        if ( ! is_array($weights)) {
399
+                    $weights = [$weights];
400
+        }
401 401
 
402 402
         if (count($values) != count($weights)) {
403 403
             throw new \InvalidArgumentException(
@@ -408,12 +408,14 @@  discard block
 block discarded – undo
408 408
             );
409 409
         }
410 410
 
411
-        if (!$values)
412
-            return null;
411
+        if (!$values) {
412
+                    return null;
413
+        }
413 414
 
414 415
         $weights_sum  = array_sum($weights);
415
-        if (!$weights_sum)
416
-            return 0;
416
+        if (!$weights_sum) {
417
+                    return 0;
418
+        }
417 419
 
418 420
         $weighted_sum = 0;
419 421
         foreach ($values as $i => $value) {
Please login to merge, or discard this patch.