@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $excluded_columns = isset($options['excluded_columns']) |
109 | 109 | ? $options['excluded_columns'] |
110 | 110 | : [] |
111 | - ; |
|
111 | + ; |
|
112 | 112 | |
113 | 113 | foreach ($row as $column => &$values) { |
114 | 114 | if (in_array($column, $excluded_columns)) { |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $excluded_columns = isset($options['excluded_columns']) |
137 | 137 | ? $options['excluded_columns'] |
138 | 138 | : [] |
139 | - ; |
|
139 | + ; |
|
140 | 140 | |
141 | 141 | foreach ($row as $column => &$values) { |
142 | 142 | if ( ! $values instanceof MergeBucket) |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | public static function mergeInColumnBuckets( |
23 | 23 | $existing_row, |
24 | 24 | $conflict_row, |
25 | - $existing_key=null, |
|
26 | - $conflict_key=null |
|
25 | + $existing_key = null, |
|
26 | + $conflict_key = null |
|
27 | 27 | ) { |
28 | 28 | static::mustBeCountable($existing_row); |
29 | 29 | static::mustBeCountable($conflict_row); |
@@ -31,16 +31,16 @@ discard block |
||
31 | 31 | $merged_row = []; |
32 | 32 | foreach ($existing_row as $existing_column => $existing_value) { |
33 | 33 | if ($existing_value instanceof MergeBucket) { |
34 | - $merged_row[ $existing_column ] = $existing_value; |
|
34 | + $merged_row[$existing_column] = $existing_value; |
|
35 | 35 | } |
36 | 36 | else { |
37 | 37 | if (isset($existing_key)) { |
38 | - $merged_row[ $existing_column ] = MergeBucket::from([ |
|
38 | + $merged_row[$existing_column] = MergeBucket::from([ |
|
39 | 39 | $existing_key => $existing_value |
40 | 40 | ]); |
41 | 41 | } |
42 | 42 | else { |
43 | - $merged_row[ $existing_column ] = MergeBucket::from([ |
|
43 | + $merged_row[$existing_column] = MergeBucket::from([ |
|
44 | 44 | $existing_value |
45 | 45 | ]); |
46 | 46 | } |
@@ -48,26 +48,26 @@ discard block |
||
48 | 48 | } |
49 | 49 | |
50 | 50 | foreach ($conflict_row as $conflict_column => $conflict_value) { |
51 | - if (! isset($merged_row[ $conflict_column ])) { |
|
52 | - $merged_row[ $conflict_column ] = new MergeBucket; |
|
51 | + if ( ! isset($merged_row[$conflict_column])) { |
|
52 | + $merged_row[$conflict_column] = new MergeBucket; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | if ($conflict_value instanceof MergeBucket) { |
56 | 56 | foreach ($conflict_value as $conflict_bucket_value) { |
57 | 57 | if (isset($conflict_key)) { |
58 | - $merged_row[ $conflict_column ][$conflict_key] = $conflict_bucket_value; |
|
58 | + $merged_row[$conflict_column][$conflict_key] = $conflict_bucket_value; |
|
59 | 59 | } |
60 | 60 | else { |
61 | - $merged_row[ $conflict_column ][] = $conflict_bucket_value; |
|
61 | + $merged_row[$conflict_column][] = $conflict_bucket_value; |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | } |
65 | 65 | else { |
66 | 66 | if (isset($conflict_key)) { |
67 | - $merged_row[ $conflict_column ][$conflict_key] = $conflict_value; |
|
67 | + $merged_row[$conflict_column][$conflict_key] = $conflict_value; |
|
68 | 68 | } |
69 | 69 | else { |
70 | - $merged_row[ $conflict_column ][] = $conflict_value; |
|
70 | + $merged_row[$conflict_column][] = $conflict_value; |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @see mergePreservingDistincts() |
102 | 102 | * @see cleanMergeDuplicates() |
103 | 103 | */ |
104 | - public static function cleanMergeBuckets($row, array $options=[]) |
|
104 | + public static function cleanMergeBuckets($row, array $options = []) |
|
105 | 105 | { |
106 | 106 | static::mustBeCountable($row); |
107 | 107 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @param array|Countable $row |
130 | 130 | * @param array $options : 'excluded_columns' |
131 | 131 | */ |
132 | - public static function cleanMergeDuplicates($row, array $options=[]) |
|
132 | + public static function cleanMergeDuplicates($row, array $options = []) |
|
133 | 133 | { |
134 | 134 | static::mustBeCountable($row); |
135 | 135 | |
@@ -168,16 +168,16 @@ discard block |
||
168 | 168 | public static function mergeRecursiveCustom( |
169 | 169 | $existing_row, |
170 | 170 | $conflict_row, |
171 | - callable $merge_resolver=null, |
|
172 | - $max_depth=null |
|
173 | - ){ |
|
171 | + callable $merge_resolver = null, |
|
172 | + $max_depth = null |
|
173 | + ) { |
|
174 | 174 | static::mustBeCountable($existing_row); |
175 | 175 | static::mustBeCountable($conflict_row); |
176 | 176 | |
177 | 177 | foreach ($conflict_row as $column => $conflict_value) { |
178 | 178 | |
179 | 179 | // not existing in first array |
180 | - if (!isset($existing_row[$column])) { |
|
180 | + if ( ! isset($existing_row[$column])) { |
|
181 | 181 | $existing_row[$column] = $conflict_value; |
182 | 182 | continue; |
183 | 183 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | } |
211 | 211 | else { |
212 | 212 | // same resolution as array_merge_recursive |
213 | - if (!is_array($existing_value)) { |
|
213 | + if ( ! is_array($existing_value)) { |
|
214 | 214 | $existing_row[$column] = [$existing_value]; |
215 | 215 | } |
216 | 216 | |
@@ -325,24 +325,24 @@ discard block |
||
325 | 325 | { |
326 | 326 | $result = []; |
327 | 327 | foreach ($array as $key => $value) { |
328 | - if (! $value instanceof MergeBucket) { |
|
329 | - $result[ $key ] = $value; |
|
328 | + if ( ! $value instanceof MergeBucket) { |
|
329 | + $result[$key] = $value; |
|
330 | 330 | } |
331 | 331 | else { |
332 | 332 | foreach ($value as $sub_key => $sub_value) { |
333 | 333 | if (is_int($sub_key)) { |
334 | 334 | $result[] = $sub_value; |
335 | 335 | } |
336 | - elseif (isset($result[ $sub_key ])) { |
|
336 | + elseif (isset($result[$sub_key])) { |
|
337 | 337 | throw new \LogicException( |
338 | 338 | "Conflict during flatten merge for key $sub_key between: \n" |
339 | - ."Existing: " . var_export($result[ $sub_key ], true) |
|
339 | + ."Existing: ".var_export($result[$sub_key], true) |
|
340 | 340 | ."\n and \n" |
341 | - ."Conflict: " . var_export($sub_value, true) |
|
341 | + ."Conflict: ".var_export($sub_value, true) |
|
342 | 342 | ); |
343 | 343 | } |
344 | 344 | else { |
345 | - $result[ $sub_key ] = $sub_value; |
|
345 | + $result[$sub_key] = $sub_value; |
|
346 | 346 | } |
347 | 347 | } |
348 | 348 | } |
@@ -32,14 +32,12 @@ discard block |
||
32 | 32 | foreach ($existing_row as $existing_column => $existing_value) { |
33 | 33 | if ($existing_value instanceof MergeBucket) { |
34 | 34 | $merged_row[ $existing_column ] = $existing_value; |
35 | - } |
|
36 | - else { |
|
35 | + } else { |
|
37 | 36 | if (isset($existing_key)) { |
38 | 37 | $merged_row[ $existing_column ] = MergeBucket::from([ |
39 | 38 | $existing_key => $existing_value |
40 | 39 | ]); |
41 | - } |
|
42 | - else { |
|
40 | + } else { |
|
43 | 41 | $merged_row[ $existing_column ] = MergeBucket::from([ |
44 | 42 | $existing_value |
45 | 43 | ]); |
@@ -56,17 +54,14 @@ discard block |
||
56 | 54 | foreach ($conflict_value as $conflict_bucket_value) { |
57 | 55 | if (isset($conflict_key)) { |
58 | 56 | $merged_row[ $conflict_column ][$conflict_key] = $conflict_bucket_value; |
59 | - } |
|
60 | - else { |
|
57 | + } else { |
|
61 | 58 | $merged_row[ $conflict_column ][] = $conflict_bucket_value; |
62 | 59 | } |
63 | 60 | } |
64 | - } |
|
65 | - else { |
|
61 | + } else { |
|
66 | 62 | if (isset($conflict_key)) { |
67 | 63 | $merged_row[ $conflict_column ][$conflict_key] = $conflict_value; |
68 | - } |
|
69 | - else { |
|
64 | + } else { |
|
70 | 65 | $merged_row[ $conflict_column ][] = $conflict_value; |
71 | 66 | } |
72 | 67 | } |
@@ -139,15 +134,18 @@ discard block |
||
139 | 134 | ; |
140 | 135 | |
141 | 136 | foreach ($row as $column => &$values) { |
142 | - if ( ! $values instanceof MergeBucket) |
|
143 | - continue; |
|
137 | + if ( ! $values instanceof MergeBucket) { |
|
138 | + continue; |
|
139 | + } |
|
144 | 140 | |
145 | - if (in_array($column, $excluded_columns)) |
|
146 | - continue; |
|
141 | + if (in_array($column, $excluded_columns)) { |
|
142 | + continue; |
|
143 | + } |
|
147 | 144 | |
148 | 145 | $values = Arrays::unique($values); |
149 | - if (count($values) == 1) |
|
150 | - $values = $values[0]; |
|
146 | + if (count($values) == 1) { |
|
147 | + $values = $values[0]; |
|
148 | + } |
|
151 | 149 | } |
152 | 150 | |
153 | 151 | return $row; |
@@ -207,8 +205,7 @@ discard block |
||
207 | 205 | $column, |
208 | 206 | ] |
209 | 207 | ); |
210 | - } |
|
211 | - else { |
|
208 | + } else { |
|
212 | 209 | // same resolution as array_merge_recursive |
213 | 210 | if (!is_array($existing_value)) { |
214 | 211 | $existing_row[$column] = [$existing_value]; |
@@ -256,14 +253,12 @@ discard block |
||
256 | 253 | ) |
257 | 254 | { |
258 | 255 | $array1[$key] = self::merge($array1[$key], $value); |
259 | - } |
|
260 | - else |
|
256 | + } else |
|
261 | 257 | { |
262 | 258 | $array1[$key] = $value; |
263 | 259 | } |
264 | 260 | } |
265 | - } |
|
266 | - else |
|
261 | + } else |
|
267 | 262 | { |
268 | 263 | foreach ($array2 as $value) |
269 | 264 | { |
@@ -288,14 +283,12 @@ discard block |
||
288 | 283 | ) |
289 | 284 | { |
290 | 285 | $array1[$key] = self::merge($array1[$key], $value); |
291 | - } |
|
292 | - else |
|
286 | + } else |
|
293 | 287 | { |
294 | 288 | $array1[$key] = $value; |
295 | 289 | } |
296 | 290 | } |
297 | - } |
|
298 | - else |
|
291 | + } else |
|
299 | 292 | { |
300 | 293 | foreach ($array2 as $value) |
301 | 294 | { |
@@ -327,21 +320,18 @@ discard block |
||
327 | 320 | foreach ($array as $key => $value) { |
328 | 321 | if (! $value instanceof MergeBucket) { |
329 | 322 | $result[ $key ] = $value; |
330 | - } |
|
331 | - else { |
|
323 | + } else { |
|
332 | 324 | foreach ($value as $sub_key => $sub_value) { |
333 | 325 | if (is_int($sub_key)) { |
334 | 326 | $result[] = $sub_value; |
335 | - } |
|
336 | - elseif (isset($result[ $sub_key ])) { |
|
327 | + } elseif (isset($result[ $sub_key ])) { |
|
337 | 328 | throw new \LogicException( |
338 | 329 | "Conflict during flatten merge for key $sub_key between: \n" |
339 | 330 | ."Existing: " . var_export($result[ $sub_key ], true) |
340 | 331 | ."\n and \n" |
341 | 332 | ."Conflict: " . var_export($sub_value, true) |
342 | 333 | ); |
343 | - } |
|
344 | - else { |
|
334 | + } else { |
|
345 | 335 | $result[ $sub_key ] = $sub_value; |
346 | 336 | } |
347 | 337 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return array The array containing the grouped rows. |
20 | 20 | */ |
21 | - public function groupBy( callable $indexGenerator, callable $conflictResolver=null ) |
|
21 | + public function groupBy(callable $indexGenerator, callable $conflictResolver = null) |
|
22 | 22 | { |
23 | 23 | // todo : this doesn't work |
24 | 24 | // return $this->groupByTransformed($indexGenerator, null, $conflictResolver); |
@@ -26,15 +26,15 @@ discard block |
||
26 | 26 | $out = []; |
27 | 27 | foreach ($this->data as $key => $row) { |
28 | 28 | |
29 | - if (!$row) |
|
29 | + if ( ! $row) |
|
30 | 30 | continue; |
31 | 31 | |
32 | 32 | $newIndexes = call_user_func($indexGenerator, $key, $row); |
33 | - if (!is_array($newIndexes)) |
|
33 | + if ( ! is_array($newIndexes)) |
|
34 | 34 | $newIndexes = [$newIndexes]; |
35 | 35 | |
36 | 36 | foreach ($newIndexes as $newIndex) { |
37 | - if (!isset($out[$newIndex])) { |
|
37 | + if ( ! isset($out[$newIndex])) { |
|
38 | 38 | $out[$newIndex] = $row; |
39 | 39 | } |
40 | 40 | else { |
@@ -69,26 +69,26 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return array The array containing the grouped rows. |
71 | 71 | */ |
72 | - public function groupInArrays( callable $indexGenerator ) |
|
72 | + public function groupInArrays(callable $indexGenerator) |
|
73 | 73 | { |
74 | 74 | $out = []; |
75 | 75 | foreach ($this->data as $key => $row) { |
76 | 76 | |
77 | - if (!$row) |
|
77 | + if ( ! $row) |
|
78 | 78 | continue; |
79 | 79 | |
80 | 80 | $new_keys = call_user_func($indexGenerator, $row, $key); |
81 | - if (!is_array($new_keys)) |
|
81 | + if ( ! is_array($new_keys)) |
|
82 | 82 | $new_keys = [$new_keys]; |
83 | 83 | |
84 | 84 | foreach ($new_keys as $new_key) { |
85 | - if (!isset($out[ $new_key ])) { |
|
86 | - $out[ $new_key ] = [ |
|
85 | + if ( ! isset($out[$new_key])) { |
|
86 | + $out[$new_key] = [ |
|
87 | 87 | $key => $row |
88 | 88 | ]; |
89 | 89 | } |
90 | 90 | else { |
91 | - $out[ $new_key ][ $key ] = $row; |
|
91 | + $out[$new_key][$key] = $row; |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function groupByTransformed( |
114 | 114 | callable $indexGenerator, |
115 | - callable $rowTransformer, // todo check this behavior |
|
115 | + callable $rowTransformer, // todo check this behavior |
|
116 | 116 | callable $conflictResolver ) |
117 | 117 | { |
118 | 118 | // The goal here is to remove the second parameter has it makes the |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | $out = []; |
126 | 126 | foreach ($this->data as $key => $row) { |
127 | 127 | |
128 | - if (!$row) |
|
128 | + if ( ! $row) |
|
129 | 129 | continue; |
130 | 130 | |
131 | 131 | $newIndex = call_user_func($indexGenerator, $key, $row); |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | ? call_user_func($rowTransformer, $row) |
135 | 135 | : $row; |
136 | 136 | |
137 | - if (!isset($out[$newIndex])) { |
|
137 | + if ( ! isset($out[$newIndex])) { |
|
138 | 138 | $out[$newIndex] = $transformedRow; |
139 | 139 | } |
140 | 140 | else { |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | * rows have the same index. |
160 | 160 | * @return static |
161 | 161 | */ |
162 | - public function mergeWith( $otherTable, callable $conflictResolver=null ) |
|
162 | + public function mergeWith($otherTable, callable $conflictResolver = null) |
|
163 | 163 | { |
164 | 164 | if (is_array($otherTable)) |
165 | 165 | $otherTable = new static($otherTable); |
166 | 166 | |
167 | - if (!$otherTable instanceof static) { |
|
167 | + if ( ! $otherTable instanceof static) { |
|
168 | 168 | self::throwUsageException( |
169 | 169 | '$otherTable must be an array or an instance of '.static::class.' instead of: ' |
170 | 170 | .var_export($otherTable, true) |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | $out = $this->data; |
175 | 175 | foreach ($otherTable->getArray() as $key => $row) { |
176 | 176 | |
177 | - if (!isset($out[$key])) { |
|
177 | + if ( ! isset($out[$key])) { |
|
178 | 178 | $out[$key] = $row; |
179 | 179 | } |
180 | 180 | else { |
181 | 181 | if ($conflictResolver === null) { |
182 | 182 | self::throwUsageException( |
183 | 183 | "No conflict resolver for a merge provoking one: $key \n\n" |
184 | - .var_export($row, true) . "\n\n" |
|
184 | + .var_export($row, true)."\n\n" |
|
185 | 185 | .var_export($out[$key], true) |
186 | 186 | ); |
187 | 187 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * (same as self::mergeWith with the other table as $this) |
208 | 208 | * @return static |
209 | 209 | */ |
210 | - public function mergeIn( $otherTable, callable $conflictResolver=null ) |
|
210 | + public function mergeIn($otherTable, callable $conflictResolver = null) |
|
211 | 211 | { |
212 | 212 | $otherTable->mergeWith($this, $conflictResolver); |
213 | 213 | return $this; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public function each(callable $rowTransformer) |
235 | 235 | { |
236 | - $out = []; |
|
236 | + $out = []; |
|
237 | 237 | foreach ($this->data as $key => $row) { |
238 | 238 | $out[$key] = call_user_func_array( |
239 | 239 | $rowTransformer, |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | */ |
264 | 264 | public function renameColumns(array $old_to_new_names) |
265 | 265 | { |
266 | - $out = []; |
|
266 | + $out = []; |
|
267 | 267 | foreach ($this->data as $key => $row) { |
268 | 268 | try { |
269 | 269 | foreach ($old_to_new_names as $old_name => $new_name) { |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | } |
273 | 273 | } |
274 | 274 | catch (\Exception $e) { |
275 | - self::throwUsageException( $e->getMessage() ); |
|
275 | + self::throwUsageException($e->getMessage()); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | $out[$key] = $row; |
@@ -324,20 +324,20 @@ discard block |
||
324 | 324 | * nor a static. |
325 | 325 | * @return static $this |
326 | 326 | */ |
327 | - public function append($new_rows, callable $conflict_resolver=null) |
|
327 | + public function append($new_rows, callable $conflict_resolver = null) |
|
328 | 328 | { |
329 | 329 | if ($new_rows instanceof static) |
330 | 330 | $new_rows = $new_rows->getArray(); |
331 | 331 | |
332 | - if (!is_array($new_rows)) { |
|
332 | + if ( ! is_array($new_rows)) { |
|
333 | 333 | $this->throwUsageException( |
334 | - "\$new_rows parameter must be an array or an instance of " . __CLASS__ |
|
334 | + "\$new_rows parameter must be an array or an instance of ".__CLASS__ |
|
335 | 335 | ); |
336 | 336 | } |
337 | 337 | |
338 | - if (!$conflict_resolver) { |
|
338 | + if ( ! $conflict_resolver) { |
|
339 | 339 | // default conflict resolver: append with numeric key |
340 | - $conflict_resolver = function (&$data, $existing_row, $confliuct_row, $key) { |
|
340 | + $conflict_resolver = function(&$data, $existing_row, $confliuct_row, $key) { |
|
341 | 341 | $data[] = $confliuct_row; |
342 | 342 | }; |
343 | 343 | } |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * |
370 | 370 | * @return static |
371 | 371 | */ |
372 | - public function dimensionsAsColumns(array $columnNames, array $options=null) |
|
372 | + public function dimensionsAsColumns(array $columnNames, array $options = null) |
|
373 | 373 | { |
374 | 374 | $out = $this->dimensionsAsColumns_recurser($this->data, $columnNames); |
375 | 375 | return $this->returnConstant($out); |
@@ -406,12 +406,12 @@ discard block |
||
406 | 406 | * ], |
407 | 407 | * ] |
408 | 408 | */ |
409 | - protected function dimensionsAsColumns_recurser(array $data, $columnNames, $rowIdParts=[]) |
|
409 | + protected function dimensionsAsColumns_recurser(array $data, $columnNames, $rowIdParts = []) |
|
410 | 410 | { |
411 | 411 | $out = []; |
412 | 412 | // if (!$columnNames) |
413 | 413 | // return $data; |
414 | - $no_more_column = !(bool) $columnNames; |
|
414 | + $no_more_column = ! (bool) $columnNames; |
|
415 | 415 | |
416 | 416 | // If all the names have been given to the dimensions |
417 | 417 | // we compile the index key of the row at the current level |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | self::throwUsageException( |
436 | 436 | "Trying to populate a column '$name' that " |
437 | 437 | ."already exists with a different value " |
438 | - .var_export($data[$name], true). " => '$value'" |
|
438 | + .var_export($data[$name], true)." => '$value'" |
|
439 | 439 | ); |
440 | 440 | } |
441 | 441 | $data[$name] = $value; |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | } |
467 | 467 | else { |
468 | 468 | |
469 | - if (!isset($rows)) { |
|
469 | + if ( ! isset($rows)) { |
|
470 | 470 | echo json_encode([ |
471 | 471 | '$rowIdParts' => $rowIdParts, |
472 | 472 | '$row' => $row, |
@@ -494,9 +494,9 @@ discard block |
||
494 | 494 | /** |
495 | 495 | * Returns the first element of the array |
496 | 496 | */ |
497 | - public function first($strict=false) |
|
497 | + public function first($strict = false) |
|
498 | 498 | { |
499 | - if (!$this->count()) { |
|
499 | + if ( ! $this->count()) { |
|
500 | 500 | if ($strict) |
501 | 501 | throw new \ErrorException("No first element found in this array"); |
502 | 502 | else |
@@ -516,9 +516,9 @@ discard block |
||
516 | 516 | * |
517 | 517 | * @todo Preserve the offset |
518 | 518 | */ |
519 | - public function last($strict=false) |
|
519 | + public function last($strict = false) |
|
520 | 520 | { |
521 | - if (!$this->count()) { |
|
521 | + if ( ! $this->count()) { |
|
522 | 522 | if ($strict) |
523 | 523 | throw new \ErrorException("No last element found in this array"); |
524 | 524 | else |
@@ -536,9 +536,9 @@ discard block |
||
536 | 536 | /** |
537 | 537 | * |
538 | 538 | */ |
539 | - public function firstKey($strict=false) |
|
539 | + public function firstKey($strict = false) |
|
540 | 540 | { |
541 | - if (!$this->count()) { |
|
541 | + if ( ! $this->count()) { |
|
542 | 542 | if ($strict) |
543 | 543 | throw new \ErrorException("No last element found in this array"); |
544 | 544 | else |
@@ -557,16 +557,16 @@ discard block |
||
557 | 557 | /** |
558 | 558 | * |
559 | 559 | */ |
560 | - public function lastKey($strict=false) |
|
560 | + public function lastKey($strict = false) |
|
561 | 561 | { |
562 | - if (!$this->count()) { |
|
562 | + if ( ! $this->count()) { |
|
563 | 563 | if ($strict) |
564 | 564 | throw new \ErrorException("No last element found in this array"); |
565 | 565 | else |
566 | 566 | $lastKey = null; |
567 | 567 | } |
568 | 568 | else { |
569 | - $key = key($this->data); |
|
569 | + $key = key($this->data); |
|
570 | 570 | end($this->data); |
571 | 571 | $lastKey = key($this->data); |
572 | 572 | $this->move($key); |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | /** |
579 | 579 | * Move the internal pointer of the array to the key given as parameter |
580 | 580 | */ |
581 | - public function move($key, $strict=true) |
|
581 | + public function move($key, $strict = true) |
|
582 | 582 | { |
583 | 583 | if (array_key_exists($key, $this->data)) { |
584 | 584 | foreach ($this->data as $i => &$value) { |
@@ -645,13 +645,13 @@ discard block |
||
645 | 645 | * @see http://php.net/manual/fr/function.var-dump.php |
646 | 646 | * @todo Handle xdebug dump formatting |
647 | 647 | */ |
648 | - public function dump($exit=false) |
|
648 | + public function dump($exit = false) |
|
649 | 649 | { |
650 | 650 | $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
651 | 651 | $caller = $bt[0]; |
652 | 652 | |
653 | 653 | var_export([ |
654 | - 'location' => $caller['file'] . ':' . $caller['line'], |
|
654 | + 'location' => $caller['file'].':'.$caller['line'], |
|
655 | 655 | 'data' => $this->data, |
656 | 656 | ]); |
657 | 657 | |
@@ -668,7 +668,7 @@ discard block |
||
668 | 668 | * @todo move it to an Arrays class storing static methods |
669 | 669 | */ |
670 | 670 | public static function replaceEntries( |
671 | - array $array, callable $replacer, $max_depth=null |
|
671 | + array $array, callable $replacer, $max_depth = null |
|
672 | 672 | ) { |
673 | 673 | foreach ($array as $key => &$row) { |
674 | 674 | $arguments = [&$row, $key]; |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | |
677 | 677 | if (is_array($row) && $max_depth !== 0) { // allowing null to have no depth limit |
678 | 678 | $row = self::replaceEntries( |
679 | - $row, $replacer, $max_depth ? $max_depth-1 : $max_depth |
|
679 | + $row, $replacer, $max_depth ? $max_depth - 1 : $max_depth |
|
680 | 680 | ); |
681 | 681 | } |
682 | 682 | } |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | * |
693 | 693 | * @return static $this or a new static. |
694 | 694 | */ |
695 | - public function extract($callback=null) |
|
695 | + public function extract($callback = null) |
|
696 | 696 | { |
697 | 697 | if ($callback) { |
698 | 698 | |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | $callback = new \JClaveau\LogicalFilter\LogicalFilter($callback); |
701 | 701 | } |
702 | 702 | |
703 | - if (!is_callable($callback)) { |
|
703 | + if ( ! is_callable($callback)) { |
|
704 | 704 | $this->throwUsageException( |
705 | 705 | "\$callback must be a logical filter description array or a callable" |
706 | 706 | ." instead of " |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | foreach ($this->data as $key => $value) { |
713 | 713 | if ($callback($value, $key)) { |
714 | 714 | $out[$key] = $value; |
715 | - unset( $this->data[$key] ); |
|
715 | + unset($this->data[$key]); |
|
716 | 716 | } |
717 | 717 | } |
718 | 718 | } |
@@ -728,23 +728,23 @@ discard block |
||
728 | 728 | $result = []; |
729 | 729 | foreach ($this->data as $key => $value) { |
730 | 730 | if ( ! Arrays::isTraversable($value)) { |
731 | - $result[ $key ] = $value; |
|
731 | + $result[$key] = $value; |
|
732 | 732 | } |
733 | 733 | else { |
734 | 734 | foreach ($value as $sub_key => $sub_value) { |
735 | 735 | if (is_int($sub_key)) { |
736 | 736 | $result[] = $sub_value; |
737 | 737 | } |
738 | - elseif (isset($result[ $sub_key ])) { |
|
738 | + elseif (isset($result[$sub_key])) { |
|
739 | 739 | throw new \LogicException( |
740 | 740 | "Conflict during flatten merge for key $sub_key between: \n" |
741 | - ."Existing: " . var_export($result[ $sub_key ], true) |
|
741 | + ."Existing: ".var_export($result[$sub_key], true) |
|
742 | 742 | ."\n and \n" |
743 | - ."Conflict: " . var_export($sub_value, true) |
|
743 | + ."Conflict: ".var_export($sub_value, true) |
|
744 | 744 | ); |
745 | 745 | } |
746 | 746 | else { |
747 | - $result[ $sub_key ] = $sub_value; |
|
747 | + $result[$sub_key] = $sub_value; |
|
748 | 748 | } |
749 | 749 | } |
750 | 750 | } |
@@ -26,18 +26,19 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -729,21 +732,18 @@ discard block |
||
729 | 732 | foreach ($this->data as $key => $value) { |
730 | 733 | if ( ! Arrays::isTraversable($value)) { |
731 | 734 | $result[ $key ] = $value; |
732 | - } |
|
733 | - else { |
|
735 | + } else { |
|
734 | 736 | foreach ($value as $sub_key => $sub_value) { |
735 | 737 | if (is_int($sub_key)) { |
736 | 738 | $result[] = $sub_value; |
737 | - } |
|
738 | - elseif (isset($result[ $sub_key ])) { |
|
739 | + } elseif (isset($result[ $sub_key ])) { |
|
739 | 740 | throw new \LogicException( |
740 | 741 | "Conflict during flatten merge for key $sub_key between: \n" |
741 | 742 | ."Existing: " . var_export($result[ $sub_key ], true) |
742 | 743 | ."\n and \n" |
743 | 744 | ."Conflict: " . var_export($sub_value, true) |
744 | 745 | ); |
745 | - } |
|
746 | - else { |
|
746 | + } else { |
|
747 | 747 | $result[ $sub_key ] = $sub_value; |
748 | 748 | } |
749 | 749 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | elseif (is_object($value)) { |
118 | 118 | if ( ! method_exists($value, 'toNumber')) { |
119 | 119 | throw new \InvalidArgumentEXception( |
120 | - "Trying to sum a ".get_class($value)." object which cannot be casted as a number. " |
|
120 | + "Trying to sum a ".get_class($value)." object which cannot be casted as a number. " |
|
121 | 121 | ."Please add a toNumber() method." |
122 | 122 | ); |
123 | 123 | } |
@@ -301,12 +301,12 @@ discard block |
||
301 | 301 | $key_value_separator = ! empty($options['key_value_separator']) |
302 | 302 | ? $options['key_value_separator'] |
303 | 303 | : ':' |
304 | - ; |
|
304 | + ; |
|
305 | 305 | |
306 | 306 | $groups_separator = ! empty($options['groups_separator']) |
307 | 307 | ? $options['groups_separator'] |
308 | 308 | : '-' |
309 | - ; |
|
309 | + ; |
|
310 | 310 | |
311 | 311 | $group_parts = []; |
312 | 312 | foreach ($groups_definitions as $group_definition_key => $group_definition_value) { |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | foreach ($group_parts as $group_name => $group_value) { |
383 | 383 | if (is_object($group_value)) { |
384 | 384 | $group_value = get_class($group_value) |
385 | - . '_' |
|
386 | - . hash( 'crc32b', var_export($group_value, true) ); |
|
385 | + . '_' |
|
386 | + . hash( 'crc32b', var_export($group_value, true) ); |
|
387 | 387 | } |
388 | 388 | elseif (is_array($group_value)) { |
389 | 389 | $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) ); |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | $id = serialize($value); |
56 | 56 | } |
57 | 57 | |
58 | - if (isset($ids[ $id ])) { |
|
59 | - unset($array[ $key ]); |
|
60 | - $ids[ $id ][] = $key; |
|
58 | + if (isset($ids[$id])) { |
|
59 | + unset($array[$key]); |
|
60 | + $ids[$id][] = $key; |
|
61 | 61 | continue; |
62 | 62 | } |
63 | 63 | |
64 | - $ids[ $id ] = [$key]; |
|
64 | + $ids[$id] = [$key]; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | return $array; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | } |
82 | 82 | else { |
83 | 83 | throw new \InvalidArgumentException( |
84 | - "keyExists() method missing on :\n". var_export($array, true) |
|
84 | + "keyExists() method missing on :\n".var_export($array, true) |
|
85 | 85 | ); |
86 | 86 | } |
87 | 87 | |
@@ -157,16 +157,16 @@ discard block |
||
157 | 157 | throw new \InvalidArgumentException( |
158 | 158 | "Different number of " |
159 | 159 | ." values and weights for weight mean calculation: \n" |
160 | - .var_export($values, true)."\n\n" |
|
160 | + .var_export($values, true)."\n\n" |
|
161 | 161 | .var_export($weights, true) |
162 | 162 | ); |
163 | 163 | } |
164 | 164 | |
165 | - if (!$values) |
|
165 | + if ( ! $values) |
|
166 | 166 | return null; |
167 | 167 | |
168 | - $weights_sum = array_sum($weights); |
|
169 | - if (!$weights_sum) |
|
168 | + $weights_sum = array_sum($weights); |
|
169 | + if ( ! $weights_sum) |
|
170 | 170 | return 0; |
171 | 171 | |
172 | 172 | $weighted_sum = 0; |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | ); |
216 | 216 | |
217 | 217 | // The true location of the throw is still available through the backtrace |
218 | - $trace_location = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; |
|
219 | - $reflectionClass = new \ReflectionClass( get_class($exception) ); |
|
218 | + $trace_location = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; |
|
219 | + $reflectionClass = new \ReflectionClass(get_class($exception)); |
|
220 | 220 | |
221 | 221 | // file |
222 | 222 | if (isset($trace_location['file'])) { |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | ); |
254 | 254 | |
255 | 255 | // The true location of the throw is still available through the backtrace |
256 | - $trace_location = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; |
|
257 | - $reflectionClass = new \ReflectionClass( get_class($exception) ); |
|
256 | + $trace_location = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; |
|
257 | + $reflectionClass = new \ReflectionClass(get_class($exception)); |
|
258 | 258 | |
259 | 259 | // file |
260 | 260 | if (isset($trace_location['file'])) { |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * |
295 | 295 | * @return string The unique identifier of the group |
296 | 296 | */ |
297 | - public static function generateGroupId($row, array $groups_definitions, array $options=[]) |
|
297 | + public static function generateGroupId($row, array $groups_definitions, array $options = []) |
|
298 | 298 | { |
299 | 299 | Arrays::mustBeCountable($row); |
300 | 300 | |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | : ':' |
304 | 304 | ; |
305 | 305 | |
306 | - $groups_separator = ! empty($options['groups_separator']) |
|
306 | + $groups_separator = ! empty($options['groups_separator']) |
|
307 | 307 | ? $options['groups_separator'] |
308 | 308 | : '-' |
309 | 309 | ; |
@@ -317,32 +317,32 @@ discard block |
||
317 | 317 | } |
318 | 318 | |
319 | 319 | if (is_string($group_definition_value)) { |
320 | - if ( (is_array($row) && ! array_key_exists($group_definition_value, $row)) |
|
320 | + if ((is_array($row) && ! array_key_exists($group_definition_value, $row)) |
|
321 | 321 | || ($row instanceof \ArrayAcces && ! $row->offsetExists($group_definition_value)) |
322 | 322 | ) { |
323 | 323 | throw new UsageException( |
324 | 324 | 'Unset column for group id generation: ' |
325 | 325 | .var_export($group_definition_value, true) |
326 | - ."\n" . var_export($row, true) |
|
326 | + ."\n".var_export($row, true) |
|
327 | 327 | ); |
328 | 328 | } |
329 | 329 | |
330 | 330 | $part_name .= $group_definition_value; |
331 | - $group_result_value = $row[ $group_definition_value ]; |
|
331 | + $group_result_value = $row[$group_definition_value]; |
|
332 | 332 | } |
333 | 333 | elseif (is_int($group_definition_value)) { |
334 | - if ( (is_array($row) && ! array_key_exists($group_definition_value, $row)) |
|
334 | + if ((is_array($row) && ! array_key_exists($group_definition_value, $row)) |
|
335 | 335 | || ($row instanceof \ArrayAcces && ! $row->offsetExists($group_definition_value)) |
336 | 336 | ) { |
337 | 337 | throw new UsageException( |
338 | 338 | 'Unset column for group id generation: ' |
339 | 339 | .var_export($group_definition_value, true) |
340 | - ."\n" . var_export($row, true) |
|
340 | + ."\n".var_export($row, true) |
|
341 | 341 | ); |
342 | 342 | } |
343 | 343 | |
344 | - $part_name .= $group_definition_value ? : '0'; |
|
345 | - $group_result_value = $row[ $group_definition_value ]; |
|
344 | + $part_name .= $group_definition_value ?: '0'; |
|
345 | + $group_result_value = $row[$group_definition_value]; |
|
346 | 346 | } |
347 | 347 | elseif (is_callable($group_definition_value)) { |
348 | 348 | |
@@ -366,12 +366,12 @@ discard block |
||
366 | 366 | throw new UsageException( |
367 | 367 | 'Bad value provided for group id generation: ' |
368 | 368 | .var_export($group_definition_value, true) |
369 | - ."\n" . var_export($row, true) |
|
369 | + ."\n".var_export($row, true) |
|
370 | 370 | ); |
371 | 371 | } |
372 | 372 | |
373 | - if (!is_null($part_name)) |
|
374 | - $group_parts[ $part_name ] = $group_result_value; |
|
373 | + if ( ! is_null($part_name)) |
|
374 | + $group_parts[$part_name] = $group_result_value; |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | // sort the groups by names (without it the same group could have multiple ids) |
@@ -383,13 +383,13 @@ discard block |
||
383 | 383 | if (is_object($group_value)) { |
384 | 384 | $group_value = get_class($group_value) |
385 | 385 | . '_' |
386 | - . hash( 'crc32b', var_export($group_value, true) ); |
|
386 | + . hash('crc32b', var_export($group_value, true)); |
|
387 | 387 | } |
388 | 388 | elseif (is_array($group_value)) { |
389 | - $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) ); |
|
389 | + $group_value = 'array_'.hash('crc32b', var_export($group_value, true)); |
|
390 | 390 | } |
391 | 391 | |
392 | - $out[] = $group_name . $key_value_separator . $group_value; |
|
392 | + $out[] = $group_name.$key_value_separator.$group_value; |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | return implode($groups_separator, $out); |
@@ -50,8 +50,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |