@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | * |
| 536 | 536 | * This helpes to ease the result of simplify() |
| 537 | 537 | * |
| 538 | - * @return OrRule |
|
| 538 | + * @return LogicalFilter |
|
| 539 | 539 | */ |
| 540 | 540 | public function addMinimalCase() |
| 541 | 541 | { |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | * |
| 591 | 591 | * @param $debug Provides a source oriented dump. |
| 592 | 592 | * |
| 593 | - * @return array A description of the rules. |
|
| 593 | + * @return string A description of the rules. |
|
| 594 | 594 | */ |
| 595 | 595 | public function toString(array $options=[]) |
| 596 | 596 | { |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | * @param array|callable Associative array of renamings or callable |
| 669 | 669 | * that would rename the fields. |
| 670 | 670 | * |
| 671 | - * @return string $this |
|
| 671 | + * @return LogicalFilter $this |
|
| 672 | 672 | */ |
| 673 | 673 | public function removeRules($filter) |
| 674 | 674 | { |
@@ -711,8 +711,8 @@ discard block |
||
| 711 | 711 | * @param array|callable Associative array of renamings or callable |
| 712 | 712 | * that would rename the fields. |
| 713 | 713 | * |
| 714 | - * @return array The rules matching the filter |
|
| 715 | - * @return array $options debug | leaves_only | clean_empty_branches |
|
| 714 | + * @return LogicalFilter The rules matching the filter |
|
| 715 | + * @return LogicalFilter $options debug | leaves_only | clean_empty_branches |
|
| 716 | 716 | * |
| 717 | 717 | * |
| 718 | 718 | * @todo Merge with rules |
@@ -927,7 +927,6 @@ discard block |
||
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | /** |
| 930 | - * @param bool $exit=false |
|
| 931 | 930 | * @param array $options + callstack_depth=2 The level of the caller to dump |
| 932 | 931 | * + mode='string' in 'export' | 'dump' | 'string' |
| 933 | 932 | * |
@@ -1022,10 +1021,9 @@ discard block |
||
| 1022 | 1021 | * Applies the current instance to a value (and its index optionnally). |
| 1023 | 1022 | * |
| 1024 | 1023 | * @param mixed $value_to_check |
| 1025 | - * @param scalar $index |
|
| 1026 | 1024 | * @param Filterer|callable|null $filterer |
| 1027 | 1025 | * |
| 1028 | - * @return AbstractRule|false|true + False if the filter doesn't validates |
|
| 1026 | + * @return boolean + False if the filter doesn't validates |
|
| 1029 | 1027 | * + Null if the target has no sens (operation filtered by field for example) |
| 1030 | 1028 | * + A rule tree containing the first matching case if there is one. |
| 1031 | 1029 | */ |
@@ -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 | |
@@ -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 | |
@@ -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 { |
@@ -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 | } |
@@ -559,9 +559,9 @@ discard block |
||
| 559 | 559 | * |
| 560 | 560 | * @return bool |
| 561 | 561 | */ |
| 562 | - public function hasSolution($save_simplification=true) |
|
| 562 | + public function hasSolution($save_simplification = true) |
|
| 563 | 563 | { |
| 564 | - if (! $this->rules) { |
|
| 564 | + if ( ! $this->rules) { |
|
| 565 | 565 | return true; |
| 566 | 566 | } |
| 567 | 567 | |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | * |
| 581 | 581 | * @return array A description of the rules. |
| 582 | 582 | */ |
| 583 | - public function toArray(array $options=[]) |
|
| 583 | + public function toArray(array $options = []) |
|
| 584 | 584 | { |
| 585 | 585 | return $this->rules ? $this->rules->toArray($options) : $this->rules; |
| 586 | 586 | } |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | * |
| 593 | 593 | * @return array A description of the rules. |
| 594 | 594 | */ |
| 595 | - public function toString(array $options=[]) |
|
| 595 | + public function toString(array $options = []) |
|
| 596 | 596 | { |
| 597 | 597 | return $this->rules ? $this->rules->toString($options) : $this->rules; |
| 598 | 598 | } |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | * @param mixed $row |
| 631 | 631 | * @return bool |
| 632 | 632 | */ |
| 633 | - public function __invoke($row, $key=null) |
|
| 633 | + public function __invoke($row, $key = null) |
|
| 634 | 634 | { |
| 635 | 635 | return $this->validates($row, $key); |
| 636 | 636 | } |
@@ -680,8 +680,8 @@ discard block |
||
| 680 | 680 | [ |
| 681 | 681 | Filterer::on_row_matches => function($rule, $key, &$rows, $matching_case) use (&$cache_flush_required) { |
| 682 | 682 | // $rule->dump(); |
| 683 | - unset( $rows[$key] ); |
|
| 684 | - if ( ! $rows ) { |
|
| 683 | + unset($rows[$key]); |
|
| 684 | + if ( ! $rows) { |
|
| 685 | 685 | throw new \Exception( |
| 686 | 686 | "Removing the only rule $rule from the filter $this " |
| 687 | 687 | ."produces a case which has no possible solution due to missing " |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | * |
| 718 | 718 | * @todo Merge with rules |
| 719 | 719 | */ |
| 720 | - public function keepLeafRulesMatching($filter=[], array $options=[]) |
|
| 720 | + public function keepLeafRulesMatching($filter = [], array $options = []) |
|
| 721 | 721 | { |
| 722 | 722 | $clean_empty_branches = ! isset($options['clean_empty_branches']) || $options['clean_empty_branches']; |
| 723 | 723 | |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | // ->dump() |
| 726 | 726 | ; |
| 727 | 727 | |
| 728 | - $options[ Filterer::leaves_only ] = true; |
|
| 728 | + $options[Filterer::leaves_only] = true; |
|
| 729 | 729 | |
| 730 | 730 | $this->rules = (new RuleFilterer)->apply($filter, $this->rules, $options); |
| 731 | 731 | // $this->rules->dump(true); |
@@ -765,13 +765,13 @@ discard block |
||
| 765 | 765 | * |
| 766 | 766 | * @todo Merge with rules |
| 767 | 767 | */ |
| 768 | - public function listLeafRulesMatching($filter=[]) |
|
| 768 | + public function listLeafRulesMatching($filter = []) |
|
| 769 | 769 | { |
| 770 | 770 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
| 771 | 771 | // ->dump() |
| 772 | 772 | ; |
| 773 | 773 | |
| 774 | - if (! $this->rules) { |
|
| 774 | + if ( ! $this->rules) { |
|
| 775 | 775 | return []; |
| 776 | 776 | } |
| 777 | 777 | |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | $key, |
| 786 | 786 | array $siblings |
| 787 | 787 | ) use (&$out) { |
| 788 | - if ( ! $matching_rule instanceof AndRule |
|
| 788 | + if ( ! $matching_rule instanceof AndRule |
|
| 789 | 789 | && ! $matching_rule instanceof OrRule |
| 790 | 790 | && ! $matching_rule instanceof NotRule |
| 791 | 791 | ) { |
@@ -826,13 +826,13 @@ discard block |
||
| 826 | 826 | * |
| 827 | 827 | * @return array The rules matching the filter |
| 828 | 828 | */ |
| 829 | - public function onEachRule($filter=[], $options) |
|
| 829 | + public function onEachRule($filter = [], $options) |
|
| 830 | 830 | { |
| 831 | 831 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
| 832 | 832 | // ->dump() |
| 833 | 833 | ; |
| 834 | 834 | |
| 835 | - if (! $this->rules) { |
|
| 835 | + if ( ! $this->rules) { |
|
| 836 | 836 | return []; |
| 837 | 837 | } |
| 838 | 838 | |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | { |
| 866 | 866 | $this->simplify()->addMinimalCase(); |
| 867 | 867 | |
| 868 | - if (! $this->rules) { |
|
| 868 | + if ( ! $this->rules) { |
|
| 869 | 869 | return $this; |
| 870 | 870 | } |
| 871 | 871 | |
@@ -909,7 +909,7 @@ discard block |
||
| 909 | 909 | * |
| 910 | 910 | * @return LogicalFilter |
| 911 | 911 | */ |
| 912 | - public function saveAs( &$variable) |
|
| 912 | + public function saveAs(&$variable) |
|
| 913 | 913 | { |
| 914 | 914 | return $variable = $this; |
| 915 | 915 | } |
@@ -920,7 +920,7 @@ discard block |
||
| 920 | 920 | * |
| 921 | 921 | * @return LogicalFilter |
| 922 | 922 | */ |
| 923 | - public function saveCopyAs( &$copied_variable) |
|
| 923 | + public function saveCopyAs(&$copied_variable) |
|
| 924 | 924 | { |
| 925 | 925 | $copied_variable = $this->copy(); |
| 926 | 926 | return $this; |
@@ -933,15 +933,15 @@ discard block |
||
| 933 | 933 | * |
| 934 | 934 | * @return $this |
| 935 | 935 | */ |
| 936 | - public function dump($exit=false, array $options=[]) |
|
| 936 | + public function dump($exit = false, array $options = []) |
|
| 937 | 937 | { |
| 938 | 938 | $default_options = [ |
| 939 | 939 | 'callstack_depth' => 3, |
| 940 | 940 | 'mode' => 'string', |
| 941 | 941 | ]; |
| 942 | 942 | foreach ($default_options as $default_option => &$default_value) { |
| 943 | - if ( ! isset($options[ $default_option ])) { |
|
| 944 | - $options[ $default_option ] = $default_value; |
|
| 943 | + if ( ! isset($options[$default_option])) { |
|
| 944 | + $options[$default_option] = $default_value; |
|
| 945 | 945 | } |
| 946 | 946 | } |
| 947 | 947 | extract($options); |
@@ -952,24 +952,24 @@ discard block |
||
| 952 | 952 | else { |
| 953 | 953 | // TODO dump a TrueRule |
| 954 | 954 | $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth); |
| 955 | - $caller = $bt[ $callstack_depth - 2 ]; |
|
| 955 | + $caller = $bt[$callstack_depth - 2]; |
|
| 956 | 956 | |
| 957 | 957 | // get line and file from the previous level of the caller |
| 958 | 958 | // TODO go deeper if this case exist? |
| 959 | - if (! isset($caller['file'])) { |
|
| 960 | - $caller['file'] = $bt[ $callstack_depth - 3 ]['file']; |
|
| 959 | + if ( ! isset($caller['file'])) { |
|
| 960 | + $caller['file'] = $bt[$callstack_depth - 3]['file']; |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | - if (! isset($caller['line'])) { |
|
| 964 | - $caller['line'] = $bt[ $callstack_depth - 3 ]['line']; |
|
| 963 | + if ( ! isset($caller['line'])) { |
|
| 964 | + $caller['line'] = $bt[$callstack_depth - 3]['line']; |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | try { |
| 968 | - echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n"; |
|
| 968 | + echo "\n".$caller['file'].':'.$caller['line']."\n"; |
|
| 969 | 969 | var_export($this->toArray($options)); |
| 970 | 970 | } |
| 971 | 971 | catch (\Exception $e) { |
| 972 | - echo "\nError while dumping: " . $e->getMessage() . "\n"; |
|
| 972 | + echo "\nError while dumping: ".$e->getMessage()."\n"; |
|
| 973 | 973 | var_export($caller); |
| 974 | 974 | echo "\n\n"; |
| 975 | 975 | var_export($bt); |
@@ -994,15 +994,15 @@ discard block |
||
| 994 | 994 | * |
| 995 | 995 | * @return mixed The filtered data |
| 996 | 996 | */ |
| 997 | - public function applyOn($data_to_filter, $action_on_matches=null, $filterer=null) |
|
| 997 | + public function applyOn($data_to_filter, $action_on_matches = null, $filterer = null) |
|
| 998 | 998 | { |
| 999 | - if (! $filterer) { |
|
| 999 | + if ( ! $filterer) { |
|
| 1000 | 1000 | $filterer = $this->getDefaultFilterer(); |
| 1001 | 1001 | } |
| 1002 | 1002 | elseif (is_callable($filterer)) { |
| 1003 | 1003 | $filterer = new CustomizableFilterer($filterer); |
| 1004 | 1004 | } |
| 1005 | - elseif (! $filterer instanceof Filterer) { |
|
| 1005 | + elseif ( ! $filterer instanceof Filterer) { |
|
| 1006 | 1006 | throw new \InvalidArgumentException( |
| 1007 | 1007 | "The given \$filterer must be null or a callable or a instance " |
| 1008 | 1008 | ."of Filterer instead of: ".var_export($filterer, true) |
@@ -1010,8 +1010,8 @@ discard block |
||
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | 1012 | if ($data_to_filter instanceof LogicalFilter) { |
| 1013 | - $filtered_rules = $filterer->apply( $this, $data_to_filter->getRules() ); |
|
| 1014 | - return $data_to_filter->flushRules()->addRule( $filtered_rules ); |
|
| 1013 | + $filtered_rules = $filterer->apply($this, $data_to_filter->getRules()); |
|
| 1014 | + return $data_to_filter->flushRules()->addRule($filtered_rules); |
|
| 1015 | 1015 | } |
| 1016 | 1016 | else { |
| 1017 | 1017 | return $filterer->apply($this, $data_to_filter); |
@@ -1029,15 +1029,15 @@ discard block |
||
| 1029 | 1029 | * + Null if the target has no sens (operation filtered by field for example) |
| 1030 | 1030 | * + A rule tree containing the first matching case if there is one. |
| 1031 | 1031 | */ |
| 1032 | - public function validates($value_to_check, $key_to_check=null, $filterer=null) |
|
| 1032 | + public function validates($value_to_check, $key_to_check = null, $filterer = null) |
|
| 1033 | 1033 | { |
| 1034 | - if (! $filterer) { |
|
| 1034 | + if ( ! $filterer) { |
|
| 1035 | 1035 | $filterer = $this->getDefaultFilterer(); |
| 1036 | 1036 | } |
| 1037 | 1037 | elseif (is_callable($filterer)) { |
| 1038 | 1038 | $filterer = new CustomizableFilterer($filterer); |
| 1039 | 1039 | } |
| 1040 | - elseif (! $filterer instanceof Filterer) { |
|
| 1040 | + elseif ( ! $filterer instanceof Filterer) { |
|
| 1041 | 1041 | throw new \InvalidArgumentException( |
| 1042 | 1042 | "The given \$filterer must be null or a callable or a instance " |
| 1043 | 1043 | ."of Filterer instead of: ".var_export($filterer, true) |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function onRowMatches(&$row, $key, &$rows, $matching_case, $options) |
| 49 | 49 | { |
| 50 | - if (isset($options[ self::on_row_matches ])) { |
|
| 51 | - $callback = $options[ self::on_row_matches ]; |
|
| 50 | + if (isset($options[self::on_row_matches])) { |
|
| 51 | + $callback = $options[self::on_row_matches]; |
|
| 52 | 52 | } |
| 53 | - elseif (isset($this->custom_actions[ self::on_row_matches ])) { |
|
| 54 | - $callback = $this->custom_actions[ self::on_row_matches ]; |
|
| 53 | + elseif (isset($this->custom_actions[self::on_row_matches])) { |
|
| 54 | + $callback = $this->custom_actions[self::on_row_matches]; |
|
| 55 | 55 | } |
| 56 | 56 | else { |
| 57 | 57 | return; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function onRowMismatches(&$row, $key, &$rows, $matching_case, $options) |
| 75 | 75 | { |
| 76 | - if ( ! $this->custom_actions |
|
| 76 | + if ( ! $this->custom_actions |
|
| 77 | 77 | && ! isset($options[self::on_row_mismatches]) |
| 78 | 78 | && ! isset($options[self::on_row_matches]) |
| 79 | 79 | ) { |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | return; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if (isset($options[ self::on_row_mismatches ])) { |
|
| 86 | - $callback = $options[ self::on_row_mismatches ]; |
|
| 85 | + if (isset($options[self::on_row_mismatches])) { |
|
| 86 | + $callback = $options[self::on_row_mismatches]; |
|
| 87 | 87 | } |
| 88 | - elseif (isset($this->custom_actions[ self::on_row_mismatches ])) { |
|
| 89 | - $callback = $this->custom_actions[ self::on_row_mismatches ]; |
|
| 88 | + elseif (isset($this->custom_actions[self::on_row_mismatches])) { |
|
| 89 | + $callback = $this->custom_actions[self::on_row_mismatches]; |
|
| 90 | 90 | } |
| 91 | 91 | else { |
| 92 | 92 | return; |
@@ -123,13 +123,13 @@ discard block |
||
| 123 | 123 | * @param Iterable $tree_to_filter |
| 124 | 124 | * @param array $options |
| 125 | 125 | */ |
| 126 | - public function apply( LogicalFilter $filter, $tree_to_filter, $options=[] ) |
|
| 126 | + public function apply(LogicalFilter $filter, $tree_to_filter, $options = []) |
|
| 127 | 127 | { |
| 128 | - if (! $filter->hasSolution()) { |
|
| 128 | + if ( ! $filter->hasSolution()) { |
|
| 129 | 129 | return null; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if (! isset($options['recurse'])) { |
|
| 132 | + if ( ! isset($options['recurse'])) { |
|
| 133 | 133 | $options['recurse'] = 'before'; |
| 134 | 134 | } |
| 135 | 135 | elseif ( ! in_array($options['recurse'], ['before', 'after', null])) { |
@@ -141,16 +141,16 @@ discard block |
||
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | return $this->foreachRow( |
| 144 | - !$filter->getRules() ? [] : $filter->addMinimalCase()->getRules()->getOperands(), |
|
| 144 | + ! $filter->getRules() ? [] : $filter->addMinimalCase()->getRules()->getOperands(), |
|
| 145 | 145 | $tree_to_filter, |
| 146 | - $path=[], |
|
| 146 | + $path = [], |
|
| 147 | 147 | $options |
| 148 | 148 | ); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | 152 | */ |
| 153 | - protected function foreachRow(array $root_cases, $tree_to_filter, array $path, $options=[]) |
|
| 153 | + protected function foreachRow(array $root_cases, $tree_to_filter, array $path, $options = []) |
|
| 154 | 154 | { |
| 155 | 155 | // Once the rules are prepared, we parse the data |
| 156 | 156 | foreach ($tree_to_filter as $row_index => $row_to_filter) { |
@@ -209,23 +209,23 @@ discard block |
||
| 209 | 209 | * |
| 210 | 210 | * @return bool |
| 211 | 211 | */ |
| 212 | - public function hasMatchingCase( LogicalFilter $filter, $row_to_check, $key_to_check, $options=[] ) |
|
| 212 | + public function hasMatchingCase(LogicalFilter $filter, $row_to_check, $key_to_check, $options = []) |
|
| 213 | 213 | { |
| 214 | - if (! $filter->hasSolution()) { |
|
| 214 | + if ( ! $filter->hasSolution()) { |
|
| 215 | 215 | return null; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | return $this->applyOnRow( |
| 219 | - !$filter->getRules() ? [] : $filter->addMinimalCase()->getRules()->getOperands(), |
|
| 219 | + ! $filter->getRules() ? [] : $filter->addMinimalCase()->getRules()->getOperands(), |
|
| 220 | 220 | $row_to_check, |
| 221 | - $path=[$key_to_check], |
|
| 221 | + $path = [$key_to_check], |
|
| 222 | 222 | $options |
| 223 | 223 | ); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
| 227 | 227 | */ |
| 228 | - protected function applyOnRow(array $root_cases, $row_to_filter, array $path, $options=[]) |
|
| 228 | + protected function applyOnRow(array $root_cases, $row_to_filter, array $path, $options = []) |
|
| 229 | 229 | { |
| 230 | 230 | $operands_validation_row_cache = []; |
| 231 | 231 | |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | |
| 262 | 262 | $cache_key = $and_case_index.'~|~'.$field.'~|~'.$operator; |
| 263 | 263 | |
| 264 | - if ( ! empty($operands_validation_row_cache[ $cache_key ])) { |
|
| 265 | - $is_valid = $operands_validation_row_cache[ $cache_key ]; |
|
| 264 | + if ( ! empty($operands_validation_row_cache[$cache_key])) { |
|
| 265 | + $is_valid = $operands_validation_row_cache[$cache_key]; |
|
| 266 | 266 | } |
| 267 | 267 | else { |
| 268 | 268 | $is_valid = $this->validateRule( |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | $options |
| 276 | 276 | ); |
| 277 | 277 | |
| 278 | - $operands_validation_row_cache[ $cache_key ] = $is_valid; |
|
| 278 | + $operands_validation_row_cache[$cache_key] = $is_valid; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | if (false === $is_valid) { |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public static function findSymbolicOperator($english_operator) |
| 37 | 37 | { |
| 38 | - $association = array_flip( self::$ruleAliases ); |
|
| 39 | - if (isset($association[ $english_operator ])) { |
|
| 40 | - return $association[ $english_operator ]; |
|
| 38 | + $association = array_flip(self::$ruleAliases); |
|
| 39 | + if (isset($association[$english_operator])) { |
|
| 40 | + return $association[$english_operator]; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | return $english_operator; |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | public static function findEnglishOperator($symbolic_operator) |
| 51 | 51 | { |
| 52 | 52 | $association = self::$ruleAliases; |
| 53 | - if (isset($association[ $symbolic_operator ])) { |
|
| 54 | - return $association[ $symbolic_operator ]; |
|
| 53 | + if (isset($association[$symbolic_operator])) { |
|
| 54 | + return $association[$symbolic_operator]; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | return $symbolic_operator; |
@@ -70,16 +70,16 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return AbstractRule |
| 72 | 72 | */ |
| 73 | - public static function generateSimpleRule($field, $type, $values, array $options=[]) |
|
| 73 | + public static function generateSimpleRule($field, $type, $values, array $options = []) |
|
| 74 | 74 | { |
| 75 | - $cache_key = hash('md4', serialize( func_get_args()) ); |
|
| 75 | + $cache_key = hash('md4', serialize(func_get_args())); |
|
| 76 | 76 | if (isset(self::$static_cache['rules_generation'][$cache_key])) { |
| 77 | 77 | return self::$static_cache['rules_generation'][$cache_key]->copy(); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | $ruleClass = self::getRuleClass($type); |
| 81 | 81 | |
| 82 | - return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass( $field, $values, $options ); |
|
| 82 | + return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass($field, $values, $options); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | . str_replace('_', '', ucwords($english_rule_operator, '_')) |
| 97 | 97 | . 'Rule'; |
| 98 | 98 | |
| 99 | - if ( ! class_exists( $rule_class)) { |
|
| 99 | + if ( ! class_exists($rule_class)) { |
|
| 100 | 100 | throw new \InvalidArgumentException( |
| 101 | 101 | "The class '$rule_class' corresponding to the operator " |
| 102 | 102 | ."'$rule_operator' / '$english_rule_operator' cannot be found." |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | * @return $this |
| 127 | 127 | */ |
| 128 | - final public function dump($exit=false, array $options=[]) |
|
| 128 | + final public function dump($exit = false, array $options = []) |
|
| 129 | 129 | { |
| 130 | 130 | $default_options = [ |
| 131 | 131 | 'callstack_depth' => 2, |
@@ -133,16 +133,16 @@ discard block |
||
| 133 | 133 | // 'show_instance' => false, |
| 134 | 134 | ]; |
| 135 | 135 | foreach ($default_options as $default_option => &$default_value) { |
| 136 | - if ( ! isset($options[ $default_option ])) { |
|
| 137 | - $options[ $default_option ] = $default_value; |
|
| 136 | + if ( ! isset($options[$default_option])) { |
|
| 137 | + $options[$default_option] = $default_value; |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | extract($options); |
| 141 | 141 | |
| 142 | 142 | $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth); |
| 143 | - $caller = $bt[ $callstack_depth - 2 ]; |
|
| 143 | + $caller = $bt[$callstack_depth - 2]; |
|
| 144 | 144 | |
| 145 | - echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n"; |
|
| 145 | + echo "\n".$caller['file'].':'.$caller['line']."\n"; |
|
| 146 | 146 | if ('string' == $mode) { |
| 147 | 147 | if ( ! isset($options['indent_unit'])) { |
| 148 | 148 | $options['indent_unit'] = " "; |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | else { |
| 186 | 186 | throw new \InvalidArgumentException( |
| 187 | 187 | "'mode' option must belong to ['string', 'export', 'dump'] " |
| 188 | - ."instead of " . var_export($mode, true) |
|
| 188 | + ."instead of ".var_export($mode, true) |
|
| 189 | 189 | ); |
| 190 | 190 | } |
| 191 | 191 | echo "\n\n"; |
@@ -240,12 +240,12 @@ discard block |
||
| 240 | 240 | /** |
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | - abstract public function toString(array $options=[]); |
|
| 243 | + abstract public function toString(array $options = []); |
|
| 244 | 244 | |
| 245 | 245 | /** |
| 246 | 246 | * @return array |
| 247 | 247 | */ |
| 248 | - abstract public function toArray(array $options=[]); |
|
| 248 | + abstract public function toArray(array $options = []); |
|
| 249 | 249 | |
| 250 | 250 | protected $instance_id; |
| 251 | 251 | |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | return $this->cache['semantic_id']; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - return hash('md4', serialize( $this->toArray(['semantic' => true]) )) // faster but longer |
|
| 279 | + return hash('md4', serialize($this->toArray(['semantic' => true]))) // faster but longer |
|
| 280 | 280 | .'-' |
| 281 | - .hash('md4', serialize( $this->options )) |
|
| 281 | + .hash('md4', serialize($this->options)) |
|
| 282 | 282 | ; |
| 283 | 283 | } |
| 284 | 284 | |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | $simplification_step_to_keep = null; |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - if ( $this instanceof AbstractAtomicRule |
|
| 319 | + if ($this instanceof AbstractAtomicRule |
|
| 320 | 320 | || $this instanceof NotRule |
| 321 | 321 | || $this instanceof InRule |
| 322 | 322 | || ! $this->isNormalizationAllowed([]) |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | elseif ($this instanceof OrRule) { |
| 336 | 336 | foreach ($this->operands as $i => $operand) { |
| 337 | - if (! $operand instanceof AndRule) { |
|
| 337 | + if ( ! $operand instanceof AndRule) { |
|
| 338 | 338 | $this->operands[$i] = new AndRule([$operand]); |
| 339 | 339 | } |
| 340 | 340 | } |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | |
| 350 | 350 | if ($simplification_step_to_keep) { |
| 351 | 351 | foreach ($operands = $ruleTree->getOperands() as $andOperand) { |
| 352 | - if (! $andOperand instanceof AndRule) { |
|
| 352 | + if ( ! $andOperand instanceof AndRule) { |
|
| 353 | 353 | throw new \LogicException( |
| 354 | 354 | "A rule is intended to be an and case: \n" |
| 355 | 355 | .$andOperand |