@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | * |
| 248 | 248 | * This helpes to ease the result of simplify() |
| 249 | 249 | * |
| 250 | - * @return OrRule |
|
| 250 | + * @return LogicalFilter |
|
| 251 | 251 | */ |
| 252 | 252 | public function addMinimalCase() |
| 253 | 253 | { |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * |
| 303 | 303 | * @param $debug Provides a source oriented dump. |
| 304 | 304 | * |
| 305 | - * @return array A description of the rules. |
|
| 305 | + * @return string A description of the rules. |
|
| 306 | 306 | */ |
| 307 | 307 | public function toString(array $options=[]) |
| 308 | 308 | { |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | * @param array|callable Associative array of renamings or callable |
| 378 | 378 | * that would rename the fields. |
| 379 | 379 | * |
| 380 | - * @return string $this |
|
| 380 | + * @return LogicalFilter $this |
|
| 381 | 381 | */ |
| 382 | 382 | public function removeRules($filter) |
| 383 | 383 | { |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | * @param array|LogicalFilter|AbstractRule $rules |
| 423 | 423 | * @param array|callable $options |
| 424 | 424 | * |
| 425 | - * @return array The rules matching the filter |
|
| 425 | + * @return LogicalFilter The rules matching the filter |
|
| 426 | 426 | */ |
| 427 | 427 | public function filterRules($rules=[], array $options=[]) |
| 428 | 428 | { |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | * @param array|callable Associative array of renamings or callable |
| 450 | 450 | * that would rename the fields. |
| 451 | 451 | * |
| 452 | - * @return array The rules matching the filter |
|
| 453 | - * @return array $options debug | leaves_only | clean_empty_branches |
|
| 452 | + * @return LogicalFilter The rules matching the filter |
|
| 453 | + * @return LogicalFilter $options debug | leaves_only | clean_empty_branches |
|
| 454 | 454 | */ |
| 455 | 455 | public function keepLeafRulesMatching($filter=[], array $options=[]) |
| 456 | 456 | { |
@@ -558,6 +558,7 @@ discard block |
||
| 558 | 558 | * @param array|LogicalFilter |
| 559 | 559 | * @param array|callable Associative array of renamings or callable |
| 560 | 560 | * that would rename the fields. |
| 561 | + * @param \Closure $options |
|
| 561 | 562 | * |
| 562 | 563 | * @return array The rules matching the filter |
| 563 | 564 | */ |
@@ -744,7 +745,6 @@ discard block |
||
| 744 | 745 | } |
| 745 | 746 | |
| 746 | 747 | /** |
| 747 | - * @param bool $exit=false |
|
| 748 | 748 | * @param array $options + callstack_depth=2 The level of the caller to dump |
| 749 | 749 | * + mode='string' in 'export' | 'dump' | 'string' |
| 750 | 750 | * |
@@ -839,10 +839,9 @@ discard block |
||
| 839 | 839 | * Applies the current instance to a value (and its index optionnally). |
| 840 | 840 | * |
| 841 | 841 | * @param mixed $value_to_check |
| 842 | - * @param scalar $index |
|
| 843 | 842 | * @param Filterer|callable|null $filterer |
| 844 | 843 | * |
| 845 | - * @return AbstractRule|false|true + False if the filter doesn't validates |
|
| 844 | + * @return boolean + False if the filter doesn't validates |
|
| 846 | 845 | * + Null if the target has no sens (operation filtered by field for example) |
| 847 | 846 | * + A rule tree containing the first matching case if there is one. |
| 848 | 847 | */ |
@@ -8,7 +8,6 @@ |
||
| 8 | 8 | namespace JClaveau\LogicalFilter; |
| 9 | 9 | |
| 10 | 10 | use JClaveau\LogicalFilter\Rule\AbstractRule; |
| 11 | -use JClaveau\LogicalFilter\Rule\AbstractOperationRule; |
|
| 12 | 11 | use JClaveau\LogicalFilter\Rule\AndRule; |
| 13 | 12 | use JClaveau\LogicalFilter\Rule\OrRule; |
| 14 | 13 | use JClaveau\LogicalFilter\Rule\NotRule; |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | unset( $rows[$key] ); |
| 393 | 393 | if (! $rows ) { |
| 394 | 394 | throw new \Exception( |
| 395 | - "Removing the only rule $rule from the filter $this " |
|
| 395 | + "Removing the only rule $rule from the filter $this " |
|
| 396 | 396 | ."produces a case which has no possible solution due to missing " |
| 397 | 397 | ."implementation of TrueRule.\n" |
| 398 | 398 | ."Please see: https://github.com/jclaveau/php-logical-filter/issues/59" |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | } |
| 822 | 822 | elseif (! $filterer instanceof Filterer) { |
| 823 | 823 | throw new \InvalidArgumentException( |
| 824 | - "The given \$filterer must be null or a callable or a instance " |
|
| 824 | + "The given \$filterer must be null or a callable or a instance " |
|
| 825 | 825 | ."of Filterer instead of: ".var_export($filterer, true) |
| 826 | 826 | ); |
| 827 | 827 | } |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | } |
| 857 | 857 | elseif (! $filterer instanceof Filterer) { |
| 858 | 858 | throw new \InvalidArgumentException( |
| 859 | - "The given \$filterer must be null or a callable or a instance " |
|
| 859 | + "The given \$filterer must be null or a callable or a instance " |
|
| 860 | 860 | ."of Filterer instead of: ".var_export($filterer, true) |
| 861 | 861 | ); |
| 862 | 862 | } |
@@ -51,12 +51,12 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @see self::addRules |
| 53 | 53 | */ |
| 54 | - public function __construct($rules=[], Filterer $default_filterer=null, array $options=[]) |
|
| 54 | + public function __construct($rules = [], Filterer $default_filterer = null, array $options = []) |
|
| 55 | 55 | { |
| 56 | 56 | if ($rules instanceof AbstractRule) { |
| 57 | 57 | $rules = $rules->copy(); |
| 58 | 58 | } |
| 59 | - elseif (! is_null($rules) && ! is_array($rules)) { |
|
| 59 | + elseif ( ! is_null($rules) && ! is_array($rules)) { |
|
| 60 | 60 | throw new \InvalidArgumentException( |
| 61 | 61 | "\$rules must be a rules description or an AbstractRule instead of" |
| 62 | 62 | .var_export($rules, true) |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | if ($rules) { |
| 75 | - $this->and_( $rules ); |
|
| 75 | + $this->and_($rules); |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | protected function getDefaultFilterer() |
| 82 | 82 | { |
| 83 | - if (! $this->default_filterer) { |
|
| 83 | + if ( ! $this->default_filterer) { |
|
| 84 | 84 | $this->default_filterer = new PhpFilterer(); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -223,12 +223,12 @@ discard block |
||
| 223 | 223 | * @param array $options stop_after | stop_before | |
| 224 | 224 | * @return $this |
| 225 | 225 | */ |
| 226 | - public function simplify($options=[]) |
|
| 226 | + public function simplify($options = []) |
|
| 227 | 227 | { |
| 228 | 228 | if ($this->rules) { |
| 229 | 229 | // AndRule added to make all Operation methods available |
| 230 | 230 | $this->rules = (new AndRule([$this->rules])) |
| 231 | - ->simplify( $options ) |
|
| 231 | + ->simplify($options) |
|
| 232 | 232 | // ->dump(true, false) |
| 233 | 233 | ; |
| 234 | 234 | } |
@@ -271,9 +271,9 @@ discard block |
||
| 271 | 271 | * |
| 272 | 272 | * @return bool |
| 273 | 273 | */ |
| 274 | - public function hasSolution($save_simplification=true) |
|
| 274 | + public function hasSolution($save_simplification = true) |
|
| 275 | 275 | { |
| 276 | - if (! $this->rules) { |
|
| 276 | + if ( ! $this->rules) { |
|
| 277 | 277 | return true; |
| 278 | 278 | } |
| 279 | 279 | |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | * |
| 293 | 293 | * @return array A description of the rules. |
| 294 | 294 | */ |
| 295 | - public function toArray(array $options=[]) |
|
| 295 | + public function toArray(array $options = []) |
|
| 296 | 296 | { |
| 297 | 297 | return $this->rules ? $this->rules->toArray($options) : $this->rules; |
| 298 | 298 | } |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | * |
| 305 | 305 | * @return array A description of the rules. |
| 306 | 306 | */ |
| 307 | - public function toString(array $options=[]) |
|
| 307 | + public function toString(array $options = []) |
|
| 308 | 308 | { |
| 309 | 309 | return $this->rules ? $this->rules->toString($options) : $this->rules; |
| 310 | 310 | } |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | * @param mixed $row |
| 343 | 343 | * @return bool |
| 344 | 344 | */ |
| 345 | - public function __invoke($row, $key=null) |
|
| 345 | + public function __invoke($row, $key = null) |
|
| 346 | 346 | { |
| 347 | 347 | return $this->validates($row, $key); |
| 348 | 348 | } |
@@ -389,8 +389,8 @@ discard block |
||
| 389 | 389 | [ |
| 390 | 390 | Filterer::on_row_matches => function($rule, $key, &$rows, $matching_case) use (&$cache_flush_required) { |
| 391 | 391 | // $rule->dump(); |
| 392 | - unset( $rows[$key] ); |
|
| 393 | - if (! $rows ) { |
|
| 392 | + unset($rows[$key]); |
|
| 393 | + if ( ! $rows) { |
|
| 394 | 394 | throw new \Exception( |
| 395 | 395 | "Removing the only rule $rule from the filter $this " |
| 396 | 396 | ."produces a case which has no possible solution due to missing " |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * |
| 425 | 425 | * @return array The rules matching the filter |
| 426 | 426 | */ |
| 427 | - public function filterRules($rules=[], array $options=[]) |
|
| 427 | + public function filterRules($rules = [], array $options = []) |
|
| 428 | 428 | { |
| 429 | 429 | if ($rules instanceof LogicalFilter) { |
| 430 | 430 | $rules = $rules->getRules(); |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | * @return array The rules matching the filter |
| 453 | 453 | * @return array $options debug | leaves_only | clean_empty_branches |
| 454 | 454 | */ |
| 455 | - public function keepLeafRulesMatching($filter=[], array $options=[]) |
|
| 455 | + public function keepLeafRulesMatching($filter = [], array $options = []) |
|
| 456 | 456 | { |
| 457 | 457 | $clean_empty_branches = ! isset($options['clean_empty_branches']) || $options['clean_empty_branches']; |
| 458 | 458 | |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | // ->dump() |
| 461 | 461 | ; |
| 462 | 462 | |
| 463 | - $options[ Filterer::leaves_only ] = true; |
|
| 463 | + $options[Filterer::leaves_only] = true; |
|
| 464 | 464 | |
| 465 | 465 | $this->rules = (new RuleFilterer)->apply($filter, $this->rules, $options); |
| 466 | 466 | // $this->rules->dump(true); |
@@ -500,13 +500,13 @@ discard block |
||
| 500 | 500 | * |
| 501 | 501 | * @todo Merge with rules |
| 502 | 502 | */ |
| 503 | - public function listLeafRulesMatching($filter=[]) |
|
| 503 | + public function listLeafRulesMatching($filter = []) |
|
| 504 | 504 | { |
| 505 | 505 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
| 506 | 506 | // ->dump() |
| 507 | 507 | ; |
| 508 | 508 | |
| 509 | - if (! $this->rules) { |
|
| 509 | + if ( ! $this->rules) { |
|
| 510 | 510 | return []; |
| 511 | 511 | } |
| 512 | 512 | |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | $key, |
| 521 | 521 | array $siblings |
| 522 | 522 | ) use (&$out) { |
| 523 | - if ( ! $matching_rule instanceof AndRule |
|
| 523 | + if ( ! $matching_rule instanceof AndRule |
|
| 524 | 524 | && ! $matching_rule instanceof OrRule |
| 525 | 525 | && ! $matching_rule instanceof NotRule |
| 526 | 526 | ) { |
@@ -561,13 +561,13 @@ discard block |
||
| 561 | 561 | * |
| 562 | 562 | * @return array The rules matching the filter |
| 563 | 563 | */ |
| 564 | - public function onEachRule($filter=[], $options) |
|
| 564 | + public function onEachRule($filter = [], $options) |
|
| 565 | 565 | { |
| 566 | 566 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
| 567 | 567 | // ->dump() |
| 568 | 568 | ; |
| 569 | 569 | |
| 570 | - if (! $this->rules) { |
|
| 570 | + if ( ! $this->rules) { |
|
| 571 | 571 | return []; |
| 572 | 572 | } |
| 573 | 573 | |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | { |
| 601 | 601 | $this->simplify()->addMinimalCase(); |
| 602 | 602 | |
| 603 | - if (! $this->rules) { |
|
| 603 | + if ( ! $this->rules) { |
|
| 604 | 604 | return $this; |
| 605 | 605 | } |
| 606 | 606 | |
@@ -626,11 +626,11 @@ discard block |
||
| 626 | 626 | * |
| 627 | 627 | * @return array The bounds of the range and a nullable property for each field |
| 628 | 628 | */ |
| 629 | - public function getRanges($ruleFilter=null) |
|
| 629 | + public function getRanges($ruleFilter = null) |
|
| 630 | 630 | { |
| 631 | 631 | $ranges = []; |
| 632 | 632 | |
| 633 | - $this->onEachCase(function (AndRule $and_rule) use (&$ranges, $ruleFilter) { |
|
| 633 | + $this->onEachCase(function(AndRule $and_rule) use (&$ranges, $ruleFilter) { |
|
| 634 | 634 | (new self($and_rule))->onEachRule( |
| 635 | 635 | ['and', |
| 636 | 636 | $ruleFilter, |
@@ -639,12 +639,12 @@ discard block |
||
| 639 | 639 | '><', '><=', '=><=', '=><', |
| 640 | 640 | ]], |
| 641 | 641 | ], |
| 642 | - function ($rule) use (&$ranges) { |
|
| 642 | + function($rule) use (&$ranges) { |
|
| 643 | 643 | |
| 644 | 644 | $field = $rule->getField(); |
| 645 | 645 | |
| 646 | - $range = isset($ranges[ $field ]) |
|
| 647 | - ? $ranges[ $field ] |
|
| 646 | + $range = isset($ranges[$field]) |
|
| 647 | + ? $ranges[$field] |
|
| 648 | 648 | : ['min' => [], 'max' => [], 'nullable' => false]; |
| 649 | 649 | |
| 650 | 650 | if ($rule::operator == '=') { |
@@ -672,7 +672,7 @@ discard block |
||
| 672 | 672 | ); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - $ranges[ $field ] = $range; |
|
| 675 | + $ranges[$field] = $range; |
|
| 676 | 676 | } |
| 677 | 677 | ); |
| 678 | 678 | }); |
@@ -726,7 +726,7 @@ discard block |
||
| 726 | 726 | * |
| 727 | 727 | * @return LogicalFilter |
| 728 | 728 | */ |
| 729 | - public function saveAs( &$variable) |
|
| 729 | + public function saveAs(&$variable) |
|
| 730 | 730 | { |
| 731 | 731 | return $variable = $this; |
| 732 | 732 | } |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | * |
| 738 | 738 | * @return LogicalFilter |
| 739 | 739 | */ |
| 740 | - public function saveCopyAs( &$copied_variable) |
|
| 740 | + public function saveCopyAs(&$copied_variable) |
|
| 741 | 741 | { |
| 742 | 742 | $copied_variable = $this->copy(); |
| 743 | 743 | return $this; |
@@ -750,15 +750,15 @@ discard block |
||
| 750 | 750 | * |
| 751 | 751 | * @return $this |
| 752 | 752 | */ |
| 753 | - public function dump($exit=false, array $options=[]) |
|
| 753 | + public function dump($exit = false, array $options = []) |
|
| 754 | 754 | { |
| 755 | 755 | $default_options = [ |
| 756 | 756 | 'callstack_depth' => 3, |
| 757 | 757 | 'mode' => 'string', |
| 758 | 758 | ]; |
| 759 | 759 | foreach ($default_options as $default_option => &$default_value) { |
| 760 | - if (! isset($options[ $default_option ])) { |
|
| 761 | - $options[ $default_option ] = $default_value; |
|
| 760 | + if ( ! isset($options[$default_option])) { |
|
| 761 | + $options[$default_option] = $default_value; |
|
| 762 | 762 | } |
| 763 | 763 | } |
| 764 | 764 | extract($options); |
@@ -769,24 +769,24 @@ discard block |
||
| 769 | 769 | else { |
| 770 | 770 | // TODO dump a TrueRule |
| 771 | 771 | $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth); |
| 772 | - $caller = $bt[ $callstack_depth - 2 ]; |
|
| 772 | + $caller = $bt[$callstack_depth - 2]; |
|
| 773 | 773 | |
| 774 | 774 | // get line and file from the previous level of the caller |
| 775 | 775 | // TODO go deeper if this case exist? |
| 776 | - if (! isset($caller['file'])) { |
|
| 777 | - $caller['file'] = $bt[ $callstack_depth - 3 ]['file']; |
|
| 776 | + if ( ! isset($caller['file'])) { |
|
| 777 | + $caller['file'] = $bt[$callstack_depth - 3]['file']; |
|
| 778 | 778 | } |
| 779 | 779 | |
| 780 | - if (! isset($caller['line'])) { |
|
| 781 | - $caller['line'] = $bt[ $callstack_depth - 3 ]['line']; |
|
| 780 | + if ( ! isset($caller['line'])) { |
|
| 781 | + $caller['line'] = $bt[$callstack_depth - 3]['line']; |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | try { |
| 785 | - echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n"; |
|
| 785 | + echo "\n".$caller['file'].':'.$caller['line']."\n"; |
|
| 786 | 786 | var_export($this->toArray($options)); |
| 787 | 787 | } |
| 788 | 788 | catch (\Exception $e) { |
| 789 | - echo "\nError while dumping: " . $e->getMessage() . "\n"; |
|
| 789 | + echo "\nError while dumping: ".$e->getMessage()."\n"; |
|
| 790 | 790 | var_export($caller); |
| 791 | 791 | echo "\n\n"; |
| 792 | 792 | var_export($bt); |
@@ -811,15 +811,15 @@ discard block |
||
| 811 | 811 | * |
| 812 | 812 | * @return mixed The filtered data |
| 813 | 813 | */ |
| 814 | - public function applyOn($data_to_filter, $action_on_matches=null, $filterer=null) |
|
| 814 | + public function applyOn($data_to_filter, $action_on_matches = null, $filterer = null) |
|
| 815 | 815 | { |
| 816 | - if (! $filterer) { |
|
| 816 | + if ( ! $filterer) { |
|
| 817 | 817 | $filterer = $this->getDefaultFilterer(); |
| 818 | 818 | } |
| 819 | 819 | elseif (is_callable($filterer)) { |
| 820 | 820 | $filterer = new CustomizableFilterer($filterer); |
| 821 | 821 | } |
| 822 | - elseif (! $filterer instanceof Filterer) { |
|
| 822 | + elseif ( ! $filterer instanceof Filterer) { |
|
| 823 | 823 | throw new \InvalidArgumentException( |
| 824 | 824 | "The given \$filterer must be null or a callable or a instance " |
| 825 | 825 | ."of Filterer instead of: ".var_export($filterer, true) |
@@ -846,15 +846,15 @@ discard block |
||
| 846 | 846 | * + Null if the target has no sens (operation filtered by field for example) |
| 847 | 847 | * + A rule tree containing the first matching case if there is one. |
| 848 | 848 | */ |
| 849 | - public function validates($value_to_check, $key_to_check=null, $filterer=null) |
|
| 849 | + public function validates($value_to_check, $key_to_check = null, $filterer = null) |
|
| 850 | 850 | { |
| 851 | - if (! $filterer) { |
|
| 851 | + if ( ! $filterer) { |
|
| 852 | 852 | $filterer = $this->getDefaultFilterer(); |
| 853 | 853 | } |
| 854 | 854 | elseif (is_callable($filterer)) { |
| 855 | 855 | $filterer = new CustomizableFilterer($filterer); |
| 856 | 856 | } |
| 857 | - elseif (! $filterer instanceof Filterer) { |
|
| 857 | + elseif ( ! $filterer instanceof Filterer) { |
|
| 858 | 858 | throw new \InvalidArgumentException( |
| 859 | 859 | "The given \$filterer must be null or a callable or a instance " |
| 860 | 860 | ."of Filterer instead of: ".var_export($filterer, true) |
@@ -148,7 +148,7 @@ |
||
| 148 | 148 | if ($filter_rules && in_array( get_class($filter_rules), [AndRule::class, OrRule::class]) |
| 149 | 149 | && ! $filter_rules->getOperands()) { |
| 150 | 150 | throw new \LogicException( |
| 151 | - "You are trying to add rules to a LogicalFilter which had " |
|
| 151 | + "You are trying to add rules to a LogicalFilter which had " |
|
| 152 | 152 | ."only contradictory rules that have already been simplified: " |
| 153 | 153 | .$filter_rules |
| 154 | 154 | ); |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if ( 3 == count($rules_description) |
|
| 73 | + if (3 == count($rules_description) |
|
| 74 | 74 | && is_string($rules_description[0]) |
| 75 | 75 | && is_string($rules_description[1]) |
| 76 | 76 | ) { |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | elseif (count($rules_description) == count(array_filter($rules_description, function($arg) { |
| 88 | 88 | return $arg instanceof LogicalFilter; |
| 89 | - })) ) { |
|
| 89 | + }))) { |
|
| 90 | 90 | // Already instanciated rules |
| 91 | 91 | foreach ($rules_description as $i => $filter_inside_description) { |
| 92 | 92 | $rules = $filter_inside_description->getRules(); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | elseif (count($rules_description) == count(array_filter($rules_description, function($arg) { |
| 99 | 99 | return $arg instanceof AbstractRule; |
| 100 | - })) ) { |
|
| 100 | + }))) { |
|
| 101 | 101 | // Already instanciated rules |
| 102 | 102 | foreach ($rules_description as $i => $new_rule) { |
| 103 | 103 | $filter_rules = static::addRule($new_rule, $operation, $filter_rules); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | elseif (1 == count($rules_description) && is_array($rules_description[0])) { |
| 107 | 107 | if (count($rules_description[0]) == count(array_filter($rules_description[0], function($arg) { |
| 108 | 108 | return $arg instanceof AbstractRule; |
| 109 | - })) ) { |
|
| 109 | + }))) { |
|
| 110 | 110 | // Case of $filter->or_([AbstractRule, AbstractRule, AbstractRule, ...]) |
| 111 | 111 | foreach ($rules_description[0] as $i => $new_rule) { |
| 112 | 112 | $filter_rules = static::addRule($new_rule, $operation, $filter_rules); |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | * |
| 143 | 143 | * @return $filter_rules The updated rule tree of the filter |
| 144 | 144 | */ |
| 145 | - protected static function addRule( AbstractRule $rule, $operation=AndRule::operator, AbstractRule $filter_rules=null) |
|
| 145 | + protected static function addRule(AbstractRule $rule, $operation = AndRule::operator, AbstractRule $filter_rules = null) |
|
| 146 | 146 | { |
| 147 | 147 | |
| 148 | - if ($filter_rules && in_array( get_class($filter_rules), [AndRule::class, OrRule::class]) |
|
| 148 | + if ($filter_rules && in_array(get_class($filter_rules), [AndRule::class, OrRule::class]) |
|
| 149 | 149 | && ! $filter_rules->getOperands()) { |
| 150 | 150 | throw new \LogicException( |
| 151 | 151 | "You are trying to add rules to a LogicalFilter which had " |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | AbstractOperationRule $recursion_position, |
| 195 | 195 | $options |
| 196 | 196 | ) { |
| 197 | - if (! array_filter($rules_composition, function ($rule_composition_part) { |
|
| 197 | + if ( ! array_filter($rules_composition, function($rule_composition_part) { |
|
| 198 | 198 | return is_string($rule_composition_part); |
| 199 | 199 | })) { |
| 200 | 200 | // at least one operator is required for operation rules |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | .var_export($rules_composition, true) |
| 204 | 204 | ); |
| 205 | 205 | } |
| 206 | - elseif ( 3 == count($rules_composition) |
|
| 206 | + elseif (3 == count($rules_composition) |
|
| 207 | 207 | && AbstractRule::isLeftOperand($rules_composition[0]) |
| 208 | 208 | && AbstractRule::isOperator($rules_composition[1]) |
| 209 | 209 | ) { |
@@ -219,16 +219,16 @@ discard block |
||
| 219 | 219 | } |
| 220 | 220 | else { |
| 221 | 221 | // operations |
| 222 | - if ( NotRule::operator == $rules_composition[0] |
|
| 223 | - || $rules_composition[0] == AbstractRule::findSymbolicOperator( NotRule::operator ) ) { |
|
| 222 | + if (NotRule::operator == $rules_composition[0] |
|
| 223 | + || $rules_composition[0] == AbstractRule::findSymbolicOperator(NotRule::operator)) { |
|
| 224 | 224 | $rule = new NotRule(); |
| 225 | 225 | } |
| 226 | - elseif (in_array( AndRule::operator, $rules_composition ) |
|
| 227 | - || in_array( AbstractRule::findSymbolicOperator( AndRule::operator ), $rules_composition)) { |
|
| 226 | + elseif (in_array(AndRule::operator, $rules_composition) |
|
| 227 | + || in_array(AbstractRule::findSymbolicOperator(AndRule::operator), $rules_composition)) { |
|
| 228 | 228 | $rule = new AndRule(); |
| 229 | 229 | } |
| 230 | - elseif (in_array( OrRule::operator, $rules_composition ) |
|
| 231 | - || in_array( AbstractRule::findSymbolicOperator( OrRule::operator ), $rules_composition) ) { |
|
| 230 | + elseif (in_array(OrRule::operator, $rules_composition) |
|
| 231 | + || in_array(AbstractRule::findSymbolicOperator(OrRule::operator), $rules_composition)) { |
|
| 232 | 232 | $rule = new OrRule(); |
| 233 | 233 | } |
| 234 | 234 | else { |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | $operands_descriptions = array_filter( |
| 244 | 244 | $rules_composition, |
| 245 | - function ($operand) use ($operator) { |
|
| 245 | + function($operand) use ($operator) { |
|
| 246 | 246 | return ! in_array($operand, [$operator, AbstractRule::findSymbolicOperator($operator)]); |
| 247 | 247 | } |
| 248 | 248 | ); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | foreach ($operands_descriptions as $i => $operands_description) { |
| 260 | 260 | if (false === $operands_description) { |
| 261 | - $operands_descriptions[ $i ] = ['and']; // FalseRule hack |
|
| 261 | + $operands_descriptions[$i] = ['and']; // FalseRule hack |
|
| 262 | 262 | } |
| 263 | 263 | elseif (null === $operands_description || true === $operands_description) { |
| 264 | 264 | $operands_description = ['and']; |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | ); |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - unset($operands_descriptions[ $i ]); |
|
| 272 | + unset($operands_descriptions[$i]); |
|
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | |
@@ -283,11 +283,11 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | ); |
| 285 | 285 | |
| 286 | - if (! empty($remaining_operations)) { |
|
| 286 | + if ( ! empty($remaining_operations)) { |
|
| 287 | 287 | throw new \InvalidArgumentException( |
| 288 | 288 | "Mixing different operations in the same rule level not implemented: \n[" |
| 289 | 289 | . implode(', ', $remaining_operations)."]\n" |
| 290 | - . 'in ' . var_export($rules_composition, true) |
|
| 290 | + . 'in '.var_export($rules_composition, true) |
|
| 291 | 291 | ); |
| 292 | 292 | } |
| 293 | 293 | |