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