@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | * |
| 532 | 532 | * This helpes to ease the result of simplify() |
| 533 | 533 | * |
| 534 | - * @return OrRule |
|
| 534 | + * @return LogicalFilter |
|
| 535 | 535 | */ |
| 536 | 536 | public function addMinimalCase() |
| 537 | 537 | { |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | * |
| 587 | 587 | * @param $debug Provides a source oriented dump. |
| 588 | 588 | * |
| 589 | - * @return array A description of the rules. |
|
| 589 | + * @return string A description of the rules. |
|
| 590 | 590 | */ |
| 591 | 591 | public function toString(array $options=[]) |
| 592 | 592 | { |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | * @param array|callable Associative array of renamings or callable |
| 662 | 662 | * that would rename the fields. |
| 663 | 663 | * |
| 664 | - * @return string $this |
|
| 664 | + * @return LogicalFilter $this |
|
| 665 | 665 | */ |
| 666 | 666 | public function removeRules($filter) |
| 667 | 667 | { |
@@ -706,7 +706,7 @@ discard block |
||
| 706 | 706 | * @param array|LogicalFilter $rule_filter |
| 707 | 707 | * @param array|callable $options |
| 708 | 708 | * |
| 709 | - * @return array The rules matching the filter |
|
| 709 | + * @return LogicalFilter The rules matching the filter |
|
| 710 | 710 | */ |
| 711 | 711 | public function filterRules($rule_filter=[], array $options=[]) |
| 712 | 712 | { |
@@ -729,8 +729,8 @@ discard block |
||
| 729 | 729 | * @param array|callable Associative array of renamings or callable |
| 730 | 730 | * that would rename the fields. |
| 731 | 731 | * |
| 732 | - * @return array The rules matching the filter |
|
| 733 | - * @return array $options debug | leaves_only | clean_empty_branches |
|
| 732 | + * @return LogicalFilter The rules matching the filter |
|
| 733 | + * @return LogicalFilter $options debug | leaves_only | clean_empty_branches |
|
| 734 | 734 | */ |
| 735 | 735 | public function keepLeafRulesMatching($filter=[], array $options=[]) |
| 736 | 736 | { |
@@ -838,6 +838,7 @@ discard block |
||
| 838 | 838 | * @param array|LogicalFilter |
| 839 | 839 | * @param array|callable Associative array of renamings or callable |
| 840 | 840 | * that would rename the fields. |
| 841 | + * @param \Closure $options |
|
| 841 | 842 | * |
| 842 | 843 | * @return array The rules matching the filter |
| 843 | 844 | */ |
@@ -1024,7 +1025,6 @@ discard block |
||
| 1024 | 1025 | } |
| 1025 | 1026 | |
| 1026 | 1027 | /** |
| 1027 | - * @param bool $exit=false |
|
| 1028 | 1028 | * @param array $options + callstack_depth=2 The level of the caller to dump |
| 1029 | 1029 | * + mode='string' in 'export' | 'dump' | 'string' |
| 1030 | 1030 | * |
@@ -1119,10 +1119,9 @@ discard block |
||
| 1119 | 1119 | * Applies the current instance to a value (and its index optionnally). |
| 1120 | 1120 | * |
| 1121 | 1121 | * @param mixed $value_to_check |
| 1122 | - * @param scalar $index |
|
| 1123 | 1122 | * @param Filterer|callable|null $filterer |
| 1124 | 1123 | * |
| 1125 | - * @return AbstractRule|false|true + False if the filter doesn't validates |
|
| 1124 | + * @return boolean + False if the filter doesn't validates |
|
| 1126 | 1125 | * + Null if the target has no sens (operation filtered by field for example) |
| 1127 | 1126 | * + A rule tree containing the first matching case if there is one. |
| 1128 | 1127 | */ |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | if ($this->rules && in_array( get_class($this->rules), [AndRule::class, OrRule::class]) |
| 238 | 238 | && ! $this->rules->getOperands() ) { |
| 239 | 239 | throw new \LogicException( |
| 240 | - "You are trying to add rules to a LogicalFilter which had " |
|
| 240 | + "You are trying to add rules to a LogicalFilter which had " |
|
| 241 | 241 | ."only contradictory rules that have already been simplified: " |
| 242 | 242 | .$this->rules |
| 243 | 243 | ); |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | unset( $rows[$key] ); |
| 677 | 677 | if (! $rows ) { |
| 678 | 678 | throw new \Exception( |
| 679 | - "Removing the only rule $rule from the filter $this " |
|
| 679 | + "Removing the only rule $rule from the filter $this " |
|
| 680 | 680 | ."produces a case which has no possible solution due to missing " |
| 681 | 681 | ."implementation of TrueRule.\n" |
| 682 | 682 | ."Please see: https://github.com/jclaveau/php-logical-filter/issues/59" |
@@ -1101,7 +1101,7 @@ discard block |
||
| 1101 | 1101 | } |
| 1102 | 1102 | elseif (! $filterer instanceof Filterer) { |
| 1103 | 1103 | throw new \InvalidArgumentException( |
| 1104 | - "The given \$filterer must be null or a callable or a instance " |
|
| 1104 | + "The given \$filterer must be null or a callable or a instance " |
|
| 1105 | 1105 | ."of Filterer instead of: ".var_export($filterer, true) |
| 1106 | 1106 | ); |
| 1107 | 1107 | } |
@@ -1136,7 +1136,7 @@ discard block |
||
| 1136 | 1136 | } |
| 1137 | 1137 | elseif (! $filterer instanceof Filterer) { |
| 1138 | 1138 | throw new \InvalidArgumentException( |
| 1139 | - "The given \$filterer must be null or a callable or a instance " |
|
| 1139 | + "The given \$filterer must be null or a callable or a instance " |
|
| 1140 | 1140 | ."of Filterer instead of: ".var_export($filterer, true) |
| 1141 | 1141 | ); |
| 1142 | 1142 | } |
@@ -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 | |
@@ -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,7 +293,7 @@ discard block |
||
| 293 | 293 | .var_export($rules_composition, true) |
| 294 | 294 | ); |
| 295 | 295 | } |
| 296 | - elseif ( 3 == count($rules_composition) |
|
| 296 | + elseif (3 == count($rules_composition) |
|
| 297 | 297 | && AbstractRule::isLeftOperand($rules_composition[0]) |
| 298 | 298 | && AbstractRule::isOperator($rules_composition[1]) |
| 299 | 299 | ) { |
@@ -305,20 +305,20 @@ discard block |
||
| 305 | 305 | $rule = AbstractRule::generateSimpleRule( |
| 306 | 306 | $operand_left, $operation, $operand_right, $this->getOptions() |
| 307 | 307 | ); |
| 308 | - $recursion_position->addOperand( $rule ); |
|
| 308 | + $recursion_position->addOperand($rule); |
|
| 309 | 309 | } |
| 310 | 310 | else { |
| 311 | 311 | // operations |
| 312 | - if ( NotRule::operator == $rules_composition[0] |
|
| 313 | - || $rules_composition[0] == AbstractRule::findSymbolicOperator( NotRule::operator ) ) { |
|
| 312 | + if (NotRule::operator == $rules_composition[0] |
|
| 313 | + || $rules_composition[0] == AbstractRule::findSymbolicOperator(NotRule::operator)) { |
|
| 314 | 314 | $rule = new NotRule(); |
| 315 | 315 | } |
| 316 | - elseif (in_array( AndRule::operator, $rules_composition ) |
|
| 317 | - || in_array( AbstractRule::findSymbolicOperator( AndRule::operator ), $rules_composition )) { |
|
| 316 | + elseif (in_array(AndRule::operator, $rules_composition) |
|
| 317 | + || in_array(AbstractRule::findSymbolicOperator(AndRule::operator), $rules_composition)) { |
|
| 318 | 318 | $rule = new AndRule(); |
| 319 | 319 | } |
| 320 | - elseif (in_array( OrRule::operator, $rules_composition ) |
|
| 321 | - || in_array( AbstractRule::findSymbolicOperator( OrRule::operator ), $rules_composition ) ) { |
|
| 320 | + elseif (in_array(OrRule::operator, $rules_composition) |
|
| 321 | + || in_array(AbstractRule::findSymbolicOperator(OrRule::operator), $rules_composition)) { |
|
| 322 | 322 | $rule = new OrRule(); |
| 323 | 323 | } |
| 324 | 324 | else { |
@@ -332,8 +332,8 @@ discard block |
||
| 332 | 332 | |
| 333 | 333 | $operands_descriptions = array_filter( |
| 334 | 334 | $rules_composition, |
| 335 | - function ($operand) use ($operator) { |
|
| 336 | - return ! in_array($operand, [$operator, AbstractRule::findSymbolicOperator( $operator )]); |
|
| 335 | + function($operand) use ($operator) { |
|
| 336 | + return ! in_array($operand, [$operator, AbstractRule::findSymbolicOperator($operator)]); |
|
| 337 | 337 | } |
| 338 | 338 | ); |
| 339 | 339 | |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | foreach ($operands_descriptions as $i => $operands_description) { |
| 350 | 350 | if (false === $operands_description) { |
| 351 | - $operands_descriptions[ $i ] = ['and']; // FalseRule hack |
|
| 351 | + $operands_descriptions[$i] = ['and']; // FalseRule hack |
|
| 352 | 352 | } |
| 353 | 353 | elseif (null === $operands_description || true === $operands_description) { |
| 354 | 354 | $operands_description = ['and']; |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | ); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - unset($operands_descriptions[ $i ]); |
|
| 362 | + unset($operands_descriptions[$i]); |
|
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | 365 | |
@@ -373,11 +373,11 @@ discard block |
||
| 373 | 373 | } |
| 374 | 374 | ); |
| 375 | 375 | |
| 376 | - if (! empty($remaining_operations)) { |
|
| 376 | + if ( ! empty($remaining_operations)) { |
|
| 377 | 377 | throw new \InvalidArgumentException( |
| 378 | 378 | "Mixing different operations in the same rule level not implemented: \n[" |
| 379 | 379 | . implode(', ', $remaining_operations)."]\n" |
| 380 | - . 'in ' . var_export($rules_composition, true) |
|
| 380 | + . 'in '.var_export($rules_composition, true) |
|
| 381 | 381 | ); |
| 382 | 382 | } |
| 383 | 383 | |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | } |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - $recursion_position->addOperand( $rule ); |
|
| 406 | + $recursion_position->addOperand($rule); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | return $this; |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | */ |
| 433 | 433 | public function and_() |
| 434 | 434 | { |
| 435 | - $this->addRules( AndRule::operator, func_get_args()); |
|
| 435 | + $this->addRules(AndRule::operator, func_get_args()); |
|
| 436 | 436 | return $this; |
| 437 | 437 | } |
| 438 | 438 | |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | */ |
| 461 | 461 | public function or_() |
| 462 | 462 | { |
| 463 | - $this->addRules( OrRule::operator, func_get_args()); |
|
| 463 | + $this->addRules(OrRule::operator, func_get_args()); |
|
| 464 | 464 | return $this; |
| 465 | 465 | } |
| 466 | 466 | |
@@ -507,12 +507,12 @@ discard block |
||
| 507 | 507 | * @param array $options stop_after | stop_before | |
| 508 | 508 | * @return $this |
| 509 | 509 | */ |
| 510 | - public function simplify($options=[]) |
|
| 510 | + public function simplify($options = []) |
|
| 511 | 511 | { |
| 512 | 512 | if ($this->rules) { |
| 513 | 513 | // AndRule added to make all Operation methods available |
| 514 | 514 | $this->rules = (new AndRule([$this->rules])) |
| 515 | - ->simplify( $options ) |
|
| 515 | + ->simplify($options) |
|
| 516 | 516 | // ->dump(true, false) |
| 517 | 517 | ; |
| 518 | 518 | } |
@@ -555,9 +555,9 @@ discard block |
||
| 555 | 555 | * |
| 556 | 556 | * @return bool |
| 557 | 557 | */ |
| 558 | - public function hasSolution($save_simplification=true) |
|
| 558 | + public function hasSolution($save_simplification = true) |
|
| 559 | 559 | { |
| 560 | - if (! $this->rules) { |
|
| 560 | + if ( ! $this->rules) { |
|
| 561 | 561 | return true; |
| 562 | 562 | } |
| 563 | 563 | |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | * |
| 577 | 577 | * @return array A description of the rules. |
| 578 | 578 | */ |
| 579 | - public function toArray(array $options=[]) |
|
| 579 | + public function toArray(array $options = []) |
|
| 580 | 580 | { |
| 581 | 581 | return $this->rules ? $this->rules->toArray($options) : $this->rules; |
| 582 | 582 | } |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | * |
| 589 | 589 | * @return array A description of the rules. |
| 590 | 590 | */ |
| 591 | - public function toString(array $options=[]) |
|
| 591 | + public function toString(array $options = []) |
|
| 592 | 592 | { |
| 593 | 593 | return $this->rules ? $this->rules->toString($options) : $this->rules; |
| 594 | 594 | } |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | * @param mixed $row |
| 627 | 627 | * @return bool |
| 628 | 628 | */ |
| 629 | - public function __invoke($row, $key=null) |
|
| 629 | + public function __invoke($row, $key = null) |
|
| 630 | 630 | { |
| 631 | 631 | return $this->validates($row, $key); |
| 632 | 632 | } |
@@ -673,8 +673,8 @@ discard block |
||
| 673 | 673 | [ |
| 674 | 674 | Filterer::on_row_matches => function($rule, $key, &$rows, $matching_case) use (&$cache_flush_required) { |
| 675 | 675 | // $rule->dump(); |
| 676 | - unset( $rows[$key] ); |
|
| 677 | - if (! $rows ) { |
|
| 676 | + unset($rows[$key]); |
|
| 677 | + if ( ! $rows) { |
|
| 678 | 678 | throw new \Exception( |
| 679 | 679 | "Removing the only rule $rule from the filter $this " |
| 680 | 680 | ."produces a case which has no possible solution due to missing " |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * |
| 709 | 709 | * @return array The rules matching the filter |
| 710 | 710 | */ |
| 711 | - public function filterRules($rule_filter=[], array $options=[]) |
|
| 711 | + public function filterRules($rule_filter = [], array $options = []) |
|
| 712 | 712 | { |
| 713 | 713 | $filter = (new LogicalFilter($rule_filter, new RuleFilterer)) |
| 714 | 714 | // ->dump() |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | * @return array The rules matching the filter |
| 733 | 733 | * @return array $options debug | leaves_only | clean_empty_branches |
| 734 | 734 | */ |
| 735 | - public function keepLeafRulesMatching($filter=[], array $options=[]) |
|
| 735 | + public function keepLeafRulesMatching($filter = [], array $options = []) |
|
| 736 | 736 | { |
| 737 | 737 | $clean_empty_branches = ! isset($options['clean_empty_branches']) || $options['clean_empty_branches']; |
| 738 | 738 | |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | // ->dump() |
| 741 | 741 | ; |
| 742 | 742 | |
| 743 | - $options[ Filterer::leaves_only ] = true; |
|
| 743 | + $options[Filterer::leaves_only] = true; |
|
| 744 | 744 | |
| 745 | 745 | $this->rules = (new RuleFilterer)->apply($filter, $this->rules, $options); |
| 746 | 746 | // $this->rules->dump(true); |
@@ -780,13 +780,13 @@ discard block |
||
| 780 | 780 | * |
| 781 | 781 | * @todo Merge with rules |
| 782 | 782 | */ |
| 783 | - public function listLeafRulesMatching($filter=[]) |
|
| 783 | + public function listLeafRulesMatching($filter = []) |
|
| 784 | 784 | { |
| 785 | 785 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
| 786 | 786 | // ->dump() |
| 787 | 787 | ; |
| 788 | 788 | |
| 789 | - if (! $this->rules) { |
|
| 789 | + if ( ! $this->rules) { |
|
| 790 | 790 | return []; |
| 791 | 791 | } |
| 792 | 792 | |
@@ -800,7 +800,7 @@ discard block |
||
| 800 | 800 | $key, |
| 801 | 801 | array $siblings |
| 802 | 802 | ) use (&$out) { |
| 803 | - if ( ! $matching_rule instanceof AndRule |
|
| 803 | + if ( ! $matching_rule instanceof AndRule |
|
| 804 | 804 | && ! $matching_rule instanceof OrRule |
| 805 | 805 | && ! $matching_rule instanceof NotRule |
| 806 | 806 | ) { |
@@ -841,13 +841,13 @@ discard block |
||
| 841 | 841 | * |
| 842 | 842 | * @return array The rules matching the filter |
| 843 | 843 | */ |
| 844 | - public function onEachRule($filter=[], $options) |
|
| 844 | + public function onEachRule($filter = [], $options) |
|
| 845 | 845 | { |
| 846 | 846 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
| 847 | 847 | // ->dump() |
| 848 | 848 | ; |
| 849 | 849 | |
| 850 | - if (! $this->rules) { |
|
| 850 | + if ( ! $this->rules) { |
|
| 851 | 851 | return []; |
| 852 | 852 | } |
| 853 | 853 | |
@@ -880,7 +880,7 @@ discard block |
||
| 880 | 880 | { |
| 881 | 881 | $this->simplify()->addMinimalCase(); |
| 882 | 882 | |
| 883 | - if (! $this->rules) { |
|
| 883 | + if ( ! $this->rules) { |
|
| 884 | 884 | return $this; |
| 885 | 885 | } |
| 886 | 886 | |
@@ -906,11 +906,11 @@ discard block |
||
| 906 | 906 | * |
| 907 | 907 | * @return array The bounds of the range and a nullable property for each field |
| 908 | 908 | */ |
| 909 | - public function getRanges($ruleFilter=null) |
|
| 909 | + public function getRanges($ruleFilter = null) |
|
| 910 | 910 | { |
| 911 | 911 | $ranges = []; |
| 912 | 912 | |
| 913 | - $this->onEachCase(function (AndRule $and_rule) use (&$ranges, $ruleFilter) { |
|
| 913 | + $this->onEachCase(function(AndRule $and_rule) use (&$ranges, $ruleFilter) { |
|
| 914 | 914 | (new self($and_rule))->onEachRule( |
| 915 | 915 | ['and', |
| 916 | 916 | $ruleFilter, |
@@ -919,12 +919,12 @@ discard block |
||
| 919 | 919 | '><', '><=', '=><=', '=><', |
| 920 | 920 | ]], |
| 921 | 921 | ], |
| 922 | - function ($rule) use (&$ranges) { |
|
| 922 | + function($rule) use (&$ranges) { |
|
| 923 | 923 | |
| 924 | 924 | $field = $rule->getField(); |
| 925 | 925 | |
| 926 | - $range = isset($ranges[ $field ]) |
|
| 927 | - ? $ranges[ $field ] |
|
| 926 | + $range = isset($ranges[$field]) |
|
| 927 | + ? $ranges[$field] |
|
| 928 | 928 | : ['min' => [], 'max' => [], 'nullable' => false]; |
| 929 | 929 | |
| 930 | 930 | if ($rule::operator == '=') { |
@@ -952,7 +952,7 @@ discard block |
||
| 952 | 952 | ); |
| 953 | 953 | } |
| 954 | 954 | |
| 955 | - $ranges[ $field ] = $range; |
|
| 955 | + $ranges[$field] = $range; |
|
| 956 | 956 | } |
| 957 | 957 | ); |
| 958 | 958 | }); |
@@ -1006,7 +1006,7 @@ discard block |
||
| 1006 | 1006 | * |
| 1007 | 1007 | * @return LogicalFilter |
| 1008 | 1008 | */ |
| 1009 | - public function saveAs( &$variable) |
|
| 1009 | + public function saveAs(&$variable) |
|
| 1010 | 1010 | { |
| 1011 | 1011 | return $variable = $this; |
| 1012 | 1012 | } |
@@ -1017,7 +1017,7 @@ discard block |
||
| 1017 | 1017 | * |
| 1018 | 1018 | * @return LogicalFilter |
| 1019 | 1019 | */ |
| 1020 | - public function saveCopyAs( &$copied_variable) |
|
| 1020 | + public function saveCopyAs(&$copied_variable) |
|
| 1021 | 1021 | { |
| 1022 | 1022 | $copied_variable = $this->copy(); |
| 1023 | 1023 | return $this; |
@@ -1030,15 +1030,15 @@ discard block |
||
| 1030 | 1030 | * |
| 1031 | 1031 | * @return $this |
| 1032 | 1032 | */ |
| 1033 | - public function dump($exit=false, array $options=[]) |
|
| 1033 | + public function dump($exit = false, array $options = []) |
|
| 1034 | 1034 | { |
| 1035 | 1035 | $default_options = [ |
| 1036 | 1036 | 'callstack_depth' => 3, |
| 1037 | 1037 | 'mode' => 'string', |
| 1038 | 1038 | ]; |
| 1039 | 1039 | foreach ($default_options as $default_option => &$default_value) { |
| 1040 | - if (! isset($options[ $default_option ])) { |
|
| 1041 | - $options[ $default_option ] = $default_value; |
|
| 1040 | + if ( ! isset($options[$default_option])) { |
|
| 1041 | + $options[$default_option] = $default_value; |
|
| 1042 | 1042 | } |
| 1043 | 1043 | } |
| 1044 | 1044 | extract($options); |
@@ -1049,24 +1049,24 @@ discard block |
||
| 1049 | 1049 | else { |
| 1050 | 1050 | // TODO dump a TrueRule |
| 1051 | 1051 | $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth); |
| 1052 | - $caller = $bt[ $callstack_depth - 2 ]; |
|
| 1052 | + $caller = $bt[$callstack_depth - 2]; |
|
| 1053 | 1053 | |
| 1054 | 1054 | // get line and file from the previous level of the caller |
| 1055 | 1055 | // TODO go deeper if this case exist? |
| 1056 | - if (! isset($caller['file'])) { |
|
| 1057 | - $caller['file'] = $bt[ $callstack_depth - 3 ]['file']; |
|
| 1056 | + if ( ! isset($caller['file'])) { |
|
| 1057 | + $caller['file'] = $bt[$callstack_depth - 3]['file']; |
|
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | - if (! isset($caller['line'])) { |
|
| 1061 | - $caller['line'] = $bt[ $callstack_depth - 3 ]['line']; |
|
| 1060 | + if ( ! isset($caller['line'])) { |
|
| 1061 | + $caller['line'] = $bt[$callstack_depth - 3]['line']; |
|
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | try { |
| 1065 | - echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n"; |
|
| 1065 | + echo "\n".$caller['file'].':'.$caller['line']."\n"; |
|
| 1066 | 1066 | var_export($this->toArray($options)); |
| 1067 | 1067 | } |
| 1068 | 1068 | catch (\Exception $e) { |
| 1069 | - echo "\nError while dumping: " . $e->getMessage() . "\n"; |
|
| 1069 | + echo "\nError while dumping: ".$e->getMessage()."\n"; |
|
| 1070 | 1070 | var_export($caller); |
| 1071 | 1071 | echo "\n\n"; |
| 1072 | 1072 | var_export($bt); |
@@ -1091,15 +1091,15 @@ discard block |
||
| 1091 | 1091 | * |
| 1092 | 1092 | * @return mixed The filtered data |
| 1093 | 1093 | */ |
| 1094 | - public function applyOn($data_to_filter, $action_on_matches=null, $filterer=null) |
|
| 1094 | + public function applyOn($data_to_filter, $action_on_matches = null, $filterer = null) |
|
| 1095 | 1095 | { |
| 1096 | - if (! $filterer) { |
|
| 1096 | + if ( ! $filterer) { |
|
| 1097 | 1097 | $filterer = $this->getDefaultFilterer(); |
| 1098 | 1098 | } |
| 1099 | 1099 | elseif (is_callable($filterer)) { |
| 1100 | 1100 | $filterer = new CustomizableFilterer($filterer); |
| 1101 | 1101 | } |
| 1102 | - elseif (! $filterer instanceof Filterer) { |
|
| 1102 | + elseif ( ! $filterer instanceof Filterer) { |
|
| 1103 | 1103 | throw new \InvalidArgumentException( |
| 1104 | 1104 | "The given \$filterer must be null or a callable or a instance " |
| 1105 | 1105 | ."of Filterer instead of: ".var_export($filterer, true) |
@@ -1107,8 +1107,8 @@ discard block |
||
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | if ($data_to_filter instanceof LogicalFilter) { |
| 1110 | - $filtered_rules = $filterer->apply( $this, $data_to_filter->getRules() ); |
|
| 1111 | - return $data_to_filter->flushRules()->addRule( $filtered_rules ); |
|
| 1110 | + $filtered_rules = $filterer->apply($this, $data_to_filter->getRules()); |
|
| 1111 | + return $data_to_filter->flushRules()->addRule($filtered_rules); |
|
| 1112 | 1112 | } |
| 1113 | 1113 | else { |
| 1114 | 1114 | return $filterer->apply($this, $data_to_filter); |
@@ -1126,15 +1126,15 @@ discard block |
||
| 1126 | 1126 | * + Null if the target has no sens (operation filtered by field for example) |
| 1127 | 1127 | * + A rule tree containing the first matching case if there is one. |
| 1128 | 1128 | */ |
| 1129 | - public function validates($value_to_check, $key_to_check=null, $filterer=null) |
|
| 1129 | + public function validates($value_to_check, $key_to_check = null, $filterer = null) |
|
| 1130 | 1130 | { |
| 1131 | - if (! $filterer) { |
|
| 1131 | + if ( ! $filterer) { |
|
| 1132 | 1132 | $filterer = $this->getDefaultFilterer(); |
| 1133 | 1133 | } |
| 1134 | 1134 | elseif (is_callable($filterer)) { |
| 1135 | 1135 | $filterer = new CustomizableFilterer($filterer); |
| 1136 | 1136 | } |
| 1137 | - elseif (! $filterer instanceof Filterer) { |
|
| 1137 | + elseif ( ! $filterer instanceof Filterer) { |
|
| 1138 | 1138 | throw new \InvalidArgumentException( |
| 1139 | 1139 | "The given \$filterer must be null or a callable or a instance " |
| 1140 | 1140 | ."of Filterer instead of: ".var_export($filterer, true) |
@@ -58,7 +58,6 @@ |
||
| 58 | 58 | * Checks if a variable contains a value which can be considered |
| 59 | 59 | * as a left value of a rule. |
| 60 | 60 | * |
| 61 | - * @param scalar|FilteredKey|FilteredValue $operator |
|
| 62 | 61 | * @return bool |
| 63 | 62 | */ |
| 64 | 63 | public static function isLeftOperand($left_operand) |
@@ -38,17 +38,17 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public static function isOperator($operator) |
| 40 | 40 | { |
| 41 | - if (! is_string($operator)) { |
|
| 41 | + if ( ! is_string($operator)) { |
|
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if (isset(self::$ruleAliases[ $operator ])) { |
|
| 45 | + if (isset(self::$ruleAliases[$operator])) { |
|
| 46 | 46 | return true; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - $association = array_flip( self::$ruleAliases ); |
|
| 50 | - if (isset($association[ $operator ])) { |
|
| 51 | - return $association[ $operator ]; |
|
| 49 | + $association = array_flip(self::$ruleAliases); |
|
| 50 | + if (isset($association[$operator])) { |
|
| 51 | + return $association[$operator]; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | return false; |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public static function findSymbolicOperator($english_operator) |
| 77 | 77 | { |
| 78 | - $association = array_flip( self::$ruleAliases ); |
|
| 79 | - if (isset($association[ $english_operator ])) { |
|
| 80 | - return $association[ $english_operator ]; |
|
| 78 | + $association = array_flip(self::$ruleAliases); |
|
| 79 | + if (isset($association[$english_operator])) { |
|
| 80 | + return $association[$english_operator]; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | return $english_operator; |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | public static function findEnglishOperator($symbolic_operator) |
| 91 | 91 | { |
| 92 | 92 | $association = self::$ruleAliases; |
| 93 | - if (isset($association[ $symbolic_operator ])) { |
|
| 94 | - return $association[ $symbolic_operator ]; |
|
| 93 | + if (isset($association[$symbolic_operator])) { |
|
| 94 | + return $association[$symbolic_operator]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return $symbolic_operator; |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @return AbstractRule |
| 108 | 108 | */ |
| 109 | - public static function generateSimpleRule($field, $type, $values, array $options=[]) |
|
| 109 | + public static function generateSimpleRule($field, $type, $values, array $options = []) |
|
| 110 | 110 | { |
| 111 | - $cache_key = hash('md4', serialize( func_get_args()) ); |
|
| 111 | + $cache_key = hash('md4', serialize(func_get_args())); |
|
| 112 | 112 | if (isset(self::$static_cache['rules_generation'][$cache_key])) { |
| 113 | 113 | return self::$static_cache['rules_generation'][$cache_key]->copy(); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | $ruleClass = self::getRuleClass($type); |
| 117 | 117 | |
| 118 | - return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass( $field, $values, $options ); |
|
| 118 | + return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass($field, $values, $options); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | . str_replace('_', '', ucwords($english_rule_operator, '_')) |
| 133 | 133 | . 'Rule'; |
| 134 | 134 | |
| 135 | - if ( ! class_exists( $rule_class)) { |
|
| 135 | + if ( ! class_exists($rule_class)) { |
|
| 136 | 136 | throw new \InvalidArgumentException( |
| 137 | 137 | "The class '$rule_class' corresponding to the operator " |
| 138 | 138 | ."'$rule_operator' / '$english_rule_operator' cannot be found." |