@@ -12,7 +12,7 @@ |
||
12 | 12 | public function reduceIfUnique() |
13 | 13 | { |
14 | 14 | if ($this->unique()->count() == 1) |
15 | - return reset( $this->data ); |
|
15 | + return reset($this->data); |
|
16 | 16 | } |
17 | 17 | /**/ |
18 | 18 | } |
@@ -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 | } |