Completed
Push — master ( 4ce22d...b7b9fb )
by Jean
02:22
created
src/Arrays.php 2 patches
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);
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
     {
231 231
         foreach ($merged_row as $entry => $values) {
232 232
             if ($values instanceof MergeBucket) {
233
-                $merged_row[ $entry ] = $values->toArray();
233
+                $merged_row[$entry] = $values->toArray();
234 234
             }
235 235
         }
236 236
 
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
      *
243 243
      * @see mergePreservingDistincts()
244 244
      */
245
-    public static function keepUniqueColumnValues(array $row, array $excluded_columns=[])
245
+    public static function keepUniqueColumnValues(array $row, array $excluded_columns = [])
246 246
     {
247 247
         foreach ($row as $column => &$values) {
248
-            if (!is_array($values))
248
+            if ( ! is_array($values))
249 249
                 continue;
250 250
 
251 251
             if (in_array($column, $excluded_columns))
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
      */
270 270
     public static function unique($array)
271 271
     {
272
-        if (! is_array($array) && ! $array instanceof \Traversable) {
272
+        if ( ! is_array($array) && ! $array instanceof \Traversable) {
273 273
             throw new \InvalidArgumentException(
274 274
                 "\$array must be an array or a \Traversable instead of: \n"
275 275
                 .var_export($array, true)
@@ -285,13 +285,13 @@  discard block
 block discarded – undo
285 285
                 $id = serialize($value);
286 286
             }
287 287
 
288
-            if (isset($ids[ $id ])) {
289
-                unset($array[ $key ]);
290
-                $ids[ $id ][] = $key;
288
+            if (isset($ids[$id])) {
289
+                unset($array[$key]);
290
+                $ids[$id][] = $key;
291 291
                 continue;
292 292
             }
293 293
 
294
-            $ids[ $id ] = [$key];
294
+            $ids[$id] = [$key];
295 295
         }
296 296
 
297 297
         return $array;
@@ -319,16 +319,16 @@  discard block
 block discarded – undo
319 319
             throw new \InvalidArgumentException(
320 320
                 "Different number of "
321 321
                 ." values and weights for weight mean calculation: \n"
322
-                .var_export($values,  true)."\n\n"
322
+                .var_export($values, true)."\n\n"
323 323
                 .var_export($weights, true)
324 324
             );
325 325
         }
326 326
 
327
-        if (!$values)
327
+        if ( ! $values)
328 328
             return null;
329 329
 
330
-        $weights_sum  = array_sum($weights);
331
-        if (!$weights_sum)
330
+        $weights_sum = array_sum($weights);
331
+        if ( ! $weights_sum)
332 332
             return 0;
333 333
 
334 334
         $weighted_sum = 0;
Please login to merge, or discard this patch.
Braces   +27 added lines, -26 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
 
@@ -309,11 +306,13 @@  discard block
 block discarded – undo
309 306
      */
310 307
     public static function weightedMean($values, $weights)
311 308
     {
312
-        if ( ! is_array($values))
313
-            $values = [$values];
309
+        if ( ! is_array($values)) {
310
+                    $values = [$values];
311
+        }
314 312
 
315
-        if ( ! is_array($weights))
316
-            $weights = [$weights];
313
+        if ( ! is_array($weights)) {
314
+                    $weights = [$weights];
315
+        }
317 316
 
318 317
         if (count($values) != count($weights)) {
319 318
             throw new \InvalidArgumentException(
@@ -324,12 +323,14 @@  discard block
 block discarded – undo
324 323
             );
325 324
         }
326 325
 
327
-        if (!$values)
328
-            return null;
326
+        if (!$values) {
327
+                    return null;
328
+        }
329 329
 
330 330
         $weights_sum  = array_sum($weights);
331
-        if (!$weights_sum)
332
-            return 0;
331
+        if (!$weights_sum) {
332
+                    return 0;
333
+        }
333 334
 
334 335
         $weighted_sum = 0;
335 336
         foreach ($values as $i => $value) {
Please login to merge, or discard this patch.