Passed
Push — master ( 747a40...d05d36 )
by Jean
03:35
created
src/LogicalFilter.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
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
             );
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
                     unset( $rows[$key] );
662 662
                     if ( ! $rows ) {
663 663
                         throw new \Exception(
664
-                             "Removing the only rule $rule from the filter $this "
664
+                                "Removing the only rule $rule from the filter $this "
665 665
                             ."produces a case which has no possible solution due to missing "
666 666
                             ."implementation of TrueRule.\n"
667 667
                             ."Please see: https://github.com/jclaveau/php-logical-filter/issues/59"
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
         }
983 983
         elseif (! $filterer instanceof Filterer) {
984 984
             throw new \InvalidArgumentException(
985
-                 "The given \$filterer must be null or a callable or a instance "
985
+                    "The given \$filterer must be null or a callable or a instance "
986 986
                 ."of Filterer instead of: ".var_export($filterer, true)
987 987
             );
988 988
         }
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
         }
1018 1018
         elseif (! $filterer instanceof Filterer) {
1019 1019
             throw new \InvalidArgumentException(
1020
-                 "The given \$filterer must be null or a callable or a instance "
1020
+                    "The given \$filterer must be null or a callable or a instance "
1021 1021
                 ."of Filterer instead of: ".var_export($filterer, true)
1022 1022
             );
1023 1023
         }
Please login to merge, or discard this patch.
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,13 +743,13 @@  discard block
 block discarded – undo
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()
750 750
         ;
751 751
 
752
-        if (! $this->rules) {
752
+        if ( ! $this->rules) {
753 753
             return [];
754 754
         }
755 755
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
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
                     ) {
@@ -804,13 +804,13 @@  discard block
 block discarded – undo
804 804
      *
805 805
      * @return array          The rules matching the filter
806 806
      */
807
-    public function onEachRule($filter=[], $options)
807
+    public function onEachRule($filter = [], $options)
808 808
     {
809 809
         $filter = (new LogicalFilter($filter, new RuleFilterer))
810 810
         // ->dump()
811 811
         ;
812 812
 
813
-        if (! $this->rules) {
813
+        if ( ! $this->rules) {
814 814
             return [];
815 815
         }
816 816
 
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
     {
844 844
         $this->simplify(['force_logical_core' => true]);
845 845
 
846
-        if (! $this->rules) {
846
+        if ( ! $this->rules) {
847 847
             return $this;
848 848
         }
849 849
 
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
      *
888 888
      * @return LogicalFilter
889 889
      */
890
-    public function saveAs( &$variable)
890
+    public function saveAs(&$variable)
891 891
     {
892 892
         return $variable = $this;
893 893
     }
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
      *
899 899
      * @return LogicalFilter
900 900
      */
901
-    public function saveCopyAs( &$copied_variable)
901
+    public function saveCopyAs(&$copied_variable)
902 902
     {
903 903
         $copied_variable = $this->copy();
904 904
         return $this;
@@ -911,15 +911,15 @@  discard block
 block discarded – undo
911 911
      *
912 912
      * @return $this
913 913
      */
914
-    public function dump($exit=false, array $options=[])
914
+    public function dump($exit = false, array $options = [])
915 915
     {
916 916
         $default_options = [
917 917
             'callstack_depth' => 3,
918 918
             'mode'            => 'string',
919 919
         ];
920 920
         foreach ($default_options as $default_option => &$default_value) {
921
-            if ( ! isset($options[ $default_option ])) {
922
-                $options[ $default_option ] = $default_value;
921
+            if ( ! isset($options[$default_option])) {
922
+                $options[$default_option] = $default_value;
923 923
             }
924 924
         }
925 925
         extract($options);
@@ -930,24 +930,24 @@  discard block
 block discarded – undo
930 930
         else {
931 931
             // TODO dump a TrueRule
932 932
             $bt     = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth);
933
-            $caller = $bt[ $callstack_depth - 2 ];
933
+            $caller = $bt[$callstack_depth - 2];
934 934
 
935 935
             // get line and file from the previous level of the caller
936 936
             // TODO go deeper if this case exist?
937
-            if (! isset($caller['file'])) {
938
-                $caller['file'] = $bt[ $callstack_depth - 3 ]['file'];
937
+            if ( ! isset($caller['file'])) {
938
+                $caller['file'] = $bt[$callstack_depth - 3]['file'];
939 939
             }
940 940
 
941
-            if (! isset($caller['line'])) {
942
-                $caller['line'] = $bt[ $callstack_depth - 3 ]['line'];
941
+            if ( ! isset($caller['line'])) {
942
+                $caller['line'] = $bt[$callstack_depth - 3]['line'];
943 943
             }
944 944
 
945 945
             try {
946
-                echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n";
946
+                echo "\n".$caller['file'].':'.$caller['line']."\n";
947 947
                 var_export($this->toArray($options));
948 948
             }
949 949
             catch (\Exception $e) {
950
-                echo "\nError while dumping: " . $e->getMessage() . "\n";
950
+                echo "\nError while dumping: ".$e->getMessage()."\n";
951 951
                 var_export($caller);
952 952
                 echo "\n\n";
953 953
                 var_export($bt);
@@ -972,15 +972,15 @@  discard block
 block discarded – undo
972 972
      *
973 973
      * @return mixed The filtered data
974 974
      */
975
-    public function applyOn($data_to_filter, $action_on_matches=null, $filterer=null)
975
+    public function applyOn($data_to_filter, $action_on_matches = null, $filterer = null)
976 976
     {
977
-        if (! $filterer) {
977
+        if ( ! $filterer) {
978 978
             $filterer = $this->getDefaultFilterer();
979 979
         }
980 980
         elseif (is_callable($filterer)) {
981 981
             $filterer = new CustomizableFilterer($filterer);
982 982
         }
983
-        elseif (! $filterer instanceof Filterer) {
983
+        elseif ( ! $filterer instanceof Filterer) {
984 984
             throw new \InvalidArgumentException(
985 985
                  "The given \$filterer must be null or a callable or a instance "
986 986
                 ."of Filterer instead of: ".var_export($filterer, true)
@@ -988,8 +988,8 @@  discard block
 block discarded – undo
988 988
         }
989 989
 
990 990
         if ($data_to_filter instanceof LogicalFilter) {
991
-            $filtered_rules = $filterer->apply( $this, $data_to_filter->getRules() );
992
-            return $data_to_filter->flushRules()->addRule( $filtered_rules );
991
+            $filtered_rules = $filterer->apply($this, $data_to_filter->getRules());
992
+            return $data_to_filter->flushRules()->addRule($filtered_rules);
993 993
         }
994 994
         else {
995 995
             return $filterer->apply($this, $data_to_filter);
@@ -1007,15 +1007,15 @@  discard block
 block discarded – undo
1007 1007
      *                                 + Null if the target has no sens (operation filtered by field for example)
1008 1008
      *                                 + A rule tree containing the first matching case if there is one.
1009 1009
      */
1010
-    public function validates($value_to_check, $key_to_check=null, $filterer=null)
1010
+    public function validates($value_to_check, $key_to_check = null, $filterer = null)
1011 1011
     {
1012
-        if (! $filterer) {
1012
+        if ( ! $filterer) {
1013 1013
             $filterer = $this->getDefaultFilterer();
1014 1014
         }
1015 1015
         elseif (is_callable($filterer)) {
1016 1016
             $filterer = new CustomizableFilterer($filterer);
1017 1017
         }
1018
-        elseif (! $filterer instanceof Filterer) {
1018
+        elseif ( ! $filterer instanceof Filterer) {
1019 1019
             throw new \InvalidArgumentException(
1020 1020
                  "The given \$filterer must be null or a callable or a instance "
1021 1021
                 ."of Filterer instead of: ".var_export($filterer, true)
Please login to merge, or discard this patch.