@@ -51,7 +51,7 @@ 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(); |
@@ -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 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @param array $rules_description Rules description |
| 139 | 139 | * @return LogicalFilter $this |
| 140 | 140 | */ |
| 141 | - protected function addRules( $operation, array $rules_description ) |
|
| 141 | + protected function addRules($operation, array $rules_description) |
|
| 142 | 142 | { |
| 143 | 143 | if ($rules_description == [null]) { |
| 144 | 144 | // TODO this is due to the bad design of using "Null" instead of |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - if ( 3 == count($rules_description) |
|
| 164 | + if (3 == count($rules_description) |
|
| 165 | 165 | && is_string($rules_description[0]) |
| 166 | 166 | && is_string($rules_description[1]) |
| 167 | 167 | ) { |
@@ -177,30 +177,30 @@ discard block |
||
| 177 | 177 | } |
| 178 | 178 | elseif (count($rules_description) == count(array_filter($rules_description, function($arg) { |
| 179 | 179 | return $arg instanceof LogicalFilter; |
| 180 | - })) ) { |
|
| 180 | + }))) { |
|
| 181 | 181 | // Already instanciated rules |
| 182 | 182 | foreach ($rules_description as $i => $filter) { |
| 183 | 183 | $rules = $filter->getRules(); |
| 184 | 184 | if (null !== $rules) { |
| 185 | - $this->addRule( $rules, $operation); |
|
| 185 | + $this->addRule($rules, $operation); |
|
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | elseif (count($rules_description) == count(array_filter($rules_description, function($arg) { |
| 190 | 190 | return $arg instanceof AbstractRule; |
| 191 | - })) ) { |
|
| 191 | + }))) { |
|
| 192 | 192 | // Already instanciated rules |
| 193 | 193 | foreach ($rules_description as $i => $new_rule) { |
| 194 | - $this->addRule( $new_rule, $operation); |
|
| 194 | + $this->addRule($new_rule, $operation); |
|
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | elseif (1 == count($rules_description) && is_array($rules_description[0])) { |
| 198 | 198 | if (count($rules_description[0]) == count(array_filter($rules_description[0], function($arg) { |
| 199 | 199 | return $arg instanceof AbstractRule; |
| 200 | - })) ) { |
|
| 200 | + }))) { |
|
| 201 | 201 | // Case of $filter->or_([AbstractRule, AbstractRule, AbstractRule, ...]) |
| 202 | 202 | foreach ($rules_description[0] as $i => $new_rule) { |
| 203 | - $this->addRule( $new_rule, $operation ); |
|
| 203 | + $this->addRule($new_rule, $operation); |
|
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | else { |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | $fake_root |
| 212 | 212 | ); |
| 213 | 213 | |
| 214 | - $this->addRule( $fake_root->getOperands()[0], $operation ); |
|
| 214 | + $this->addRule($fake_root->getOperands()[0], $operation); |
|
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | else { |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | * |
| 233 | 233 | * @return $this |
| 234 | 234 | */ |
| 235 | - protected function addRule( AbstractRule $rule, $operation=AndRule::operator ) |
|
| 235 | + protected function addRule(AbstractRule $rule, $operation = AndRule::operator) |
|
| 236 | 236 | { |
| 237 | - if ( $this->rules && in_array( get_class($this->rules), [AndRule::class, OrRule::class] ) |
|
| 238 | - && ! $this->rules->getOperands() ) { |
|
| 237 | + if ($this->rules && in_array(get_class($this->rules), [AndRule::class, OrRule::class]) |
|
| 238 | + && ! $this->rules->getOperands()) { |
|
| 239 | 239 | throw new \LogicException( |
| 240 | 240 | "You are trying to add rules to a LogicalFilter which had " |
| 241 | 241 | ."only contradictory rules that have already been simplified: " |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | array $rules_composition, |
| 285 | 285 | AbstractOperationRule $recursion_position |
| 286 | 286 | ) { |
| 287 | - if ( ! array_filter($rules_composition, function ($rule_composition_part) { |
|
| 287 | + if ( ! array_filter($rules_composition, function($rule_composition_part) { |
|
| 288 | 288 | return is_string($rule_composition_part); |
| 289 | 289 | })) { |
| 290 | 290 | // at least one operator is required for operation rules |
@@ -293,13 +293,13 @@ discard block |
||
| 293 | 293 | .var_export($rules_composition, true) |
| 294 | 294 | ); |
| 295 | 295 | } |
| 296 | - elseif ( 3 == count($rules_composition) |
|
| 297 | - && ! in_array( AndRule::operator, $rules_composition, true ) |
|
| 298 | - && ! in_array( OrRule::operator, $rules_composition, true ) |
|
| 299 | - && ! in_array( NotRule::operator, $rules_composition, true ) |
|
| 300 | - && ! in_array( AbstractRule::findSymbolicOperator( AndRule::operator ), $rules_composition, true ) |
|
| 301 | - && ! in_array( AbstractRule::findSymbolicOperator( OrRule::operator ), $rules_composition, true ) |
|
| 302 | - && ! in_array( AbstractRule::findSymbolicOperator( NotRule::operator ), $rules_composition, true ) |
|
| 296 | + elseif (3 == count($rules_composition) |
|
| 297 | + && ! in_array(AndRule::operator, $rules_composition, true) |
|
| 298 | + && ! in_array(OrRule::operator, $rules_composition, true) |
|
| 299 | + && ! in_array(NotRule::operator, $rules_composition, true) |
|
| 300 | + && ! in_array(AbstractRule::findSymbolicOperator(AndRule::operator), $rules_composition, true) |
|
| 301 | + && ! in_array(AbstractRule::findSymbolicOperator(OrRule::operator), $rules_composition, true) |
|
| 302 | + && ! in_array(AbstractRule::findSymbolicOperator(NotRule::operator), $rules_composition, true) |
|
| 303 | 303 | ) { |
| 304 | 304 | // atomic or composit rules |
| 305 | 305 | $operand_left = $rules_composition[0]; |
@@ -309,20 +309,20 @@ discard block |
||
| 309 | 309 | $rule = AbstractRule::generateSimpleRule( |
| 310 | 310 | $operand_left, $operation, $operand_right, $this->getOptions() |
| 311 | 311 | ); |
| 312 | - $recursion_position->addOperand( $rule ); |
|
| 312 | + $recursion_position->addOperand($rule); |
|
| 313 | 313 | } |
| 314 | 314 | else { |
| 315 | 315 | // operations |
| 316 | - if ( NotRule::operator == $rules_composition[0] |
|
| 317 | - || $rules_composition[0] == AbstractRule::findSymbolicOperator( NotRule::operator ) ) { |
|
| 316 | + if (NotRule::operator == $rules_composition[0] |
|
| 317 | + || $rules_composition[0] == AbstractRule::findSymbolicOperator(NotRule::operator)) { |
|
| 318 | 318 | $rule = new NotRule(); |
| 319 | 319 | } |
| 320 | - elseif (in_array( AndRule::operator, $rules_composition ) |
|
| 321 | - || in_array( AbstractRule::findSymbolicOperator( AndRule::operator ), $rules_composition )) { |
|
| 320 | + elseif (in_array(AndRule::operator, $rules_composition) |
|
| 321 | + || in_array(AbstractRule::findSymbolicOperator(AndRule::operator), $rules_composition)) { |
|
| 322 | 322 | $rule = new AndRule(); |
| 323 | 323 | } |
| 324 | - elseif (in_array( OrRule::operator, $rules_composition ) |
|
| 325 | - || in_array( AbstractRule::findSymbolicOperator( OrRule::operator ), $rules_composition ) ) { |
|
| 324 | + elseif (in_array(OrRule::operator, $rules_composition) |
|
| 325 | + || in_array(AbstractRule::findSymbolicOperator(OrRule::operator), $rules_composition)) { |
|
| 326 | 326 | $rule = new OrRule(); |
| 327 | 327 | } |
| 328 | 328 | else { |
@@ -336,8 +336,8 @@ discard block |
||
| 336 | 336 | |
| 337 | 337 | $operands_descriptions = array_filter( |
| 338 | 338 | $rules_composition, |
| 339 | - function ($operand) use ($operator) { |
|
| 340 | - return ! in_array($operand, [$operator, AbstractRule::findSymbolicOperator( $operator )]); |
|
| 339 | + function($operand) use ($operator) { |
|
| 340 | + return ! in_array($operand, [$operator, AbstractRule::findSymbolicOperator($operator)]); |
|
| 341 | 341 | } |
| 342 | 342 | ); |
| 343 | 343 | |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | |
| 353 | 353 | foreach ($operands_descriptions as $i => $operands_description) { |
| 354 | 354 | if (false === $operands_description) { |
| 355 | - $operands_descriptions[ $i ] = ['and']; // FalseRule hack |
|
| 355 | + $operands_descriptions[$i] = ['and']; // FalseRule hack |
|
| 356 | 356 | } |
| 357 | 357 | elseif (null === $operands_description || true === $operands_description) { |
| 358 | 358 | $operands_description = ['and']; |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | ); |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - unset($operands_descriptions[ $i ]); |
|
| 366 | + unset($operands_descriptions[$i]); |
|
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | 369 | |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | throw new \InvalidArgumentException( |
| 382 | 382 | "Mixing different operations in the same rule level not implemented: \n[" |
| 383 | 383 | . implode(', ', $remaining_operations)."]\n" |
| 384 | - . 'in ' . var_export($rules_composition, true) |
|
| 384 | + . 'in '.var_export($rules_composition, true) |
|
| 385 | 385 | ); |
| 386 | 386 | } |
| 387 | 387 | |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - $recursion_position->addOperand( $rule ); |
|
| 410 | + $recursion_position->addOperand($rule); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | return $this; |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | */ |
| 437 | 437 | public function and_() |
| 438 | 438 | { |
| 439 | - $this->addRules( AndRule::operator, func_get_args()); |
|
| 439 | + $this->addRules(AndRule::operator, func_get_args()); |
|
| 440 | 440 | return $this; |
| 441 | 441 | } |
| 442 | 442 | |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | */ |
| 465 | 465 | public function or_() |
| 466 | 466 | { |
| 467 | - $this->addRules( OrRule::operator, func_get_args()); |
|
| 467 | + $this->addRules(OrRule::operator, func_get_args()); |
|
| 468 | 468 | return $this; |
| 469 | 469 | } |
| 470 | 470 | |
@@ -511,12 +511,12 @@ discard block |
||
| 511 | 511 | * @param array $options stop_after | stop_before | |
| 512 | 512 | * @return $this |
| 513 | 513 | */ |
| 514 | - public function simplify($options=[]) |
|
| 514 | + public function simplify($options = []) |
|
| 515 | 515 | { |
| 516 | 516 | if ($this->rules) { |
| 517 | 517 | // AndRule added to make all Operation methods available |
| 518 | 518 | $this->rules = (new AndRule([$this->rules])) |
| 519 | - ->simplify( $options ) |
|
| 519 | + ->simplify($options) |
|
| 520 | 520 | // ->dump(true, false) |
| 521 | 521 | ; |
| 522 | 522 | } |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | * |
| 538 | 538 | * @return bool |
| 539 | 539 | */ |
| 540 | - public function hasSolution($save_simplification=true) |
|
| 540 | + public function hasSolution($save_simplification = true) |
|
| 541 | 541 | { |
| 542 | 542 | if ( ! $this->rules) { |
| 543 | 543 | return true; |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | * |
| 559 | 559 | * @return array A description of the rules. |
| 560 | 560 | */ |
| 561 | - public function toArray(array $options=[]) |
|
| 561 | + public function toArray(array $options = []) |
|
| 562 | 562 | { |
| 563 | 563 | return $this->rules ? $this->rules->toArray($options) : $this->rules; |
| 564 | 564 | } |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | * |
| 571 | 571 | * @return array A description of the rules. |
| 572 | 572 | */ |
| 573 | - public function toString(array $options=[]) |
|
| 573 | + public function toString(array $options = []) |
|
| 574 | 574 | { |
| 575 | 575 | return $this->rules ? $this->rules->toString($options) : $this->rules; |
| 576 | 576 | } |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | * @param mixed $row |
| 609 | 609 | * @return bool |
| 610 | 610 | */ |
| 611 | - public function __invoke($row, $key=null) |
|
| 611 | + public function __invoke($row, $key = null) |
|
| 612 | 612 | { |
| 613 | 613 | return $this->validates($row, $key); |
| 614 | 614 | } |
@@ -658,8 +658,8 @@ discard block |
||
| 658 | 658 | [ |
| 659 | 659 | Filterer::on_row_matches => function($rule, $key, &$rows, $matching_case) use (&$cache_flush_required) { |
| 660 | 660 | // $rule->dump(); |
| 661 | - unset( $rows[$key] ); |
|
| 662 | - if ( ! $rows ) { |
|
| 661 | + unset($rows[$key]); |
|
| 662 | + if ( ! $rows) { |
|
| 663 | 663 | throw new \Exception( |
| 664 | 664 | "Removing the only rule $rule from the filter $this " |
| 665 | 665 | ."produces a case which has no possible solution due to missing " |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | * |
| 696 | 696 | * @todo Merge with rules |
| 697 | 697 | */ |
| 698 | - public function keepLeafRulesMatching($filter=[], array $options=[]) |
|
| 698 | + public function keepLeafRulesMatching($filter = [], array $options = []) |
|
| 699 | 699 | { |
| 700 | 700 | $clean_empty_branches = ! isset($options['clean_empty_branches']) || $options['clean_empty_branches']; |
| 701 | 701 | |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | // ->dump() |
| 704 | 704 | ; |
| 705 | 705 | |
| 706 | - $options[ Filterer::leaves_only ] = true; |
|
| 706 | + $options[Filterer::leaves_only] = true; |
|
| 707 | 707 | |
| 708 | 708 | $this->rules = (new RuleFilterer)->apply($filter, $this->rules, $options); |
| 709 | 709 | // $this->rules->dump(true); |
@@ -718,7 +718,7 @@ discard block |
||
| 718 | 718 | $this->rules, |
| 719 | 719 | [ |
| 720 | 720 | Filterer::on_row_matches => function($rule, $key, &$rows) { |
| 721 | - unset( $rows[$key] ); |
|
| 721 | + unset($rows[$key]); |
|
| 722 | 722 | }, |
| 723 | 723 | Filterer::on_row_mismatches => function($rule, $key, &$rows) { |
| 724 | 724 | }, |
@@ -743,7 +743,7 @@ discard block |
||
| 743 | 743 | * |
| 744 | 744 | * @todo Merge with rules |
| 745 | 745 | */ |
| 746 | - public function listLeafRulesMatching($filter=[]) |
|
| 746 | + public function listLeafRulesMatching($filter = []) |
|
| 747 | 747 | { |
| 748 | 748 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
| 749 | 749 | // ->dump() |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | $key, |
| 764 | 764 | array $siblings |
| 765 | 765 | ) use (&$out) { |
| 766 | - if ( ! $matching_rule instanceof AndRule |
|
| 766 | + if ( ! $matching_rule instanceof AndRule |
|
| 767 | 767 | && ! $matching_rule instanceof OrRule |
| 768 | 768 | && ! $matching_rule instanceof NotRule |
| 769 | 769 | ) { |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | * |
| 787 | 787 | * @todo Make it available on AbstractRule also |
| 788 | 788 | */ |
| 789 | - public function onEachRule($filter=[], $options) |
|
| 789 | + public function onEachRule($filter = [], $options) |
|
| 790 | 790 | { |
| 791 | 791 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
| 792 | 792 | // ->dump() |
@@ -862,7 +862,7 @@ discard block |
||
| 862 | 862 | * |
| 863 | 863 | * @return LogicalFilter |
| 864 | 864 | */ |
| 865 | - public function saveAs( &$variable ) |
|
| 865 | + public function saveAs(&$variable) |
|
| 866 | 866 | { |
| 867 | 867 | return $variable = $this; |
| 868 | 868 | } |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | * |
| 874 | 874 | * @return LogicalFilter |
| 875 | 875 | */ |
| 876 | - public function saveCopyAs( &$copied_variable ) |
|
| 876 | + public function saveCopyAs(&$copied_variable) |
|
| 877 | 877 | { |
| 878 | 878 | $copied_variable = $this->copy(); |
| 879 | 879 | return $this; |
@@ -886,15 +886,15 @@ discard block |
||
| 886 | 886 | * |
| 887 | 887 | * @return $this |
| 888 | 888 | */ |
| 889 | - public function dump($exit=false, array $options=[]) |
|
| 889 | + public function dump($exit = false, array $options = []) |
|
| 890 | 890 | { |
| 891 | 891 | $default_options = [ |
| 892 | 892 | 'callstack_depth' => 3, |
| 893 | 893 | 'mode' => 'string', |
| 894 | 894 | ]; |
| 895 | 895 | foreach ($default_options as $default_option => &$default_value) { |
| 896 | - if ( ! isset($options[ $default_option ])) { |
|
| 897 | - $options[ $default_option ] = $default_value; |
|
| 896 | + if ( ! isset($options[$default_option])) { |
|
| 897 | + $options[$default_option] = $default_value; |
|
| 898 | 898 | } |
| 899 | 899 | } |
| 900 | 900 | extract($options); |
@@ -905,23 +905,23 @@ discard block |
||
| 905 | 905 | else { |
| 906 | 906 | // TODO dump a TrueRule |
| 907 | 907 | $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth); |
| 908 | - $caller = $bt[ $callstack_depth - 2 ]; |
|
| 908 | + $caller = $bt[$callstack_depth - 2]; |
|
| 909 | 909 | |
| 910 | 910 | // get line and file from the previous level of the caller |
| 911 | 911 | // TODO go deeper if this case exist? |
| 912 | 912 | if ( ! isset($caller['file'])) { |
| 913 | - $caller['file'] = $bt[ $callstack_depth - 3 ]['file']; |
|
| 913 | + $caller['file'] = $bt[$callstack_depth - 3]['file']; |
|
| 914 | 914 | } |
| 915 | 915 | if ( ! isset($caller['line'])) { |
| 916 | - $caller['line'] = $bt[ $callstack_depth - 3 ]['line']; |
|
| 916 | + $caller['line'] = $bt[$callstack_depth - 3]['line']; |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | try { |
| 920 | - echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n"; |
|
| 920 | + echo "\n".$caller['file'].':'.$caller['line']."\n"; |
|
| 921 | 921 | var_export($this->toArray($options)); |
| 922 | 922 | } |
| 923 | 923 | catch (\Exception $e) { |
| 924 | - echo "\nError while dumping: " . $e->getMessage() . "\n"; |
|
| 924 | + echo "\nError while dumping: ".$e->getMessage()."\n"; |
|
| 925 | 925 | var_export($caller); |
| 926 | 926 | echo "\n\n"; |
| 927 | 927 | var_export($bt); |
@@ -946,7 +946,7 @@ discard block |
||
| 946 | 946 | * |
| 947 | 947 | * @return mixed The filtered data |
| 948 | 948 | */ |
| 949 | - public function applyOn($data_to_filter, $action_on_matches=null, $filterer=null) |
|
| 949 | + public function applyOn($data_to_filter, $action_on_matches = null, $filterer = null) |
|
| 950 | 950 | { |
| 951 | 951 | if ( ! $filterer) { |
| 952 | 952 | $filterer = $this->getDefaultFilterer(); |
@@ -962,11 +962,11 @@ discard block |
||
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | if ($data_to_filter instanceof LogicalFilter) { |
| 965 | - $filtered_rules = $filterer->apply( $this, $data_to_filter->getRules() ); |
|
| 966 | - return $data_to_filter->flushRules()->addRule( $filtered_rules ); |
|
| 965 | + $filtered_rules = $filterer->apply($this, $data_to_filter->getRules()); |
|
| 966 | + return $data_to_filter->flushRules()->addRule($filtered_rules); |
|
| 967 | 967 | } |
| 968 | 968 | else { |
| 969 | - return $filterer->apply( $this, $data_to_filter ); |
|
| 969 | + return $filterer->apply($this, $data_to_filter); |
|
| 970 | 970 | } |
| 971 | 971 | } |
| 972 | 972 | |
@@ -981,7 +981,7 @@ discard block |
||
| 981 | 981 | * + Null if the target has no sens (operation filtered by field for example) |
| 982 | 982 | * + A rule tree containing the first matching case if there is one. |
| 983 | 983 | */ |
| 984 | - public function validates($value_to_check, $key_to_check=null, $filterer=null) |
|
| 984 | + public function validates($value_to_check, $key_to_check = null, $filterer = null) |
|
| 985 | 985 | { |
| 986 | 986 | if ( ! $filterer) { |
| 987 | 987 | $filterer = $this->getDefaultFilterer(); |
@@ -996,7 +996,7 @@ discard block |
||
| 996 | 996 | ); |
| 997 | 997 | } |
| 998 | 998 | |
| 999 | - return $filterer->hasMatchingCase( $this, $value_to_check, $key_to_check ); |
|
| 999 | + return $filterer->hasMatchingCase($this, $value_to_check, $key_to_check); |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | /**/ |
@@ -21,14 +21,14 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @return array |
| 23 | 23 | */ |
| 24 | - public function toArray(array $options=[]) |
|
| 24 | + public function toArray(array $options = []) |
|
| 25 | 25 | { |
| 26 | 26 | $default_options = [ |
| 27 | 27 | 'show_instance' => false, |
| 28 | 28 | ]; |
| 29 | 29 | foreach ($default_options as $default_option => &$default_value) { |
| 30 | - if ( ! isset($options[ $default_option ])) { |
|
| 31 | - $options[ $default_option ] = $default_value; |
|
| 30 | + if ( ! isset($options[$default_option])) { |
|
| 31 | + $options[$default_option] = $default_value; |
|
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | */ |
| 57 | - public function toString(array $options=[]) |
|
| 57 | + public function toString(array $options = []) |
|
| 58 | 58 | { |
| 59 | 59 | if ( ! empty($this->cache['string'])) { |
| 60 | 60 | return $this->cache['string']; |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | const remove_negations = 'remove_negations'; |
| 21 | 21 | const rootify_disjunctions = 'rootify_disjunctions'; |
| 22 | 22 | const unify_atomic_operands = 'unify_atomic_operands'; |
| 23 | - const remove_invalid_branches = 'remove_invalid_branches'; // simplified after this step |
|
| 23 | + const remove_invalid_branches = 'remove_invalid_branches'; // simplified after this step |
|
| 24 | 24 | |
| 25 | 25 | const simplified = self::remove_invalid_branches; |
| 26 | 26 | |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | */ |
| 46 | - public function __construct( array $operands=[] ) |
|
| 46 | + public function __construct(array $operands = []) |
|
| 47 | 47 | { |
| 48 | - $this->setOperands( $operands ); |
|
| 48 | + $this->setOperands($operands); |
|
| 49 | 49 | $this->flushCache(); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -64,10 +64,10 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return $this |
| 66 | 66 | */ |
| 67 | - public function addOperand( AbstractRule $new_operand ) |
|
| 67 | + public function addOperand(AbstractRule $new_operand) |
|
| 68 | 68 | { |
| 69 | - if ( ! isset($this->operands[ $id = $new_operand->getSemanticId() ])) { |
|
| 70 | - $this->operands[ $id ] = $new_operand; |
|
| 69 | + if ( ! isset($this->operands[$id = $new_operand->getSemanticId()])) { |
|
| 70 | + $this->operands[$id] = $new_operand; |
|
| 71 | 71 | |
| 72 | 72 | if ($this->current_simplification_step) { |
| 73 | 73 | $this->current_simplification_step = null; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function getOperands() |
| 86 | 86 | { |
| 87 | - return array_values( $this->operands ); |
|
| 87 | + return array_values($this->operands); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @param array $simplification_options |
| 129 | 129 | * @param bool $force |
| 130 | 130 | */ |
| 131 | - public function moveSimplificationStepForward($step_to_go_to, array $simplification_options, $force=false) |
|
| 131 | + public function moveSimplificationStepForward($step_to_go_to, array $simplification_options, $force = false) |
|
| 132 | 132 | { |
| 133 | 133 | if ( ! in_array($step_to_go_to, self::simplification_steps)) { |
| 134 | 134 | throw new \InvalidArgumentException( |
@@ -140,18 +140,18 @@ discard block |
||
| 140 | 140 | if ( ! $force && null !== $this->current_simplification_step) { |
| 141 | 141 | $steps_indices = array_flip(self::simplification_steps); |
| 142 | 142 | |
| 143 | - $current_index = $steps_indices[ $this->current_simplification_step ]; |
|
| 144 | - $target_index = $steps_indices[ $step_to_go_to ]; |
|
| 143 | + $current_index = $steps_indices[$this->current_simplification_step]; |
|
| 144 | + $target_index = $steps_indices[$step_to_go_to]; |
|
| 145 | 145 | |
| 146 | - if ( $current_index >= $target_index ) { |
|
| 146 | + if ($current_index >= $target_index) { |
|
| 147 | 147 | // allow recall of previous step without going back |
| 148 | 148 | return; |
| 149 | 149 | } |
| 150 | - elseif ( $current_index < $target_index - 1 ) { |
|
| 150 | + elseif ($current_index < $target_index - 1) { |
|
| 151 | 151 | throw new \LogicException( |
| 152 | - "$step_to_go_to MUST be fullfilled after " . self::simplification_steps[$target_index - 1] |
|
| 153 | - . " instead of the current step: " . $this->current_simplification_step |
|
| 154 | - ."\nfor: " . $this |
|
| 152 | + "$step_to_go_to MUST be fullfilled after ".self::simplification_steps[$target_index - 1] |
|
| 153 | + . " instead of the current step: ".$this->current_simplification_step |
|
| 154 | + ."\nfor: ".$this |
|
| 155 | 155 | ); |
| 156 | 156 | } |
| 157 | 157 | } |
@@ -180,8 +180,8 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | $steps_indices = array_flip(self::simplification_steps); |
| 182 | 182 | |
| 183 | - $current_index = $steps_indices[ $this->current_simplification_step ]; |
|
| 184 | - $step_index = $steps_indices[ $step ]; |
|
| 183 | + $current_index = $steps_indices[$this->current_simplification_step]; |
|
| 184 | + $step_index = $steps_indices[$step]; |
|
| 185 | 185 | |
| 186 | 186 | return $current_index >= $step_index; |
| 187 | 187 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | if ($operands[$i] instanceof AbstractOperationRule) { |
| 210 | - $operands[$i]->removeNegations( $contextual_options ); |
|
| 210 | + $operands[$i]->removeNegations($contextual_options); |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
@@ -230,11 +230,11 @@ discard block |
||
| 230 | 230 | * |
| 231 | 231 | * @return AbstractOperationRule |
| 232 | 232 | */ |
| 233 | - public function cleanOperations(array $simplification_options, $recurse=true) |
|
| 233 | + public function cleanOperations(array $simplification_options, $recurse = true) |
|
| 234 | 234 | { |
| 235 | 235 | if ($recurse) { |
| 236 | 236 | foreach ($this->operands as $i => $operand) { |
| 237 | - if ( $operand instanceof AbstractOperationRule |
|
| 237 | + if ($operand instanceof AbstractOperationRule |
|
| 238 | 238 | && ! $operand instanceof InRule |
| 239 | 239 | && ! $operand instanceof NotEqualRule |
| 240 | 240 | && ! $operand instanceof NotInRule |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | public function unifyAtomicOperands($simplification_strategy_step = false, array $contextual_options) |
| 308 | 308 | { |
| 309 | 309 | if ($simplification_strategy_step) { |
| 310 | - $this->moveSimplificationStepForward( self::unify_atomic_operands, $contextual_options ); |
|
| 310 | + $this->moveSimplificationStepForward(self::unify_atomic_operands, $contextual_options); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | // $this->dump(true); |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | catch (\Exception $e) { |
| 344 | 344 | VisibilityViolator::setHiddenProperty( |
| 345 | 345 | $e, 'message', |
| 346 | - $e->getMessage() . "\n" . var_export($operandsByOperator, true) |
|
| 346 | + $e->getMessage()."\n".var_export($operandsByOperator, true) |
|
| 347 | 347 | ); |
| 348 | 348 | |
| 349 | 349 | throw $e; |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - return $this->setOperandsOrReplaceByOperation( $unifiedOperands, $contextual_options ); |
|
| 354 | + return $this->setOperandsOrReplaceByOperation($unifiedOperands, $contextual_options); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | private static $simplification_cache = []; |
@@ -367,10 +367,10 @@ discard block |
||
| 367 | 367 | * |
| 368 | 368 | * @return AbstractRule the simplified rule |
| 369 | 369 | */ |
| 370 | - final public function simplify($options=[]) |
|
| 370 | + final public function simplify($options = []) |
|
| 371 | 371 | { |
| 372 | - $step_to_stop_before = ! empty($options['stop_before']) ? $options['stop_before'] : null; |
|
| 373 | - $step_to_stop_after = ! empty($options['stop_after']) ? $options['stop_after'] : null; |
|
| 372 | + $step_to_stop_before = ! empty($options['stop_before']) ? $options['stop_before'] : null; |
|
| 373 | + $step_to_stop_after = ! empty($options['stop_after']) ? $options['stop_after'] : null; |
|
| 374 | 374 | $force_logical_core = ! empty($options['force_logical_core']) ? $options['force_logical_core'] : false; |
| 375 | 375 | |
| 376 | 376 | if ($step_to_stop_before && ! in_array($step_to_stop_before, self::simplification_steps)) { |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | // $instance->dump(true); |
| 409 | 409 | |
| 410 | 410 | if (self::remove_negations == $step_to_stop_after || |
| 411 | - self::rootify_disjunctions == $step_to_stop_before ) { |
|
| 411 | + self::rootify_disjunctions == $step_to_stop_before) { |
|
| 412 | 412 | return $instance; |
| 413 | 413 | } |
| 414 | 414 | |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | // $instance->dump(true); |
| 421 | 421 | |
| 422 | 422 | if (self::rootify_disjunctions == $step_to_stop_after || |
| 423 | - self::unify_atomic_operands == $step_to_stop_before ) { |
|
| 423 | + self::unify_atomic_operands == $step_to_stop_before) { |
|
| 424 | 424 | return $instance; |
| 425 | 425 | } |
| 426 | 426 | |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | // $instance->dump(true); |
| 432 | 432 | |
| 433 | 433 | if (self::unify_atomic_operands == $step_to_stop_after || |
| 434 | - self::remove_invalid_branches == $step_to_stop_before ) { |
|
| 434 | + self::remove_invalid_branches == $step_to_stop_before) { |
|
| 435 | 435 | return $instance; |
| 436 | 436 | } |
| 437 | 437 | |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | // last non recursive clean |
| 449 | 449 | // TODO kind of monad|become|cese |
| 450 | 450 | //@see https://github.com/jclaveau/php-logical-filter/issues/20 |
| 451 | - if ($instance instanceof AndRule || $instance instanceof OrRule ) { |
|
| 451 | + if ($instance instanceof AndRule || $instance instanceof OrRule) { |
|
| 452 | 452 | if ( ! $instance->getOperands()) { |
| 453 | 453 | return $instance; |
| 454 | 454 | } |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | |
| 488 | 488 | $cache_keys[] = $instance->getSemanticId().'-'.$options_id; |
| 489 | 489 | foreach ($cache_keys as $cache_key) { |
| 490 | - self::$simplification_cache[ $cache_key ] = $instance; |
|
| 490 | + self::$simplification_cache[$cache_key] = $instance; |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | return $instance->copy(); |
@@ -510,15 +510,15 @@ discard block |
||
| 510 | 510 | // For FilteredValue and FilteredKey |
| 511 | 511 | $field = (string) $field; |
| 512 | 512 | |
| 513 | - if ( ! isset($operandsByFields[ $field ])) { |
|
| 514 | - $operandsByFields[ $field ] = []; |
|
| 513 | + if ( ! isset($operandsByFields[$field])) { |
|
| 514 | + $operandsByFields[$field] = []; |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - if ( ! isset($operandsByFields[ $field ][ $operand::operator ])) { |
|
| 518 | - $operandsByFields[ $field ][ $operand::operator ] = []; |
|
| 517 | + if ( ! isset($operandsByFields[$field][$operand::operator])) { |
|
| 518 | + $operandsByFields[$field][$operand::operator] = []; |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - $operandsByFields[ $field ][ $operand::operator ][] = $operand; |
|
| 521 | + $operandsByFields[$field][$operand::operator][] = $operand; |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | return $operandsByFields; |
@@ -541,15 +541,15 @@ discard block |
||
| 541 | 541 | // For FilteredValue and FilteredKey |
| 542 | 542 | $field = (string) $field; |
| 543 | 543 | |
| 544 | - if ( ! isset($operandsByFields[ $field ])) { |
|
| 545 | - $operandsByFields[ $field ] = []; |
|
| 544 | + if ( ! isset($operandsByFields[$field])) { |
|
| 545 | + $operandsByFields[$field] = []; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | - if ( ! isset($operandsByFields[ $field ][ $operand::operator ])) { |
|
| 549 | - $operandsByFields[ $field ][ $operand::operator ] = []; |
|
| 548 | + if ( ! isset($operandsByFields[$field][$operand::operator])) { |
|
| 549 | + $operandsByFields[$field][$operand::operator] = []; |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - $operandsByFields[ $field ][ $operand::operator ][] = $operand; |
|
| 552 | + $operandsByFields[$field][$operand::operator][] = $operand; |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | return $operandsByFields; |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | * |
| 588 | 588 | * @return AbstractRule|null The operand if it exists or null |
| 589 | 589 | */ |
| 590 | - protected function getOperandAt($index=0) |
|
| 590 | + protected function getOperandAt($index = 0) |
|
| 591 | 591 | { |
| 592 | 592 | $operands = array_values($this->operands); |
| 593 | 593 | if (isset($operands[$index])) { |
@@ -57,11 +57,11 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | foreach ($upLiftedOperands as $i => $operand) { |
| 59 | 59 | if ($operand instanceof NotRule) { |
| 60 | - if ( ($operand instanceof NotEqualRule || $operand instanceof NotInRule) |
|
| 60 | + if (($operand instanceof NotEqualRule || $operand instanceof NotInRule) |
|
| 61 | 61 | && ! $operand->isNormalizationAllowed($simplification_options) |
| 62 | 62 | ) { |
| 63 | 63 | foreach ($upLiftedOr->getOperands() as $upLifdtedOperand) { |
| 64 | - $upLifdtedOperand->addOperand( $operand->copy() ); |
|
| 64 | + $upLifdtedOperand->addOperand($operand->copy()); |
|
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | else { |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | foreach ($operand->getOperands() as $subOperand) { |
| 84 | 84 | foreach ($upLiftedOr->getOperands() as $upLiftedOrSubOperand) { |
| 85 | 85 | $newUpLiftedOrSubOperand = $upLiftedOrSubOperand->copy(); |
| 86 | - $newUpLiftedOrSubOperand->addOperand( $subOperand->copy() ); |
|
| 86 | + $newUpLiftedOrSubOperand->addOperand($subOperand->copy()); |
|
| 87 | 87 | if ($newUpLiftedOrSubOperand->simplify($simplification_options)->hasSolution($simplification_options)) { |
| 88 | - $newUpLiftedOr->addOperand( $newUpLiftedOrSubOperand ); |
|
| 88 | + $newUpLiftedOr->addOperand($newUpLiftedOrSubOperand); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | ); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - $upLifdtedOperand->addOperand( $operand->copy() ); |
|
| 105 | + $upLifdtedOperand->addOperand($operand->copy()); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @todo same as OrRule |
| 119 | 119 | */ |
| 120 | - public function toArray(array $options=[]) |
|
| 120 | + public function toArray(array $options = []) |
|
| 121 | 121 | { |
| 122 | 122 | $default_options = [ |
| 123 | 123 | 'show_instance' => false, |
@@ -125,8 +125,8 @@ discard block |
||
| 125 | 125 | 'semantic' => false, |
| 126 | 126 | ]; |
| 127 | 127 | foreach ($default_options as $default_option => &$default_value) { |
| 128 | - if ( ! isset($options[ $default_option ])) { |
|
| 129 | - $options[ $default_option ] = $default_value; |
|
| 128 | + if ( ! isset($options[$default_option])) { |
|
| 129 | + $options[$default_option] = $default_value; |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | 167 | */ |
| 168 | - public function toString(array $options=[]) |
|
| 168 | + public function toString(array $options = []) |
|
| 169 | 169 | { |
| 170 | 170 | $operator = self::operator; |
| 171 | 171 | if ( ! $this->operands) { |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | foreach ($this->operands as $operand) { |
| 181 | 181 | $out .= implode("\n", array_map(function($line) use (&$indent_unit) { |
| 182 | 182 | return $indent_unit.$line; |
| 183 | - }, explode("\n", $operand->toString($options)) )) . ",$line_break"; |
|
| 183 | + }, explode("\n", $operand->toString($options)))).",$line_break"; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | $out .= ']'; |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | // Id AND is an operand on AND they can be merge (and the same with OR) |
| 206 | 206 | foreach ($operands as $sub_operand) { |
| 207 | - $this->addOperand( $sub_operand->copy() ); |
|
| 207 | + $this->addOperand($sub_operand->copy()); |
|
| 208 | 208 | } |
| 209 | 209 | unset($this->operands[$i]); |
| 210 | 210 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | foreach ($this->operands as $i => $operand) { |
| 233 | 233 | // if ($operand instanceof AndRule || $operand instanceof OrRule ) { |
| 234 | - if ( in_array( get_class($operand), [AndRule::class, OrRule::class]) ) { |
|
| 234 | + if (in_array(get_class($operand), [AndRule::class, OrRule::class])) { |
|
| 235 | 235 | $this->operands[$i] = $operand->removeInvalidBranches($simplification_options); |
| 236 | 236 | if ( ! $this->operands[$i]->hasSolution()) { |
| 237 | 237 | $this->operands = []; |
@@ -245,8 +245,8 @@ discard block |
||
| 245 | 245 | // $this->dump(true); |
| 246 | 246 | |
| 247 | 247 | foreach ($operandsByFields as $field => $operandsByOperator) { |
| 248 | - if ( ! empty($operandsByOperator[ EqualRule::operator ])) { |
|
| 249 | - foreach ($operandsByOperator[ EqualRule::operator ] as $equalRule) { |
|
| 248 | + if ( ! empty($operandsByOperator[EqualRule::operator])) { |
|
| 249 | + foreach ($operandsByOperator[EqualRule::operator] as $equalRule) { |
|
| 250 | 250 | // Multiple equal rules without the same value is invalid |
| 251 | 251 | if (isset($previousEqualRule) && $previousEqualRule->getValue() != $equalRule->getValue()) { |
| 252 | 252 | $this->operands = []; |
@@ -256,55 +256,55 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | unset($previousEqualRule); |
| 258 | 258 | |
| 259 | - $equalRule = reset($operandsByOperator[ EqualRule::operator ]); |
|
| 259 | + $equalRule = reset($operandsByOperator[EqualRule::operator]); |
|
| 260 | 260 | |
| 261 | - if ( ! empty($operandsByOperator[ BelowRule::operator ]) |
|
| 261 | + if ( ! empty($operandsByOperator[BelowRule::operator]) |
|
| 262 | 262 | && null === $equalRule->getValue() |
| 263 | 263 | ) { |
| 264 | 264 | $this->operands = []; |
| 265 | 265 | return $this; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - if ( ! empty($operandsByOperator[ BelowRule::operator ]) |
|
| 269 | - && $equalRule->getValue() >= reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit() |
|
| 268 | + if ( ! empty($operandsByOperator[BelowRule::operator]) |
|
| 269 | + && $equalRule->getValue() >= reset($operandsByOperator[BelowRule::operator])->getUpperLimit() |
|
| 270 | 270 | ) { |
| 271 | 271 | $this->operands = []; |
| 272 | 272 | return $this; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if ( ! empty($operandsByOperator[ AboveRule::operator ]) |
|
| 275 | + if ( ! empty($operandsByOperator[AboveRule::operator]) |
|
| 276 | 276 | && null === $equalRule->getValue() |
| 277 | 277 | ) { |
| 278 | 278 | $this->operands = []; |
| 279 | 279 | return $this; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if ( ! empty($operandsByOperator[ AboveRule::operator ]) |
|
| 283 | - && $equalRule->getValue() <= reset($operandsByOperator[ AboveRule::operator ])->getLowerLimit() |
|
| 282 | + if ( ! empty($operandsByOperator[AboveRule::operator]) |
|
| 283 | + && $equalRule->getValue() <= reset($operandsByOperator[AboveRule::operator])->getLowerLimit() |
|
| 284 | 284 | ) { |
| 285 | 285 | $this->operands = []; |
| 286 | 286 | return $this; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - if ( ! empty($operandsByOperator[ NotEqualRule::operator ]) |
|
| 290 | - && $equalRule->getValue() == reset($operandsByOperator[ NotEqualRule::operator ])->getValue() |
|
| 289 | + if ( ! empty($operandsByOperator[NotEqualRule::operator]) |
|
| 290 | + && $equalRule->getValue() == reset($operandsByOperator[NotEqualRule::operator])->getValue() |
|
| 291 | 291 | ) { |
| 292 | 292 | $this->operands = []; |
| 293 | 293 | return $this; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - if ( ! empty($operandsByOperator[ NotEqualRule::operator ]) |
|
| 296 | + if ( ! empty($operandsByOperator[NotEqualRule::operator]) |
|
| 297 | 297 | && null === $equalRule->getValue() |
| 298 | - && null === reset($operandsByOperator[ NotEqualRule::operator ])->getValue() |
|
| 298 | + && null === reset($operandsByOperator[NotEqualRule::operator])->getValue() |
|
| 299 | 299 | ) { |
| 300 | 300 | $this->operands = []; |
| 301 | 301 | return $this; |
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | - elseif ( ! empty($operandsByOperator[ BelowRule::operator ]) |
|
| 305 | - && ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 306 | - $aboveRule = reset($operandsByOperator[ AboveRule::operator ]); |
|
| 307 | - $belowRule = reset($operandsByOperator[ BelowRule::operator ]); |
|
| 304 | + elseif ( ! empty($operandsByOperator[BelowRule::operator]) |
|
| 305 | + && ! empty($operandsByOperator[AboveRule::operator])) { |
|
| 306 | + $aboveRule = reset($operandsByOperator[AboveRule::operator]); |
|
| 307 | + $belowRule = reset($operandsByOperator[BelowRule::operator]); |
|
| 308 | 308 | |
| 309 | 309 | if ($belowRule->getUpperLimit() <= $aboveRule->getLowerLimit()) { |
| 310 | 310 | $this->operands = []; |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | * |
| 325 | 325 | * @return bool If the AndRule can have a solution or not |
| 326 | 326 | */ |
| 327 | - public function hasSolution(array $contextual_options=[]) |
|
| 327 | + public function hasSolution(array $contextual_options = []) |
|
| 328 | 328 | { |
| 329 | 329 | if ( ! $this->simplicationStepReached(self::simplified)) { |
| 330 | 330 | throw new \LogicException( |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | |
| 357 | 357 | try { |
| 358 | 358 | if (AboveRule::operator == $operator) { |
| 359 | - usort($operands, function( AboveRule $a, AboveRule $b ) { |
|
| 359 | + usort($operands, function(AboveRule $a, AboveRule $b) { |
|
| 360 | 360 | if (null === $a->getLowerLimit()) { |
| 361 | 361 | return 1; |
| 362 | 362 | } |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | $operands = [reset($operands)]; |
| 375 | 375 | } |
| 376 | 376 | elseif (BelowRule::operator == $operator) { |
| 377 | - usort($operands, function( BelowRule $a, BelowRule $b ) { |
|
| 377 | + usort($operands, function(BelowRule $a, BelowRule $b) { |
|
| 378 | 378 | if (null === $a->getUpperLimit()) { |
| 379 | 379 | return 1; |
| 380 | 380 | } |
@@ -420,10 +420,10 @@ discard block |
||
| 420 | 420 | continue; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - $first_in->setPossibilities( array_intersect( |
|
| 423 | + $first_in->setPossibilities(array_intersect( |
|
| 424 | 424 | $first_in->getPossibilities(), |
| 425 | 425 | $next_in->getPossibilities() |
| 426 | - ) ); |
|
| 426 | + )); |
|
| 427 | 427 | |
| 428 | 428 | unset($operands[$i]); |
| 429 | 429 | } |
@@ -441,17 +441,17 @@ discard block |
||
| 441 | 441 | continue; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - $first_not_in->setPossibilities( array_merge( |
|
| 444 | + $first_not_in->setPossibilities(array_merge( |
|
| 445 | 445 | $first_not_in->getPossibilities(), |
| 446 | 446 | $next_not_in->getPossibilities() |
| 447 | - ) ); |
|
| 447 | + )); |
|
| 448 | 448 | |
| 449 | 449 | unset($operands[$i]); |
| 450 | 450 | } |
| 451 | 451 | } |
| 452 | 452 | } |
| 453 | 453 | catch (\Exception $e) { |
| 454 | - VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage() . "\n" . var_export([ |
|
| 454 | + VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage()."\n".var_export([ |
|
| 455 | 455 | 'operands' => $operands, |
| 456 | 456 | // 'this' => $this, |
| 457 | 457 | ], true) |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | throw $e; |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - $operandsByFields[ $field ][ $operator ] = $operands; |
|
| 464 | + $operandsByFields[$field][$operator] = $operands; |
|
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | |
@@ -484,14 +484,14 @@ discard block |
||
| 484 | 484 | ] |
| 485 | 485 | as $unifyable_operator |
| 486 | 486 | ) { |
| 487 | - if ( ! empty($operandsByOperator[ $unifyable_operator ])) { |
|
| 488 | - if (1 != count($operandsByOperator[ $unifyable_operator ])) { |
|
| 487 | + if ( ! empty($operandsByOperator[$unifyable_operator])) { |
|
| 488 | + if (1 != count($operandsByOperator[$unifyable_operator])) { |
|
| 489 | 489 | throw new \LogicException( |
| 490 | - __METHOD__ . " MUST be called after unifyAtomicOperands() " |
|
| 490 | + __METHOD__." MUST be called after unifyAtomicOperands() " |
|
| 491 | 491 | ."to have only one '$unifyable_operator' predicate istead of:\n" |
| 492 | - ."[\n".implode( ",\n", array_map(function ($rule) { |
|
| 492 | + ."[\n".implode(",\n", array_map(function($rule) { |
|
| 493 | 493 | return $rule->toString(); |
| 494 | - }, $operandsByOperator[ $unifyable_operator ]) |
|
| 494 | + }, $operandsByOperator[$unifyable_operator]) |
|
| 495 | 495 | )."\n]" |
| 496 | 496 | ); |
| 497 | 497 | } |
@@ -517,73 +517,73 @@ discard block |
||
| 517 | 517 | protected static function simplifyDifferentOperandsForField($field, array $operandsByOperator) |
| 518 | 518 | { |
| 519 | 519 | // EqualRule comparisons |
| 520 | - if ( ! empty($operandsByOperator[ EqualRule::operator ])) { |
|
| 521 | - $equalRule = reset( $operandsByOperator[ EqualRule::operator ] ); |
|
| 520 | + if ( ! empty($operandsByOperator[EqualRule::operator])) { |
|
| 521 | + $equalRule = reset($operandsByOperator[EqualRule::operator]); |
|
| 522 | 522 | |
| 523 | - if ( ! empty($operandsByOperator[ NotEqualRule::operator ])) { |
|
| 524 | - foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $not_equal_rule) { |
|
| 523 | + if ( ! empty($operandsByOperator[NotEqualRule::operator])) { |
|
| 524 | + foreach ($operandsByOperator[NotEqualRule::operator] as $i => $not_equal_rule) { |
|
| 525 | 525 | if (null !== $equalRule->getValue()) { |
| 526 | 526 | if (null === $not_equal_rule->getValue()) { // means if exists <=> equals something |
| 527 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 527 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 528 | 528 | } |
| 529 | 529 | elseif ($not_equal_rule->getValue() != $equalRule->getValue()) { |
| 530 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 530 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 531 | 531 | } |
| 532 | 532 | } |
| 533 | - elseif (null === $equalRule->getValue() ) { |
|
| 533 | + elseif (null === $equalRule->getValue()) { |
|
| 534 | 534 | if (null !== $not_equal_rule->getValue()) { |
| 535 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 535 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 536 | 536 | } |
| 537 | 537 | // else we let the "equal null" and the "not equal null" for the romeInvalidBranches step |
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 543 | - $aboveRule = reset($operandsByOperator[ AboveRule::operator ]); |
|
| 542 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
| 543 | + $aboveRule = reset($operandsByOperator[AboveRule::operator]); |
|
| 544 | 544 | if (null !== $equalRule->getValue() && $aboveRule->getLowerLimit() < $equalRule->getValue()) { |
| 545 | - unset($operandsByOperator[ AboveRule::operator ]); |
|
| 545 | + unset($operandsByOperator[AboveRule::operator]); |
|
| 546 | 546 | } |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | - if ( ! empty($operandsByOperator[ BelowRule::operator ])) { |
|
| 550 | - $belowRule = reset($operandsByOperator[ BelowRule::operator ]); |
|
| 549 | + if ( ! empty($operandsByOperator[BelowRule::operator])) { |
|
| 550 | + $belowRule = reset($operandsByOperator[BelowRule::operator]); |
|
| 551 | 551 | if (null !== $equalRule->getValue() && $belowRule->getUpperLimit() > $equalRule->getValue()) { |
| 552 | - unset($operandsByOperator[ BelowRule::operator ]); |
|
| 552 | + unset($operandsByOperator[BelowRule::operator]); |
|
| 553 | 553 | } |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - if ( ! empty($operandsByOperator[ InRule::operator ])) { |
|
| 557 | - $possibilities = reset($operandsByOperator[ InRule::operator ])->getPossibilities(); |
|
| 556 | + if ( ! empty($operandsByOperator[InRule::operator])) { |
|
| 557 | + $possibilities = reset($operandsByOperator[InRule::operator])->getPossibilities(); |
|
| 558 | 558 | |
| 559 | 559 | if (in_array($equalRule->getValue(), $possibilities)) { |
| 560 | - unset($operandsByOperator[ InRule::operator ]); |
|
| 560 | + unset($operandsByOperator[InRule::operator]); |
|
| 561 | 561 | } |
| 562 | 562 | else { |
| 563 | 563 | // We flush possibilities of the InRule |
| 564 | 564 | // TODO Replace it by a FalseRule |
| 565 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities([]); |
|
| 565 | + $operandsByOperator[InRule::operator][0]->setPossibilities([]); |
|
| 566 | 566 | // and also remove the equal rule to shorten the reste of the simplification process |
| 567 | - unset($operandsByOperator[ EqualRule::operator ]); |
|
| 567 | + unset($operandsByOperator[EqualRule::operator]); |
|
| 568 | 568 | } |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | - if ( ! empty($operandsByOperator[ NotInRule::operator ])) { |
|
| 572 | - $notInRule = reset($operandsByOperator[ NotInRule::operator ]); |
|
| 571 | + if ( ! empty($operandsByOperator[NotInRule::operator])) { |
|
| 572 | + $notInRule = reset($operandsByOperator[NotInRule::operator]); |
|
| 573 | 573 | if (in_array($equalRule->getValue(), $notInRule->getPossibilities())) { |
| 574 | 574 | // ['field', '=', 4] && ['field', '!in', [4]...] <=> false |
| 575 | 575 | return []; |
| 576 | 576 | } |
| 577 | 577 | else { |
| 578 | - unset($operandsByOperator[ NotInRule::operator ]); |
|
| 578 | + unset($operandsByOperator[NotInRule::operator]); |
|
| 579 | 579 | } |
| 580 | 580 | // $notInRule->dump(true); |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - if ( ! empty($operandsByOperator[ BelowOrEqualRule::operator ])) { |
|
| 584 | - $belowOrEqualRule = reset($operandsByOperator[ BelowOrEqualRule::operator ]); |
|
| 583 | + if ( ! empty($operandsByOperator[BelowOrEqualRule::operator])) { |
|
| 584 | + $belowOrEqualRule = reset($operandsByOperator[BelowOrEqualRule::operator]); |
|
| 585 | 585 | if ($equalRule->getValue() <= $belowOrEqualRule->getMaximum()) { |
| 586 | - unset($operandsByOperator[ BelowOrEqualRule::operator ]); |
|
| 586 | + unset($operandsByOperator[BelowOrEqualRule::operator]); |
|
| 587 | 587 | } |
| 588 | 588 | else { |
| 589 | 589 | // ['field', '=', 4] && ['field', '<=', [3]...] <=> false |
@@ -591,10 +591,10 @@ discard block |
||
| 591 | 591 | } |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - if ( ! empty($operandsByOperator[ AboveOrEqualRule::operator ])) { |
|
| 595 | - $aboveOrEqualRule = reset($operandsByOperator[ AboveOrEqualRule::operator ]); |
|
| 594 | + if ( ! empty($operandsByOperator[AboveOrEqualRule::operator])) { |
|
| 595 | + $aboveOrEqualRule = reset($operandsByOperator[AboveOrEqualRule::operator]); |
|
| 596 | 596 | if ($equalRule->getValue() >= $aboveOrEqualRule->getMinimum()) { |
| 597 | - unset($operandsByOperator[ AboveOrEqualRule::operator ]); |
|
| 597 | + unset($operandsByOperator[AboveOrEqualRule::operator]); |
|
| 598 | 598 | } |
| 599 | 599 | else { |
| 600 | 600 | // ['field', '=', 4] && ['field', '<=', [3]...] <=> false |
@@ -604,54 +604,54 @@ discard block |
||
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | // NotEqualRule null comparisons |
| 607 | - if ( ! empty($operandsByOperator[ NotEqualRule::operator ])) { |
|
| 608 | - if ( ! empty($operandsByOperator[ NotEqualRule::operator ])) { |
|
| 609 | - foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $notEqualRule) { |
|
| 607 | + if ( ! empty($operandsByOperator[NotEqualRule::operator])) { |
|
| 608 | + if ( ! empty($operandsByOperator[NotEqualRule::operator])) { |
|
| 609 | + foreach ($operandsByOperator[NotEqualRule::operator] as $i => $notEqualRule) { |
|
| 610 | 610 | if (null === $notEqualRule->getValue()) { |
| 611 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 612 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 611 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
| 612 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - if ( ! empty($operandsByOperator[ BelowRule::operator ])) { |
|
| 616 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 615 | + if ( ! empty($operandsByOperator[BelowRule::operator])) { |
|
| 616 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | - if ( ! empty($operandsByOperator[ EqualRule::operator ])) { |
|
| 620 | - if (null !== reset($operandsByOperator[ EqualRule::operator ])->getValue()) { |
|
| 621 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 619 | + if ( ! empty($operandsByOperator[EqualRule::operator])) { |
|
| 620 | + if (null !== reset($operandsByOperator[EqualRule::operator])->getValue()) { |
|
| 621 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 622 | 622 | } |
| 623 | 623 | } |
| 624 | 624 | } |
| 625 | 625 | else { |
| 626 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 627 | - if ($operandsByOperator[ AboveRule::operator ][0]->getLowerLimit() >= $notEqualRule->getValue()) { |
|
| 628 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 626 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
| 627 | + if ($operandsByOperator[AboveRule::operator][0]->getLowerLimit() >= $notEqualRule->getValue()) { |
|
| 628 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 629 | 629 | } |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - if ( ! empty($operandsByOperator[ BelowRule::operator ])) { |
|
| 633 | - if ($operandsByOperator[ BelowRule::operator ][0]->getUpperLimit() <= $notEqualRule->getValue()) { |
|
| 634 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 632 | + if ( ! empty($operandsByOperator[BelowRule::operator])) { |
|
| 633 | + if ($operandsByOperator[BelowRule::operator][0]->getUpperLimit() <= $notEqualRule->getValue()) { |
|
| 634 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 635 | 635 | } |
| 636 | 636 | } |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - if ( ! empty($operandsByOperator[ NotInRule::operator ])) { |
|
| 640 | - $notInRule = reset($operandsByOperator[ NotInRule::operator ]); |
|
| 639 | + if ( ! empty($operandsByOperator[NotInRule::operator])) { |
|
| 640 | + $notInRule = reset($operandsByOperator[NotInRule::operator]); |
|
| 641 | 641 | if ( ! in_array($notEqualRule->getValue(), $notInRule->getPossibilities())) { |
| 642 | 642 | // TODO Replace it by a FalseRule |
| 643 | - $operandsByOperator[ NotInRule::operator ][0]->setPossibilities( |
|
| 643 | + $operandsByOperator[NotInRule::operator][0]->setPossibilities( |
|
| 644 | 644 | array_merge($notInRule->getPossibilities(), [$notEqualRule->getValue()]) |
| 645 | 645 | ); |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 648 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | - if ( ! empty($operandsByOperator[ InRule::operator ])) { |
|
| 652 | - $inRule = reset($operandsByOperator[ InRule::operator ]); |
|
| 651 | + if ( ! empty($operandsByOperator[InRule::operator])) { |
|
| 652 | + $inRule = reset($operandsByOperator[InRule::operator]); |
|
| 653 | 653 | |
| 654 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
| 654 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
| 655 | 655 | array_diff($inRule->getPossibilities(), [$notEqualRule->getValue()]) |
| 656 | 656 | ); |
| 657 | 657 | } |
@@ -661,61 +661,61 @@ discard block |
||
| 661 | 661 | |
| 662 | 662 | // Comparison between InRules and NotInRules |
| 663 | 663 | // This is an optimization to avoid NotIn explosion |
| 664 | - if ( ! empty($operandsByOperator[ InRule::operator ])) { |
|
| 665 | - $inRule = $operandsByOperator[ InRule::operator ][0]; |
|
| 664 | + if ( ! empty($operandsByOperator[InRule::operator])) { |
|
| 665 | + $inRule = $operandsByOperator[InRule::operator][0]; |
|
| 666 | 666 | |
| 667 | - if ( ! empty($operandsByOperator[ NotInRule::operator ])) { |
|
| 668 | - $notInRule = reset($operandsByOperator[ NotInRule::operator ]); |
|
| 669 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
| 670 | - array_diff( $inRule->getPossibilities(), $notInRule->getPossibilities()) |
|
| 667 | + if ( ! empty($operandsByOperator[NotInRule::operator])) { |
|
| 668 | + $notInRule = reset($operandsByOperator[NotInRule::operator]); |
|
| 669 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
| 670 | + array_diff($inRule->getPossibilities(), $notInRule->getPossibilities()) |
|
| 671 | 671 | ); |
| 672 | - unset($operandsByOperator[ NotInRule::operator ]); |
|
| 672 | + unset($operandsByOperator[NotInRule::operator]); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - if ( ! empty($operandsByOperator[ BelowRule::operator ])) { |
|
| 676 | - $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit(); |
|
| 675 | + if ( ! empty($operandsByOperator[BelowRule::operator])) { |
|
| 676 | + $upper_limit = reset($operandsByOperator[BelowRule::operator])->getUpperLimit(); |
|
| 677 | 677 | |
| 678 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
| 679 | - array_filter( $inRule->getPossibilities(), function ($possibility) use ($upper_limit) { |
|
| 678 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
| 679 | + array_filter($inRule->getPossibilities(), function($possibility) use ($upper_limit) { |
|
| 680 | 680 | return $possibility < $upper_limit; |
| 681 | 681 | } ) |
| 682 | 682 | ); |
| 683 | 683 | |
| 684 | - unset($operandsByOperator[ BelowRule::operator ]); |
|
| 684 | + unset($operandsByOperator[BelowRule::operator]); |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 688 | - $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getLowerLimit(); |
|
| 687 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
| 688 | + $lower_limit = reset($operandsByOperator[AboveRule::operator])->getLowerLimit(); |
|
| 689 | 689 | |
| 690 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
| 691 | - array_filter( $inRule->getPossibilities(), function ($possibility) use ($lower_limit) { |
|
| 690 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
| 691 | + array_filter($inRule->getPossibilities(), function($possibility) use ($lower_limit) { |
|
| 692 | 692 | return $possibility > $lower_limit; |
| 693 | 693 | } ) |
| 694 | 694 | ); |
| 695 | 695 | |
| 696 | - unset($operandsByOperator[ AboveRule::operator ]); |
|
| 696 | + unset($operandsByOperator[AboveRule::operator]); |
|
| 697 | 697 | } |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | // Comparison between NotInRules and > or < |
| 701 | - if ( ! empty($operandsByOperator[ NotInRule::operator ])) { |
|
| 702 | - $notInRule = $operandsByOperator[ NotInRule::operator ][0]; |
|
| 701 | + if ( ! empty($operandsByOperator[NotInRule::operator])) { |
|
| 702 | + $notInRule = $operandsByOperator[NotInRule::operator][0]; |
|
| 703 | 703 | |
| 704 | - if ( ! empty($operandsByOperator[ BelowRule::operator ])) { |
|
| 705 | - $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit(); |
|
| 704 | + if ( ! empty($operandsByOperator[BelowRule::operator])) { |
|
| 705 | + $upper_limit = reset($operandsByOperator[BelowRule::operator])->getUpperLimit(); |
|
| 706 | 706 | |
| 707 | - $operandsByOperator[ NotInRule::operator ][0]->setPossibilities( |
|
| 708 | - array_filter( $notInRule->getPossibilities(), function ($possibility) use ($upper_limit) { |
|
| 707 | + $operandsByOperator[NotInRule::operator][0]->setPossibilities( |
|
| 708 | + array_filter($notInRule->getPossibilities(), function($possibility) use ($upper_limit) { |
|
| 709 | 709 | return $possibility < $upper_limit; |
| 710 | 710 | } ) |
| 711 | 711 | ); |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 715 | - $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getLowerLimit(); |
|
| 714 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
| 715 | + $lower_limit = reset($operandsByOperator[AboveRule::operator])->getLowerLimit(); |
|
| 716 | 716 | |
| 717 | - $operandsByOperator[ NotInRule::operator ][0]->setPossibilities( |
|
| 718 | - array_filter( $notInRule->getPossibilities(), function ($possibility) use ($lower_limit) { |
|
| 717 | + $operandsByOperator[NotInRule::operator][0]->setPossibilities( |
|
| 718 | + array_filter($notInRule->getPossibilities(), function($possibility) use ($lower_limit) { |
|
| 719 | 719 | return $possibility > $lower_limit; |
| 720 | 720 | } ) |
| 721 | 721 | ); |
@@ -723,25 +723,25 @@ discard block |
||
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | // Comparison between <= and > or < |
| 726 | - if ( ! empty($operandsByOperator[ BelowOrEqualRule::operator ])) { |
|
| 727 | - $belowOrEqualRule = $operandsByOperator[ BelowOrEqualRule::operator ][0]; |
|
| 726 | + if ( ! empty($operandsByOperator[BelowOrEqualRule::operator])) { |
|
| 727 | + $belowOrEqualRule = $operandsByOperator[BelowOrEqualRule::operator][0]; |
|
| 728 | 728 | |
| 729 | - if ( ! empty($operandsByOperator[ BelowRule::operator ])) { |
|
| 730 | - $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit(); |
|
| 729 | + if ( ! empty($operandsByOperator[BelowRule::operator])) { |
|
| 730 | + $upper_limit = reset($operandsByOperator[BelowRule::operator])->getUpperLimit(); |
|
| 731 | 731 | |
| 732 | 732 | if ($belowOrEqualRule->getMaximum() >= $upper_limit) { |
| 733 | 733 | // [field < 3] && [field <= 3] |
| 734 | 734 | // [field < 3] && [field <= 4] |
| 735 | - unset($operandsByOperator[ BelowOrEqualRule::operator ][0]); |
|
| 735 | + unset($operandsByOperator[BelowOrEqualRule::operator][0]); |
|
| 736 | 736 | } |
| 737 | 737 | else { |
| 738 | 738 | // [field < 3] && [field <= 2] |
| 739 | - unset($operandsByOperator[ BelowRule::operator ][0]); |
|
| 739 | + unset($operandsByOperator[BelowRule::operator][0]); |
|
| 740 | 740 | } |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 744 | - $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getLowerLimit(); |
|
| 743 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
| 744 | + $lower_limit = reset($operandsByOperator[AboveRule::operator])->getLowerLimit(); |
|
| 745 | 745 | |
| 746 | 746 | if ($belowOrEqualRule->getMaximum() <= $lower_limit) { |
| 747 | 747 | // [field > 3] && [field <= 2] <=> false |
@@ -749,8 +749,8 @@ discard block |
||
| 749 | 749 | } |
| 750 | 750 | } |
| 751 | 751 | |
| 752 | - if ( ! empty($operandsByOperator[ AboveOrEqualRule::operator ])) { |
|
| 753 | - $minimum = reset($operandsByOperator[ AboveOrEqualRule::operator ])->getMinimum(); |
|
| 752 | + if ( ! empty($operandsByOperator[AboveOrEqualRule::operator])) { |
|
| 753 | + $minimum = reset($operandsByOperator[AboveOrEqualRule::operator])->getMinimum(); |
|
| 754 | 754 | |
| 755 | 755 | if ($belowOrEqualRule->getMaximum() < $minimum) { |
| 756 | 756 | // [field <= 3] && [field >= 4] <=> false |
@@ -758,11 +758,11 @@ discard block |
||
| 758 | 758 | } |
| 759 | 759 | elseif ($belowOrEqualRule->getMaximum() == $minimum) { |
| 760 | 760 | // [field <= 3] && [field >= 3] <=> [field = 3] |
| 761 | - unset($operandsByOperator[ BelowOrEqualRule::operator ]); |
|
| 762 | - unset($operandsByOperator[ AboveOrEqualRule::operator ]); |
|
| 763 | - $operandsByOperator[ EqualRule::operator ][] = new EqualRule($field, $minimum); |
|
| 761 | + unset($operandsByOperator[BelowOrEqualRule::operator]); |
|
| 762 | + unset($operandsByOperator[AboveOrEqualRule::operator]); |
|
| 763 | + $operandsByOperator[EqualRule::operator][] = new EqualRule($field, $minimum); |
|
| 764 | 764 | |
| 765 | - if (count($operandsByOperator[ EqualRule::operator ]) > 1) { |
|
| 765 | + if (count($operandsByOperator[EqualRule::operator]) > 1) { |
|
| 766 | 766 | $operandsByOperator = self::simplifyDifferentOperandsForField($field, $operandsByOperator); |
| 767 | 767 | } |
| 768 | 768 | } |
@@ -781,10 +781,10 @@ discard block |
||
| 781 | 781 | public function setOperandsOrReplaceByOperation($new_operands) |
| 782 | 782 | { |
| 783 | 783 | try { |
| 784 | - return $this->setOperands( $new_operands ); |
|
| 784 | + return $this->setOperands($new_operands); |
|
| 785 | 785 | } |
| 786 | 786 | catch (\LogicException $e) { |
| 787 | - return new AndRule( $new_operands ); |
|
| 787 | + return new AndRule($new_operands); |
|
| 788 | 788 | } |
| 789 | 789 | } |
| 790 | 790 | |