@@ -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 | |
@@ -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 ( count($rules_description) == 3 |
|
| 164 | + if (count($rules_description) == 3 |
|
| 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 ($rules !== null) { |
| 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 (count($rules_description) == 1 && 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 ( count($rules_composition) == 3 |
|
| 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 (count($rules_composition) == 3 |
|
| 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 ( $rules_composition[0] == NotRule::operator |
|
| 317 | - || $rules_composition[0] == AbstractRule::findSymbolicOperator( NotRule::operator ) ) { |
|
| 316 | + if ($rules_composition[0] == NotRule::operator |
|
| 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,27 +352,27 @@ discard block |
||
| 352 | 352 | |
| 353 | 353 | foreach ($operands_descriptions as $i => $operands_description) { |
| 354 | 354 | if ($operands_description === false) { |
| 355 | - $operands_descriptions[ $i ] = ['and']; // FalseRule hack |
|
| 355 | + $operands_descriptions[$i] = ['and']; // FalseRule hack |
|
| 356 | 356 | } |
| 357 | 357 | elseif ($operands_description === null || $operands_description === true) { |
| 358 | 358 | $operands_description = ['and']; |
| 359 | - if ( ! $non_true_rule_descriptions) { |
|
| 359 | + if (!$non_true_rule_descriptions) { |
|
| 360 | 360 | throw new \LogicException( |
| 361 | 361 | "TrueRules are not implemented. Please add " |
| 362 | 362 | ."them to operations having other type of rules" |
| 363 | 363 | ); |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - unset($operands_descriptions[ $i ]); |
|
| 366 | + unset($operands_descriptions[$i]); |
|
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | $remaining_operations = array_filter( |
| 371 | 371 | $operands_descriptions, |
| 372 | 372 | function($operand) { |
| 373 | - return ! is_array($operand) |
|
| 374 | - && ! $operand instanceof AbstractRule |
|
| 375 | - && ! $operand instanceof LogicalFilter |
|
| 373 | + return !is_array($operand) |
|
| 374 | + && !$operand instanceof AbstractRule |
|
| 375 | + && !$operand instanceof LogicalFilter |
|
| 376 | 376 | ; |
| 377 | 377 | } |
| 378 | 378 | ); |
@@ -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,9 +537,9 @@ 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 | - if ( ! $this->rules) { |
|
| 542 | + if (!$this->rules) { |
|
| 543 | 543 | return true; |
| 544 | 544 | } |
| 545 | 545 | |
@@ -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,15 +695,15 @@ 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 | - $clean_empty_branches = ! isset($options['clean_empty_branches']) || $options['clean_empty_branches']; |
|
| 700 | + $clean_empty_branches = !isset($options['clean_empty_branches']) || $options['clean_empty_branches']; |
|
| 701 | 701 | |
| 702 | 702 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
| 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); |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | $this->rules, |
| 720 | 720 | [ |
| 721 | 721 | Filterer::on_row_matches => function($rule, $key, &$rows) { |
| 722 | - unset( $rows[$key] ); |
|
| 722 | + unset($rows[$key]); |
|
| 723 | 723 | }, |
| 724 | 724 | Filterer::on_row_mismatches => function($rule, $key, &$rows) { |
| 725 | 725 | }, |
@@ -744,13 +744,13 @@ discard block |
||
| 744 | 744 | * |
| 745 | 745 | * @todo Merge with rules |
| 746 | 746 | */ |
| 747 | - public function listLeafRulesMatching($filter=[]) |
|
| 747 | + public function listLeafRulesMatching($filter = []) |
|
| 748 | 748 | { |
| 749 | 749 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
| 750 | 750 | // ->dump() |
| 751 | 751 | ; |
| 752 | 752 | |
| 753 | - if ( ! $this->rules) { |
|
| 753 | + if (!$this->rules) { |
|
| 754 | 754 | return []; |
| 755 | 755 | } |
| 756 | 756 | |
@@ -764,9 +764,9 @@ discard block |
||
| 764 | 764 | $key, |
| 765 | 765 | array $siblings |
| 766 | 766 | ) use (&$out) { |
| 767 | - if ( ! $matching_rule instanceof AndRule |
|
| 768 | - && ! $matching_rule instanceof OrRule |
|
| 769 | - && ! $matching_rule instanceof NotRule |
|
| 767 | + if (!$matching_rule instanceof AndRule |
|
| 768 | + && !$matching_rule instanceof OrRule |
|
| 769 | + && !$matching_rule instanceof NotRule |
|
| 770 | 770 | ) { |
| 771 | 771 | $out[] = $matching_rule; |
| 772 | 772 | } |
@@ -787,13 +787,13 @@ discard block |
||
| 787 | 787 | * |
| 788 | 788 | * @todo Make it available on AbstractRule also |
| 789 | 789 | */ |
| 790 | - public function onEachRule($filter=[], $options) |
|
| 790 | + public function onEachRule($filter = [], $options) |
|
| 791 | 791 | { |
| 792 | 792 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
| 793 | 793 | // ->dump() |
| 794 | 794 | ; |
| 795 | 795 | |
| 796 | - if ( ! $this->rules) { |
|
| 796 | + if (!$this->rules) { |
|
| 797 | 797 | return []; |
| 798 | 798 | } |
| 799 | 799 | |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | { |
| 819 | 819 | $this->simplify(['force_logical_core' => true]); |
| 820 | 820 | |
| 821 | - if ( ! $this->rules) { |
|
| 821 | + if (!$this->rules) { |
|
| 822 | 822 | return $this; |
| 823 | 823 | } |
| 824 | 824 | |
@@ -863,7 +863,7 @@ discard block |
||
| 863 | 863 | * |
| 864 | 864 | * @return LogicalFilter |
| 865 | 865 | */ |
| 866 | - public function saveAs( &$variable ) |
|
| 866 | + public function saveAs(&$variable) |
|
| 867 | 867 | { |
| 868 | 868 | return $variable = $this; |
| 869 | 869 | } |
@@ -874,7 +874,7 @@ discard block |
||
| 874 | 874 | * |
| 875 | 875 | * @return LogicalFilter |
| 876 | 876 | */ |
| 877 | - public function saveCopyAs( &$copied_variable ) |
|
| 877 | + public function saveCopyAs(&$copied_variable) |
|
| 878 | 878 | { |
| 879 | 879 | $copied_variable = $this->copy(); |
| 880 | 880 | return $this; |
@@ -887,15 +887,15 @@ discard block |
||
| 887 | 887 | * |
| 888 | 888 | * @return $this |
| 889 | 889 | */ |
| 890 | - public function dump($exit=false, array $options=[]) |
|
| 890 | + public function dump($exit = false, array $options = []) |
|
| 891 | 891 | { |
| 892 | 892 | $default_options = [ |
| 893 | 893 | 'callstack_depth' => 3, |
| 894 | 894 | 'mode' => 'string', |
| 895 | 895 | ]; |
| 896 | 896 | foreach ($default_options as $default_option => &$default_value) { |
| 897 | - if ( ! isset($options[ $default_option ])) { |
|
| 898 | - $options[ $default_option ] = $default_value; |
|
| 897 | + if (!isset($options[$default_option])) { |
|
| 898 | + $options[$default_option] = $default_value; |
|
| 899 | 899 | } |
| 900 | 900 | } |
| 901 | 901 | extract($options); |
@@ -906,23 +906,23 @@ discard block |
||
| 906 | 906 | else { |
| 907 | 907 | // TODO dump a TrueRule |
| 908 | 908 | $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth); |
| 909 | - $caller = $bt[ $callstack_depth - 2 ]; |
|
| 909 | + $caller = $bt[$callstack_depth - 2]; |
|
| 910 | 910 | |
| 911 | 911 | // get line and file from the previous level of the caller |
| 912 | 912 | // TODO go deeper if this case exist? |
| 913 | - if ( ! isset($caller['file'])) { |
|
| 914 | - $caller['file'] = $bt[ $callstack_depth - 3 ]['file']; |
|
| 913 | + if (!isset($caller['file'])) { |
|
| 914 | + $caller['file'] = $bt[$callstack_depth - 3]['file']; |
|
| 915 | 915 | } |
| 916 | - if ( ! isset($caller['line'])) { |
|
| 917 | - $caller['line'] = $bt[ $callstack_depth - 3 ]['line']; |
|
| 916 | + if (!isset($caller['line'])) { |
|
| 917 | + $caller['line'] = $bt[$callstack_depth - 3]['line']; |
|
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | try { |
| 921 | - echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n"; |
|
| 921 | + echo "\n".$caller['file'].':'.$caller['line']."\n"; |
|
| 922 | 922 | var_export($this->toArray($options)); |
| 923 | 923 | } |
| 924 | 924 | catch (\Exception $e) { |
| 925 | - echo "\nError while dumping: " . $e->getMessage() . "\n"; |
|
| 925 | + echo "\nError while dumping: ".$e->getMessage()."\n"; |
|
| 926 | 926 | var_export($caller); |
| 927 | 927 | echo "\n\n"; |
| 928 | 928 | var_export($bt); |
@@ -947,15 +947,15 @@ discard block |
||
| 947 | 947 | * |
| 948 | 948 | * @return mixed The filtered data |
| 949 | 949 | */ |
| 950 | - public function applyOn($data_to_filter, $action_on_matches=null, $filterer=null) |
|
| 950 | + public function applyOn($data_to_filter, $action_on_matches = null, $filterer = null) |
|
| 951 | 951 | { |
| 952 | - if ( ! $filterer) { |
|
| 952 | + if (!$filterer) { |
|
| 953 | 953 | $filterer = $this->getDefaultFilterer(); |
| 954 | 954 | } |
| 955 | 955 | elseif (is_callable($filterer)) { |
| 956 | 956 | $filterer = new CustomizableFilterer($filterer); |
| 957 | 957 | } |
| 958 | - elseif ( ! $filterer instanceof Filterer) { |
|
| 958 | + elseif (!$filterer instanceof Filterer) { |
|
| 959 | 959 | throw new \InvalidArgumentException( |
| 960 | 960 | "The given \$filterer must be null or a callable or a instance " |
| 961 | 961 | ."of Filterer instead of: ".var_export($filterer, true) |
@@ -963,11 +963,11 @@ discard block |
||
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | if ($data_to_filter instanceof LogicalFilter) { |
| 966 | - $filtered_rules = $filterer->apply( $this, $data_to_filter->getRules() ); |
|
| 967 | - return $data_to_filter->flushRules()->addRule( $filtered_rules ); |
|
| 966 | + $filtered_rules = $filterer->apply($this, $data_to_filter->getRules()); |
|
| 967 | + return $data_to_filter->flushRules()->addRule($filtered_rules); |
|
| 968 | 968 | } |
| 969 | 969 | else { |
| 970 | - return $filterer->apply( $this, $data_to_filter ); |
|
| 970 | + return $filterer->apply($this, $data_to_filter); |
|
| 971 | 971 | } |
| 972 | 972 | } |
| 973 | 973 | |
@@ -982,22 +982,22 @@ discard block |
||
| 982 | 982 | * + Null if the target has no sens (operation filtered by field for example) |
| 983 | 983 | * + A rule tree containing the first matching case if there is one. |
| 984 | 984 | */ |
| 985 | - public function validates($value_to_check, $key_to_check=null, $filterer=null) |
|
| 985 | + public function validates($value_to_check, $key_to_check = null, $filterer = null) |
|
| 986 | 986 | { |
| 987 | - if ( ! $filterer) { |
|
| 987 | + if (!$filterer) { |
|
| 988 | 988 | $filterer = $this->getDefaultFilterer(); |
| 989 | 989 | } |
| 990 | 990 | elseif (is_callable($filterer)) { |
| 991 | 991 | $filterer = new CustomizableFilterer($filterer); |
| 992 | 992 | } |
| 993 | - elseif ( ! $filterer instanceof Filterer) { |
|
| 993 | + elseif (!$filterer instanceof Filterer) { |
|
| 994 | 994 | throw new \InvalidArgumentException( |
| 995 | 995 | "The given \$filterer must be null or a callable or a instance " |
| 996 | 996 | ."of Filterer instead of: ".var_export($filterer, true) |
| 997 | 997 | ); |
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | - return $filterer->hasMatchingCase( $this, $value_to_check, $key_to_check ); |
|
| 1000 | + return $filterer->hasMatchingCase($this, $value_to_check, $key_to_check); |
|
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | 1003 | /**/ |
@@ -144,8 +144,7 @@ discard block |
||
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | echo ($this->toString($options)); |
| 147 | - } |
|
| 148 | - elseif ($mode == 'dump') { |
|
| 147 | + } elseif ($mode == 'dump') { |
|
| 149 | 148 | if ($xdebug_enabled = ini_get('xdebug.overload_var_dump')) { |
| 150 | 149 | ini_set('xdebug.overload_var_dump', 0); |
| 151 | 150 | } |
@@ -155,8 +154,7 @@ discard block |
||
| 155 | 154 | if ($xdebug_enabled) { |
| 156 | 155 | ini_set('xdebug.overload_var_dump', 1); |
| 157 | 156 | } |
| 158 | - } |
|
| 159 | - elseif ($mode == 'xdebug') { |
|
| 157 | + } elseif ($mode == 'xdebug') { |
|
| 160 | 158 | if ( ! function_exists('xdebug_is_enabled')) { |
| 161 | 159 | throw new \RuntimeException("Xdebug is not installed"); |
| 162 | 160 | } |
@@ -173,11 +171,9 @@ discard block |
||
| 173 | 171 | if ($xdebug_enabled) { |
| 174 | 172 | ini_set('xdebug.overload_var_dump', 0); |
| 175 | 173 | } |
| 176 | - } |
|
| 177 | - elseif ($mode == 'export') { |
|
| 174 | + } elseif ($mode == 'export') { |
|
| 178 | 175 | var_export($this->toArray($options)); |
| 179 | - } |
|
| 180 | - else { |
|
| 176 | + } else { |
|
| 181 | 177 | throw new \InvalidArgumentException( |
| 182 | 178 | "'mode' option must belong to ['string', 'export', 'dump'] " |
| 183 | 179 | ."instead of " . var_export($mode, true) |
@@ -288,21 +284,18 @@ discard block |
||
| 288 | 284 | $this, |
| 289 | 285 | ]), |
| 290 | 286 | ]); |
| 291 | - } |
|
| 292 | - elseif ($this instanceof AndRule) { |
|
| 287 | + } elseif ($this instanceof AndRule) { |
|
| 293 | 288 | $ruleTree = new OrRule([ |
| 294 | 289 | $this, |
| 295 | 290 | ]); |
| 296 | - } |
|
| 297 | - elseif ($this instanceof OrRule) { |
|
| 291 | + } elseif ($this instanceof OrRule) { |
|
| 298 | 292 | foreach ($this->operands as $i => $operand) { |
| 299 | 293 | if ( ! $operand instanceof AndRule) { |
| 300 | 294 | $this->operands[$i] = new AndRule([$operand]); |
| 301 | 295 | } |
| 302 | 296 | } |
| 303 | 297 | $ruleTree = $this; |
| 304 | - } |
|
| 305 | - else { |
|
| 298 | + } else { |
|
| 306 | 299 | throw new \LogicException( |
| 307 | 300 | "Unhandled type of simplified rules provided for conversion: " |
| 308 | 301 | .$this |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | // https://www.elastic.co/guide/en/elasticsearch/guide/current/_dealing_with_null_values.html#_missing_query |
| 65 | 65 | $new_rule = [ |
| 66 | 66 | 'missing' => [ |
| 67 | - 'field' => $field, |
|
| 67 | + 'field' => $field, |
|
| 68 | 68 | ], |
| 69 | 69 | ]; |
| 70 | 70 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html |
| 124 | 124 | $new_rule = [ |
| 125 | 125 | 'exists' => [ |
| 126 | - 'field' => $field, |
|
| 126 | + 'field' => $field, |
|
| 127 | 127 | ], |
| 128 | 128 | ]; |
| 129 | 129 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html |
| 132 | 132 | $new_rule = [ |
| 133 | 133 | 'regexp' => [ |
| 134 | - $field => [ |
|
| 134 | + $field => [ |
|
| 135 | 135 | 'value' => $operand->getPattern(), |
| 136 | 136 | // 'flags' => 'INTERSECTION|COMPLEMENT|EMPTY', |
| 137 | 137 | // 'max_determinized_states' => 2000 |
@@ -67,23 +67,20 @@ discard block |
||
| 67 | 67 | 'field' => $field, |
| 68 | 68 | ], |
| 69 | 69 | ]; |
| 70 | - } |
|
| 71 | - else { |
|
| 70 | + } else { |
|
| 72 | 71 | $new_rule = [ |
| 73 | 72 | 'term' => [ |
| 74 | 73 | $field => $operand->getValue(), |
| 75 | 74 | ], |
| 76 | 75 | ]; |
| 77 | 76 | } |
| 78 | - } |
|
| 79 | - elseif ($operator == 'in') { |
|
| 77 | + } elseif ($operator == 'in') { |
|
| 80 | 78 | $new_rule = [ |
| 81 | 79 | 'terms' => [ |
| 82 | 80 | $field => $operand->getPossibilities(), |
| 83 | 81 | ], |
| 84 | 82 | ]; |
| 85 | - } |
|
| 86 | - elseif ($operator == '<') { |
|
| 83 | + } elseif ($operator == '<') { |
|
| 87 | 84 | $new_rule = [ |
| 88 | 85 | 'range' => [ |
| 89 | 86 | $field => [ |
@@ -91,8 +88,7 @@ discard block |
||
| 91 | 88 | ], |
| 92 | 89 | ], |
| 93 | 90 | ]; |
| 94 | - } |
|
| 95 | - elseif ($operator == '>') { |
|
| 91 | + } elseif ($operator == '>') { |
|
| 96 | 92 | $new_rule = [ |
| 97 | 93 | 'range' => [ |
| 98 | 94 | $field => [ |
@@ -100,8 +96,7 @@ discard block |
||
| 100 | 96 | ], |
| 101 | 97 | ], |
| 102 | 98 | ]; |
| 103 | - } |
|
| 104 | - elseif ($operator == '<=') { |
|
| 99 | + } elseif ($operator == '<=') { |
|
| 105 | 100 | $new_rule = [ |
| 106 | 101 | 'range' => [ |
| 107 | 102 | $field => [ |
@@ -109,8 +104,7 @@ discard block |
||
| 109 | 104 | ], |
| 110 | 105 | ], |
| 111 | 106 | ]; |
| 112 | - } |
|
| 113 | - elseif ($operator == '>=') { |
|
| 107 | + } elseif ($operator == '>=') { |
|
| 114 | 108 | $new_rule = [ |
| 115 | 109 | 'range' => [ |
| 116 | 110 | $field => [ |
@@ -118,16 +112,14 @@ discard block |
||
| 118 | 112 | ], |
| 119 | 113 | ], |
| 120 | 114 | ]; |
| 121 | - } |
|
| 122 | - elseif ($operator == '!=' && $operand->getValue() === null) { |
|
| 115 | + } elseif ($operator == '!=' && $operand->getValue() === null) { |
|
| 123 | 116 | // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html |
| 124 | 117 | $new_rule = [ |
| 125 | 118 | 'exists' => [ |
| 126 | 119 | 'field' => $field, |
| 127 | 120 | ], |
| 128 | 121 | ]; |
| 129 | - } |
|
| 130 | - elseif ($operator == 'regexp') { |
|
| 122 | + } elseif ($operator == 'regexp') { |
|
| 131 | 123 | // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html |
| 132 | 124 | $new_rule = [ |
| 133 | 125 | 'regexp' => [ |
@@ -138,8 +130,7 @@ discard block |
||
| 138 | 130 | ], |
| 139 | 131 | ], |
| 140 | 132 | ]; |
| 141 | - } |
|
| 142 | - else { |
|
| 133 | + } else { |
|
| 143 | 134 | throw new \InvalidArgumentException( |
| 144 | 135 | "Unhandled operator '$operator' during ES query generation" |
| 145 | 136 | ); |