Passed
Push — master ( 5a3130...b581bc )
by Jean
04:21
created
src/Arrays/Arrays.php 1 patch
Braces   +39 added lines, -42 removed lines patch added patch discarded remove patch
@@ -50,8 +50,7 @@  discard block
 block discarded – undo
50 50
         foreach ($array as $key => $value) {
51 51
             if (is_scalar($value)) {
52 52
                 $id = $value;
53
-            }
54
-            else {
53
+            } else {
55 54
                 $id = serialize($value);
56 55
             }
57 56
 
@@ -75,11 +74,9 @@  discard block
 block discarded – undo
75 74
 
76 75
         if (is_array($array)) {
77 76
             return array_key_exists($key, $array);
78
-        }
79
-        elseif ($array instanceof ChainableArray || method_exists($array, 'keyExists')) {
77
+        } elseif ($array instanceof ChainableArray || method_exists($array, 'keyExists')) {
80 78
             return $array->keyExists($key);
81
-        }
82
-        else {
79
+        } else {
83 80
             throw new \InvalidArgumentException(
84 81
                 "keyExists() method missing on :\n". var_export($array, true)
85 82
             );
@@ -105,16 +102,13 @@  discard block
 block discarded – undo
105 102
         foreach ($array as $key => &$value) { // &for optimization
106 103
             if (is_scalar($value)) {
107 104
                 $sum += $value;
108
-            }
109
-            elseif (is_null($value)) {
105
+            } elseif (is_null($value)) {
110 106
                 continue;
111
-            }
112
-            elseif (is_array($value)) {
107
+            } elseif (is_array($value)) {
113 108
                 throw new \InvalidArgumentException(
114 109
                     "Trying to sum an array with '$sum': ".var_export($value, true)
115 110
                 );
116
-            }
117
-            elseif (is_object($value)) {
111
+            } elseif (is_object($value)) {
118 112
                 if ( ! method_exists($value, 'toNumber')) {
119 113
                     throw new \InvalidArgumentEXception(
120 114
                          "Trying to sum a ".get_class($value)." object which cannot be casted as a number. "
@@ -141,17 +135,21 @@  discard block
 block discarded – undo
141 135
      */
142 136
     public static function weightedMean($values, $weights)
143 137
     {
144
-        if ($values instanceof ChainableArray)
145
-            $values = $values->toArray();
138
+        if ($values instanceof ChainableArray) {
139
+                    $values = $values->toArray();
140
+        }
146 141
 
147
-        if ($weights instanceof ChainableArray)
148
-            $weights = $weights->toArray();
142
+        if ($weights instanceof ChainableArray) {
143
+                    $weights = $weights->toArray();
144
+        }
149 145
 
150
-        if ( ! is_array($values))
151
-            $values = [$values];
146
+        if ( ! is_array($values)) {
147
+                    $values = [$values];
148
+        }
152 149
 
153
-        if ( ! is_array($weights))
154
-            $weights = [$weights];
150
+        if ( ! is_array($weights)) {
151
+                    $weights = [$weights];
152
+        }
155 153
 
156 154
         if (count($values) != count($weights)) {
157 155
             throw new \InvalidArgumentException(
@@ -162,12 +160,14 @@  discard block
 block discarded – undo
162 160
             );
163 161
         }
164 162
 
165
-        if (!$values)
166
-            return null;
163
+        if (!$values) {
164
+                    return null;
165
+        }
167 166
 
168 167
         $weights_sum  = array_sum($weights);
169
-        if (!$weights_sum)
170
-            return 0;
168
+        if (!$weights_sum) {
169
+                    return 0;
170
+        }
171 171
 
172 172
         $weighted_sum = 0;
173 173
         foreach ($values as $i => $value) {
@@ -206,8 +206,9 @@  discard block
 block discarded – undo
206 206
      */
207 207
     public static function mustBeCountable($value)
208 208
     {
209
-        if (static::isCountable($value))
210
-            return true;
209
+        if (static::isCountable($value)) {
210
+                    return true;
211
+        }
211 212
 
212 213
         $exception = new \InvalidArgumentException(
213 214
             "A value must be Countable instead of: \n"
@@ -244,8 +245,9 @@  discard block
 block discarded – undo
244 245
      */
245 246
     public static function mustBeTraversable($value)
246 247
     {
247
-        if (static::isTraversable($value))
248
-            return true;
248
+        if (static::isTraversable($value)) {
249
+                    return true;
250
+        }
249 251
 
250 252
         $exception = new \InvalidArgumentException(
251 253
             "A value must be Traversable instead of: \n"
@@ -329,8 +331,7 @@  discard block
 block discarded – undo
329 331
 
330 332
                 $part_name         .= $group_definition_value;
331 333
                 $group_result_value = $row[ $group_definition_value ];
332
-            }
333
-            elseif (is_int($group_definition_value)) {
334
+            } elseif (is_int($group_definition_value)) {
334 335
                 if (    (is_array($row)              && ! array_key_exists($group_definition_value, $row))
335 336
                     ||  ($row instanceof \ArrayAcces && ! $row->offsetExists($group_definition_value))
336 337
                 ) {
@@ -343,8 +344,7 @@  discard block
 block discarded – undo
343 344
 
344 345
                 $part_name         .= $group_definition_value ? : '0';
345 346
                 $group_result_value = $row[ $group_definition_value ];
346
-            }
347
-            elseif (is_callable($group_definition_value)) {
347
+            } elseif (is_callable($group_definition_value)) {
348 348
 
349 349
                 if (is_string($group_definition_value)) {
350 350
                     $part_name .= $group_definition_value;
@@ -353,16 +353,14 @@  discard block
 block discarded – undo
353 353
                 elseif (is_object($group_definition_value) && ($group_definition_value instanceof \Closure)) {
354 354
                     $part_name .= 'unnamed-closure-'
355 355
                                 . hash('crc32b', var_export($group_definition_value, true));
356
-                }
357
-                elseif (is_array($group_definition_value)) {
356
+                } elseif (is_array($group_definition_value)) {
358 357
                     $part_name .= implode('::', $group_definition_value);
359 358
                 }
360 359
 
361 360
                 $group_result_value = call_user_func_array($group_definition_value, [
362 361
                     $row, &$part_name
363 362
                 ]);
364
-            }
365
-            else {
363
+            } else {
366 364
                 throw new UsageException(
367 365
                     'Bad value provided for group id generation: '
368 366
                     .var_export($group_definition_value, true)
@@ -370,8 +368,9 @@  discard block
 block discarded – undo
370 368
                 );
371 369
             }
372 370
 
373
-            if (!is_null($part_name))
374
-                $group_parts[ $part_name ] = $group_result_value;
371
+            if (!is_null($part_name)) {
372
+                            $group_parts[ $part_name ] = $group_result_value;
373
+            }
375 374
         }
376 375
 
377 376
         // sort the groups by names (without it the same group could have multiple ids)
@@ -384,8 +383,7 @@  discard block
 block discarded – undo
384 383
                 $group_value = get_class($group_value)
385 384
                              . '_'
386 385
                              . hash( 'crc32b', var_export($group_value, true) );
387
-            }
388
-            elseif (is_array($group_value)) {
386
+            } elseif (is_array($group_value)) {
389 387
                 $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) );
390 388
             }
391 389
 
@@ -439,8 +437,7 @@  discard block
 block discarded – undo
439 437
         foreach ($location_parts as $location_part) {
440 438
             if (isset($value[$location_part])) {
441 439
                 $value = $value[$location_part];
442
-            }
443
-            else {
440
+            } else {
444 441
                 return $default_value;
445 442
             }
446 443
         }
Please login to merge, or discard this patch.