Completed
Push — master ( d20ccf...046303 )
by Jean
02:40
created
src/Arrays.php 1 patch
Braces   +38 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];
@@ -245,15 +240,18 @@  discard block
 block discarded – undo
245 240
     public static function keepUniqueColumnValues(array $row, array $excluded_columns=[])
246 241
     {
247 242
         foreach ($row as $column => &$values) {
248
-            if (!is_array($values))
249
-                continue;
243
+            if (!is_array($values)) {
244
+                            continue;
245
+            }
250 246
 
251
-            if (in_array($column, $excluded_columns))
252
-                continue;
247
+            if (in_array($column, $excluded_columns)) {
248
+                            continue;
249
+            }
253 250
 
254 251
             $values = array_unique($values);
255
-            if (count($values) == 1)
256
-                $values = $values[0];
252
+            if (count($values) == 1) {
253
+                            $values = $values[0];
254
+            }
257 255
         }
258 256
 
259 257
         return $row;
@@ -280,8 +278,7 @@  discard block
 block discarded – undo
280 278
         foreach ($array as $key => $value) {
281 279
             if (is_scalar($value)) {
282 280
                 $id = $value;
283
-            }
284
-            else {
281
+            } else {
285 282
                 $id = serialize($value);
286 283
             }
287 284
 
@@ -319,28 +316,23 @@  discard block
 block discarded – undo
319 316
         foreach ($array as $key => &$value) { // &for optimization
320 317
             if (is_scalar($value)) {
321 318
                 $sum += $value;
322
-            }
323
-            elseif (is_null($value)) {
319
+            } elseif (is_null($value)) {
324 320
                 continue;
325
-            }
326
-            elseif (is_array($value)) {
321
+            } elseif (is_array($value)) {
327 322
                 throw new \InvalidArgumentException(
328 323
                     "Trying to sum an array with '$sum': ".var_export($value, true)
329 324
                 );
330
-            }
331
-            elseif (is_object($value)) {
325
+            } elseif (is_object($value)) {
332 326
                 if (version_compare(phpversion(), '7.0.0', '>=')) {
333 327
                     try {
334 328
                         $sum += $value->toNumber();
335
-                    }
336
-                    catch (\Exception $e) {
329
+                    } catch (\Exception $e) {
337 330
                         throw new \InvalidArgumentEXception(
338 331
                              "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
339 332
                             ."Please add a toNumber() method."
340 333
                         );
341 334
                     }
342
-                }
343
-                else {
335
+                } else {
344 336
                     if ( ! method_exists($value, 'toNumber')) {
345 337
                         throw new \InvalidArgumentEXception(
346 338
                              "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
@@ -368,17 +360,21 @@  discard block
 block discarded – undo
368 360
      */
369 361
     public static function weightedMean($values, $weights)
370 362
     {
371
-        if ($values instanceof ChainableArray)
372
-            $values = $values->toArray();
363
+        if ($values instanceof ChainableArray) {
364
+                    $values = $values->toArray();
365
+        }
373 366
 
374
-        if ($weights instanceof ChainableArray)
375
-            $weights = $weights->toArray();
367
+        if ($weights instanceof ChainableArray) {
368
+                    $weights = $weights->toArray();
369
+        }
376 370
 
377
-        if ( ! is_array($values))
378
-            $values = [$values];
371
+        if ( ! is_array($values)) {
372
+                    $values = [$values];
373
+        }
379 374
 
380
-        if ( ! is_array($weights))
381
-            $weights = [$weights];
375
+        if ( ! is_array($weights)) {
376
+                    $weights = [$weights];
377
+        }
382 378
 
383 379
         if (count($values) != count($weights)) {
384 380
             throw new \InvalidArgumentException(
@@ -389,12 +385,14 @@  discard block
 block discarded – undo
389 385
             );
390 386
         }
391 387
 
392
-        if (!$values)
393
-            return null;
388
+        if (!$values) {
389
+                    return null;
390
+        }
394 391
 
395 392
         $weights_sum  = array_sum($weights);
396
-        if (!$weights_sum)
397
-            return 0;
393
+        if (!$weights_sum) {
394
+                    return 0;
395
+        }
398 396
 
399 397
         $weighted_sum = 0;
400 398
         foreach ($values as $i => $value) {
Please login to merge, or discard this patch.