@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @see self::addRules |
53 | 53 | */ |
54 | - public function __construct($rules=[], Filterer $default_filterer=null, array $options=[]) |
|
54 | + public function __construct($rules = [], Filterer $default_filterer = null, array $options = []) |
|
55 | 55 | { |
56 | 56 | if ($rules instanceof AbstractRule) { |
57 | 57 | $rules = $rules->copy(); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | if ($rules) { |
75 | - $this->and_( $rules ); |
|
75 | + $this->and_($rules); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @param array $rules_description Rules description |
139 | 139 | * @return LogicalFilter $this |
140 | 140 | */ |
141 | - protected function addRules( $operation, array $rules_description ) |
|
141 | + protected function addRules($operation, array $rules_description) |
|
142 | 142 | { |
143 | 143 | if ($rules_description == [null]) { |
144 | 144 | // TODO this is due to the bad design of using "Null" instead of |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | - if ( 3 == count($rules_description) |
|
164 | + if (3 == count($rules_description) |
|
165 | 165 | && is_string($rules_description[0]) |
166 | 166 | && is_string($rules_description[1]) |
167 | 167 | ) { |
@@ -177,30 +177,30 @@ discard block |
||
177 | 177 | } |
178 | 178 | elseif (count($rules_description) == count(array_filter($rules_description, function($arg) { |
179 | 179 | return $arg instanceof LogicalFilter; |
180 | - })) ) { |
|
180 | + }))) { |
|
181 | 181 | // Already instanciated rules |
182 | 182 | foreach ($rules_description as $i => $filter) { |
183 | 183 | $rules = $filter->getRules(); |
184 | 184 | if (null !== $rules) { |
185 | - $this->addRule( $rules, $operation); |
|
185 | + $this->addRule($rules, $operation); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | } |
189 | 189 | elseif (count($rules_description) == count(array_filter($rules_description, function($arg) { |
190 | 190 | return $arg instanceof AbstractRule; |
191 | - })) ) { |
|
191 | + }))) { |
|
192 | 192 | // Already instanciated rules |
193 | 193 | foreach ($rules_description as $i => $new_rule) { |
194 | - $this->addRule( $new_rule, $operation); |
|
194 | + $this->addRule($new_rule, $operation); |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 | elseif (1 == count($rules_description) && is_array($rules_description[0])) { |
198 | 198 | if (count($rules_description[0]) == count(array_filter($rules_description[0], function($arg) { |
199 | 199 | return $arg instanceof AbstractRule; |
200 | - })) ) { |
|
200 | + }))) { |
|
201 | 201 | // Case of $filter->or_([AbstractRule, AbstractRule, AbstractRule, ...]) |
202 | 202 | foreach ($rules_description[0] as $i => $new_rule) { |
203 | - $this->addRule( $new_rule, $operation ); |
|
203 | + $this->addRule($new_rule, $operation); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | else { |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | $fake_root |
212 | 212 | ); |
213 | 213 | |
214 | - $this->addRule( $fake_root->getOperands()[0], $operation ); |
|
214 | + $this->addRule($fake_root->getOperands()[0], $operation); |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | else { |
@@ -232,10 +232,10 @@ discard block |
||
232 | 232 | * |
233 | 233 | * @return $this |
234 | 234 | */ |
235 | - protected function addRule( AbstractRule $rule, $operation=AndRule::operator ) |
|
235 | + protected function addRule(AbstractRule $rule, $operation = AndRule::operator) |
|
236 | 236 | { |
237 | - if ( $this->rules && in_array( get_class($this->rules), [AndRule::class, OrRule::class] ) |
|
238 | - && ! $this->rules->getOperands() ) { |
|
237 | + if ($this->rules && in_array(get_class($this->rules), [AndRule::class, OrRule::class]) |
|
238 | + && ! $this->rules->getOperands()) { |
|
239 | 239 | throw new \LogicException( |
240 | 240 | "You are trying to add rules to a LogicalFilter which had " |
241 | 241 | ."only contradictory rules that have already been simplified: " |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | array $rules_composition, |
285 | 285 | AbstractOperationRule $recursion_position |
286 | 286 | ) { |
287 | - if ( ! array_filter($rules_composition, function ($rule_composition_part) { |
|
287 | + if ( ! array_filter($rules_composition, function($rule_composition_part) { |
|
288 | 288 | return is_string($rule_composition_part); |
289 | 289 | })) { |
290 | 290 | // at least one operator is required for operation rules |
@@ -293,13 +293,13 @@ discard block |
||
293 | 293 | .var_export($rules_composition, true) |
294 | 294 | ); |
295 | 295 | } |
296 | - elseif ( 3 == count($rules_composition) |
|
297 | - && ! in_array( AndRule::operator, $rules_composition, true ) |
|
298 | - && ! in_array( OrRule::operator, $rules_composition, true ) |
|
299 | - && ! in_array( NotRule::operator, $rules_composition, true ) |
|
300 | - && ! in_array( AbstractRule::findSymbolicOperator( AndRule::operator ), $rules_composition, true ) |
|
301 | - && ! in_array( AbstractRule::findSymbolicOperator( OrRule::operator ), $rules_composition, true ) |
|
302 | - && ! in_array( AbstractRule::findSymbolicOperator( NotRule::operator ), $rules_composition, true ) |
|
296 | + elseif (3 == count($rules_composition) |
|
297 | + && ! in_array(AndRule::operator, $rules_composition, true) |
|
298 | + && ! in_array(OrRule::operator, $rules_composition, true) |
|
299 | + && ! in_array(NotRule::operator, $rules_composition, true) |
|
300 | + && ! in_array(AbstractRule::findSymbolicOperator(AndRule::operator), $rules_composition, true) |
|
301 | + && ! in_array(AbstractRule::findSymbolicOperator(OrRule::operator), $rules_composition, true) |
|
302 | + && ! in_array(AbstractRule::findSymbolicOperator(NotRule::operator), $rules_composition, true) |
|
303 | 303 | ) { |
304 | 304 | // atomic or composit rules |
305 | 305 | $operand_left = $rules_composition[0]; |
@@ -309,20 +309,20 @@ discard block |
||
309 | 309 | $rule = AbstractRule::generateSimpleRule( |
310 | 310 | $operand_left, $operation, $operand_right, $this->getOptions() |
311 | 311 | ); |
312 | - $recursion_position->addOperand( $rule ); |
|
312 | + $recursion_position->addOperand($rule); |
|
313 | 313 | } |
314 | 314 | else { |
315 | 315 | // operations |
316 | - if ( NotRule::operator == $rules_composition[0] |
|
317 | - || $rules_composition[0] == AbstractRule::findSymbolicOperator( NotRule::operator ) ) { |
|
316 | + if (NotRule::operator == $rules_composition[0] |
|
317 | + || $rules_composition[0] == AbstractRule::findSymbolicOperator(NotRule::operator)) { |
|
318 | 318 | $rule = new NotRule(); |
319 | 319 | } |
320 | - elseif (in_array( AndRule::operator, $rules_composition ) |
|
321 | - || in_array( AbstractRule::findSymbolicOperator( AndRule::operator ), $rules_composition )) { |
|
320 | + elseif (in_array(AndRule::operator, $rules_composition) |
|
321 | + || in_array(AbstractRule::findSymbolicOperator(AndRule::operator), $rules_composition)) { |
|
322 | 322 | $rule = new AndRule(); |
323 | 323 | } |
324 | - elseif (in_array( OrRule::operator, $rules_composition ) |
|
325 | - || in_array( AbstractRule::findSymbolicOperator( OrRule::operator ), $rules_composition ) ) { |
|
324 | + elseif (in_array(OrRule::operator, $rules_composition) |
|
325 | + || in_array(AbstractRule::findSymbolicOperator(OrRule::operator), $rules_composition)) { |
|
326 | 326 | $rule = new OrRule(); |
327 | 327 | } |
328 | 328 | else { |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | |
337 | 337 | $operands_descriptions = array_filter( |
338 | 338 | $rules_composition, |
339 | - function ($operand) use ($operator) { |
|
340 | - return ! in_array($operand, [$operator, AbstractRule::findSymbolicOperator( $operator )]); |
|
339 | + function($operand) use ($operator) { |
|
340 | + return ! in_array($operand, [$operator, AbstractRule::findSymbolicOperator($operator)]); |
|
341 | 341 | } |
342 | 342 | ); |
343 | 343 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | |
353 | 353 | foreach ($operands_descriptions as $i => $operands_description) { |
354 | 354 | if (false === $operands_description) { |
355 | - $operands_descriptions[ $i ] = ['and']; // FalseRule hack |
|
355 | + $operands_descriptions[$i] = ['and']; // FalseRule hack |
|
356 | 356 | } |
357 | 357 | elseif (null === $operands_description || true === $operands_description) { |
358 | 358 | $operands_description = ['and']; |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | ); |
364 | 364 | } |
365 | 365 | |
366 | - unset($operands_descriptions[ $i ]); |
|
366 | + unset($operands_descriptions[$i]); |
|
367 | 367 | } |
368 | 368 | } |
369 | 369 | |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | throw new \InvalidArgumentException( |
382 | 382 | "Mixing different operations in the same rule level not implemented: \n[" |
383 | 383 | . implode(', ', $remaining_operations)."]\n" |
384 | - . 'in ' . var_export($rules_composition, true) |
|
384 | + . 'in '.var_export($rules_composition, true) |
|
385 | 385 | ); |
386 | 386 | } |
387 | 387 | |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | - $recursion_position->addOperand( $rule ); |
|
410 | + $recursion_position->addOperand($rule); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | return $this; |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | */ |
437 | 437 | public function and_() |
438 | 438 | { |
439 | - $this->addRules( AndRule::operator, func_get_args()); |
|
439 | + $this->addRules(AndRule::operator, func_get_args()); |
|
440 | 440 | return $this; |
441 | 441 | } |
442 | 442 | |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | */ |
465 | 465 | public function or_() |
466 | 466 | { |
467 | - $this->addRules( OrRule::operator, func_get_args()); |
|
467 | + $this->addRules(OrRule::operator, func_get_args()); |
|
468 | 468 | return $this; |
469 | 469 | } |
470 | 470 | |
@@ -511,12 +511,12 @@ discard block |
||
511 | 511 | * @param array $options stop_after | stop_before | |
512 | 512 | * @return $this |
513 | 513 | */ |
514 | - public function simplify($options=[]) |
|
514 | + public function simplify($options = []) |
|
515 | 515 | { |
516 | 516 | if ($this->rules) { |
517 | 517 | // AndRule added to make all Operation methods available |
518 | 518 | $this->rules = (new AndRule([$this->rules])) |
519 | - ->simplify( $options ) |
|
519 | + ->simplify($options) |
|
520 | 520 | // ->dump(true, false) |
521 | 521 | ; |
522 | 522 | } |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | * |
538 | 538 | * @return bool |
539 | 539 | */ |
540 | - public function hasSolution($save_simplification=true) |
|
540 | + public function hasSolution($save_simplification = true) |
|
541 | 541 | { |
542 | 542 | if ( ! $this->rules) { |
543 | 543 | return true; |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | * |
559 | 559 | * @return array A description of the rules. |
560 | 560 | */ |
561 | - public function toArray(array $options=[]) |
|
561 | + public function toArray(array $options = []) |
|
562 | 562 | { |
563 | 563 | return $this->rules ? $this->rules->toArray($options) : $this->rules; |
564 | 564 | } |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | * |
571 | 571 | * @return array A description of the rules. |
572 | 572 | */ |
573 | - public function toString(array $options=[]) |
|
573 | + public function toString(array $options = []) |
|
574 | 574 | { |
575 | 575 | return $this->rules ? $this->rules->toString($options) : $this->rules; |
576 | 576 | } |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | * @param mixed $row |
609 | 609 | * @return bool |
610 | 610 | */ |
611 | - public function __invoke($row, $key=null) |
|
611 | + public function __invoke($row, $key = null) |
|
612 | 612 | { |
613 | 613 | return $this->validates($row, $key); |
614 | 614 | } |
@@ -658,8 +658,8 @@ discard block |
||
658 | 658 | [ |
659 | 659 | Filterer::on_row_matches => function($rule, $key, &$rows, $matching_case) use (&$cache_flush_required) { |
660 | 660 | // $rule->dump(); |
661 | - unset( $rows[$key] ); |
|
662 | - if ( ! $rows ) { |
|
661 | + unset($rows[$key]); |
|
662 | + if ( ! $rows) { |
|
663 | 663 | throw new \Exception( |
664 | 664 | "Removing the only rule $rule from the filter $this " |
665 | 665 | ."produces a case which has no possible solution due to missing " |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | * |
696 | 696 | * @todo Merge with rules |
697 | 697 | */ |
698 | - public function keepLeafRulesMatching($filter=[], array $options=[]) |
|
698 | + public function keepLeafRulesMatching($filter = [], array $options = []) |
|
699 | 699 | { |
700 | 700 | $clean_empty_branches = ! isset($options['clean_empty_branches']) || $options['clean_empty_branches']; |
701 | 701 | |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | // ->dump() |
704 | 704 | ; |
705 | 705 | |
706 | - $options[ Filterer::leaves_only ] = true; |
|
706 | + $options[Filterer::leaves_only] = true; |
|
707 | 707 | |
708 | 708 | $this->rules = (new RuleFilterer)->apply($filter, $this->rules, $options); |
709 | 709 | // $this->rules->dump(true); |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | $this->rules, |
719 | 719 | [ |
720 | 720 | Filterer::on_row_matches => function($rule, $key, &$rows) { |
721 | - unset( $rows[$key] ); |
|
721 | + unset($rows[$key]); |
|
722 | 722 | }, |
723 | 723 | Filterer::on_row_mismatches => function($rule, $key, &$rows) { |
724 | 724 | }, |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | * |
744 | 744 | * @todo Merge with rules |
745 | 745 | */ |
746 | - public function listLeafRulesMatching($filter=[]) |
|
746 | + public function listLeafRulesMatching($filter = []) |
|
747 | 747 | { |
748 | 748 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
749 | 749 | // ->dump() |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | $key, |
764 | 764 | array $siblings |
765 | 765 | ) use (&$out) { |
766 | - if ( ! $matching_rule instanceof AndRule |
|
766 | + if ( ! $matching_rule instanceof AndRule |
|
767 | 767 | && ! $matching_rule instanceof OrRule |
768 | 768 | && ! $matching_rule instanceof NotRule |
769 | 769 | ) { |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | * |
787 | 787 | * @todo Make it available on AbstractRule also |
788 | 788 | */ |
789 | - public function onEachRule($filter=[], $options) |
|
789 | + public function onEachRule($filter = [], $options) |
|
790 | 790 | { |
791 | 791 | $filter = (new LogicalFilter($filter, new RuleFilterer)) |
792 | 792 | // ->dump() |
@@ -862,7 +862,7 @@ discard block |
||
862 | 862 | * |
863 | 863 | * @return LogicalFilter |
864 | 864 | */ |
865 | - public function saveAs( &$variable ) |
|
865 | + public function saveAs(&$variable) |
|
866 | 866 | { |
867 | 867 | return $variable = $this; |
868 | 868 | } |
@@ -873,7 +873,7 @@ discard block |
||
873 | 873 | * |
874 | 874 | * @return LogicalFilter |
875 | 875 | */ |
876 | - public function saveCopyAs( &$copied_variable ) |
|
876 | + public function saveCopyAs(&$copied_variable) |
|
877 | 877 | { |
878 | 878 | $copied_variable = $this->copy(); |
879 | 879 | return $this; |
@@ -886,15 +886,15 @@ discard block |
||
886 | 886 | * |
887 | 887 | * @return $this |
888 | 888 | */ |
889 | - public function dump($exit=false, array $options=[]) |
|
889 | + public function dump($exit = false, array $options = []) |
|
890 | 890 | { |
891 | 891 | $default_options = [ |
892 | 892 | 'callstack_depth' => 3, |
893 | 893 | 'mode' => 'string', |
894 | 894 | ]; |
895 | 895 | foreach ($default_options as $default_option => &$default_value) { |
896 | - if ( ! isset($options[ $default_option ])) { |
|
897 | - $options[ $default_option ] = $default_value; |
|
896 | + if ( ! isset($options[$default_option])) { |
|
897 | + $options[$default_option] = $default_value; |
|
898 | 898 | } |
899 | 899 | } |
900 | 900 | extract($options); |
@@ -905,23 +905,23 @@ discard block |
||
905 | 905 | else { |
906 | 906 | // TODO dump a TrueRule |
907 | 907 | $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth); |
908 | - $caller = $bt[ $callstack_depth - 2 ]; |
|
908 | + $caller = $bt[$callstack_depth - 2]; |
|
909 | 909 | |
910 | 910 | // get line and file from the previous level of the caller |
911 | 911 | // TODO go deeper if this case exist? |
912 | 912 | if ( ! isset($caller['file'])) { |
913 | - $caller['file'] = $bt[ $callstack_depth - 3 ]['file']; |
|
913 | + $caller['file'] = $bt[$callstack_depth - 3]['file']; |
|
914 | 914 | } |
915 | 915 | if ( ! isset($caller['line'])) { |
916 | - $caller['line'] = $bt[ $callstack_depth - 3 ]['line']; |
|
916 | + $caller['line'] = $bt[$callstack_depth - 3]['line']; |
|
917 | 917 | } |
918 | 918 | |
919 | 919 | try { |
920 | - echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n"; |
|
920 | + echo "\n".$caller['file'].':'.$caller['line']."\n"; |
|
921 | 921 | var_export($this->toArray($options)); |
922 | 922 | } |
923 | 923 | catch (\Exception $e) { |
924 | - echo "\nError while dumping: " . $e->getMessage() . "\n"; |
|
924 | + echo "\nError while dumping: ".$e->getMessage()."\n"; |
|
925 | 925 | var_export($caller); |
926 | 926 | echo "\n\n"; |
927 | 927 | var_export($bt); |
@@ -946,7 +946,7 @@ discard block |
||
946 | 946 | * |
947 | 947 | * @return mixed The filtered data |
948 | 948 | */ |
949 | - public function applyOn($data_to_filter, $action_on_matches=null, $filterer=null) |
|
949 | + public function applyOn($data_to_filter, $action_on_matches = null, $filterer = null) |
|
950 | 950 | { |
951 | 951 | if ( ! $filterer) { |
952 | 952 | $filterer = $this->getDefaultFilterer(); |
@@ -962,11 +962,11 @@ discard block |
||
962 | 962 | } |
963 | 963 | |
964 | 964 | if ($data_to_filter instanceof LogicalFilter) { |
965 | - $filtered_rules = $filterer->apply( $this, $data_to_filter->getRules() ); |
|
966 | - return $data_to_filter->flushRules()->addRule( $filtered_rules ); |
|
965 | + $filtered_rules = $filterer->apply($this, $data_to_filter->getRules()); |
|
966 | + return $data_to_filter->flushRules()->addRule($filtered_rules); |
|
967 | 967 | } |
968 | 968 | else { |
969 | - return $filterer->apply( $this, $data_to_filter ); |
|
969 | + return $filterer->apply($this, $data_to_filter); |
|
970 | 970 | } |
971 | 971 | } |
972 | 972 | |
@@ -981,7 +981,7 @@ discard block |
||
981 | 981 | * + Null if the target has no sens (operation filtered by field for example) |
982 | 982 | * + A rule tree containing the first matching case if there is one. |
983 | 983 | */ |
984 | - public function validates($value_to_check, $key_to_check=null, $filterer=null) |
|
984 | + public function validates($value_to_check, $key_to_check = null, $filterer = null) |
|
985 | 985 | { |
986 | 986 | if ( ! $filterer) { |
987 | 987 | $filterer = $this->getDefaultFilterer(); |
@@ -996,7 +996,7 @@ discard block |
||
996 | 996 | ); |
997 | 997 | } |
998 | 998 | |
999 | - return $filterer->hasMatchingCase( $this, $value_to_check, $key_to_check ); |
|
999 | + return $filterer->hasMatchingCase($this, $value_to_check, $key_to_check); |
|
1000 | 1000 | } |
1001 | 1001 | |
1002 | 1002 | /**/ |