Passed
Push — master ( 76213e...2a417c )
by Jean
02:49
created
src/LogicalFilter.php 2 patches
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -51,12 +51,12 @@  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();
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
 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
 
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
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
 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 {
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
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
 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,27 +352,27 @@  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'];
359
-                    if ( ! $non_true_rule_descriptions) {
359
+                    if (!$non_true_rule_descriptions) {
360 360
                         throw new \LogicException(
361 361
                             "TrueRules are not implemented. Please add "
362 362
                             ."them to operations having other type of rules"
363 363
                         );
364 364
                     }
365 365
 
366
-                    unset($operands_descriptions[ $i ]);
366
+                    unset($operands_descriptions[$i]);
367 367
                 }
368 368
             }
369 369
 
370 370
             $remaining_operations = array_filter(
371 371
                 $operands_descriptions,
372 372
                 function($operand) {
373
-                    return ! is_array($operand)
374
-                        && ! $operand instanceof AbstractRule
375
-                        && ! $operand instanceof LogicalFilter
373
+                    return !is_array($operand)
374
+                        && !$operand instanceof AbstractRule
375
+                        && !$operand instanceof LogicalFilter
376 376
                         ;
377 377
                 }
378 378
             );
@@ -381,7 +381,7 @@  discard block
 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,15 +695,15 @@  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
-        $clean_empty_branches = ! isset($options['clean_empty_branches']) || $options['clean_empty_branches'];
700
+        $clean_empty_branches = !isset($options['clean_empty_branches']) || $options['clean_empty_branches'];
701 701
 
702 702
         $filter = (new LogicalFilter($filter, new RuleFilterer))
703 703
         // ->dump()
704 704
         ;
705 705
 
706
-        $options[ Filterer::leaves_only ] = true;
706
+        $options[Filterer::leaves_only] = true;
707 707
 
708 708
         $this->rules = (new RuleFilterer)->apply($filter, $this->rules, $options);
709 709
         // $this->rules->dump(true);
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
                 $this->rules,
720 720
                 [
721 721
                     Filterer::on_row_matches => function($rule, $key, &$rows) {
722
-                        unset( $rows[$key] );
722
+                        unset($rows[$key]);
723 723
                     },
724 724
                     Filterer::on_row_mismatches => function($rule, $key, &$rows) {
725 725
                     },
@@ -744,13 +744,13 @@  discard block
 block discarded – undo
744 744
      *
745 745
      * @todo Merge with rules
746 746
      */
747
-    public function listLeafRulesMatching($filter=[])
747
+    public function listLeafRulesMatching($filter = [])
748 748
     {
749 749
         $filter = (new LogicalFilter($filter, new RuleFilterer))
750 750
         // ->dump()
751 751
         ;
752 752
 
753
-        if ( ! $this->rules) {
753
+        if (!$this->rules) {
754 754
             return [];
755 755
         }
756 756
 
@@ -764,9 +764,9 @@  discard block
 block discarded – undo
764 764
                     $key,
765 765
                     array $siblings
766 766
                 ) use (&$out) {
767
-                    if (   ! $matching_rule instanceof AndRule
768
-                        && ! $matching_rule instanceof OrRule
769
-                        && ! $matching_rule instanceof NotRule
767
+                    if (!$matching_rule instanceof AndRule
768
+                        && !$matching_rule instanceof OrRule
769
+                        && !$matching_rule instanceof NotRule
770 770
                     ) {
771 771
                         $out[] = $matching_rule;
772 772
                     }
@@ -787,13 +787,13 @@  discard block
 block discarded – undo
787 787
      *
788 788
      * @todo Make it available on AbstractRule also
789 789
      */
790
-    public function onEachRule($filter=[], $options)
790
+    public function onEachRule($filter = [], $options)
791 791
     {
792 792
         $filter = (new LogicalFilter($filter, new RuleFilterer))
793 793
         // ->dump()
794 794
         ;
795 795
 
796
-        if ( ! $this->rules) {
796
+        if (!$this->rules) {
797 797
             return [];
798 798
         }
799 799
 
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
     {
819 819
         $this->simplify(['force_logical_core' => true]);
820 820
 
821
-        if ( ! $this->rules) {
821
+        if (!$this->rules) {
822 822
             return $this;
823 823
         }
824 824
 
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
      *
864 864
      * @return LogicalFilter
865 865
      */
866
-    public function saveAs( &$variable )
866
+    public function saveAs(&$variable)
867 867
     {
868 868
         return $variable = $this;
869 869
     }
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
      *
875 875
      * @return LogicalFilter
876 876
      */
877
-    public function saveCopyAs( &$copied_variable )
877
+    public function saveCopyAs(&$copied_variable)
878 878
     {
879 879
         $copied_variable = $this->copy();
880 880
         return $this;
@@ -887,15 +887,15 @@  discard block
 block discarded – undo
887 887
      *
888 888
      * @return $this
889 889
      */
890
-    public function dump($exit=false, array $options=[])
890
+    public function dump($exit = false, array $options = [])
891 891
     {
892 892
         $default_options = [
893 893
             'callstack_depth' => 3,
894 894
             'mode'            => 'string',
895 895
         ];
896 896
         foreach ($default_options as $default_option => &$default_value) {
897
-            if ( ! isset($options[ $default_option ])) {
898
-                $options[ $default_option ] = $default_value;
897
+            if (!isset($options[$default_option])) {
898
+                $options[$default_option] = $default_value;
899 899
             }
900 900
         }
901 901
         extract($options);
@@ -906,23 +906,23 @@  discard block
 block discarded – undo
906 906
         else {
907 907
             // TODO dump a TrueRule
908 908
             $bt     = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth);
909
-            $caller = $bt[ $callstack_depth - 2 ];
909
+            $caller = $bt[$callstack_depth - 2];
910 910
 
911 911
             // get line and file from the previous level of the caller
912 912
             // TODO go deeper if this case exist?
913
-            if ( ! isset($caller['file'])) {
914
-                $caller['file'] = $bt[ $callstack_depth - 3 ]['file'];
913
+            if (!isset($caller['file'])) {
914
+                $caller['file'] = $bt[$callstack_depth - 3]['file'];
915 915
             }
916
-            if ( ! isset($caller['line'])) {
917
-                $caller['line'] = $bt[ $callstack_depth - 3 ]['line'];
916
+            if (!isset($caller['line'])) {
917
+                $caller['line'] = $bt[$callstack_depth - 3]['line'];
918 918
             }
919 919
 
920 920
             try {
921
-                echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n";
921
+                echo "\n".$caller['file'].':'.$caller['line']."\n";
922 922
                 var_export($this->toArray($options));
923 923
             }
924 924
             catch (\Exception $e) {
925
-                echo "\nError while dumping: " . $e->getMessage() . "\n";
925
+                echo "\nError while dumping: ".$e->getMessage()."\n";
926 926
                 var_export($caller);
927 927
                 echo "\n\n";
928 928
                 var_export($bt);
@@ -947,15 +947,15 @@  discard block
 block discarded – undo
947 947
      *
948 948
      * @return mixed The filtered data
949 949
      */
950
-    public function applyOn($data_to_filter, $action_on_matches=null, $filterer=null)
950
+    public function applyOn($data_to_filter, $action_on_matches = null, $filterer = null)
951 951
     {
952
-        if ( ! $filterer) {
952
+        if (!$filterer) {
953 953
             $filterer = $this->getDefaultFilterer();
954 954
         }
955 955
         elseif (is_callable($filterer)) {
956 956
             $filterer = new CustomizableFilterer($filterer);
957 957
         }
958
-        elseif ( ! $filterer instanceof Filterer) {
958
+        elseif (!$filterer instanceof Filterer) {
959 959
             throw new \InvalidArgumentException(
960 960
                  "The given \$filterer must be null or a callable or a instance "
961 961
                 ."of Filterer instead of: ".var_export($filterer, true)
@@ -963,11 +963,11 @@  discard block
 block discarded – undo
963 963
         }
964 964
 
965 965
         if ($data_to_filter instanceof LogicalFilter) {
966
-            $filtered_rules = $filterer->apply( $this, $data_to_filter->getRules() );
967
-            return $data_to_filter->flushRules()->addRule( $filtered_rules );
966
+            $filtered_rules = $filterer->apply($this, $data_to_filter->getRules());
967
+            return $data_to_filter->flushRules()->addRule($filtered_rules);
968 968
         }
969 969
         else {
970
-            return $filterer->apply( $this, $data_to_filter );
970
+            return $filterer->apply($this, $data_to_filter);
971 971
         }
972 972
     }
973 973
 
@@ -982,22 +982,22 @@  discard block
 block discarded – undo
982 982
      *                                 + Null if the target has no sens (operation filtered by field for example)
983 983
      *                                 + A rule tree containing the first matching case if there is one.
984 984
      */
985
-    public function validates($value_to_check, $key_to_check=null, $filterer=null)
985
+    public function validates($value_to_check, $key_to_check = null, $filterer = null)
986 986
     {
987
-        if ( ! $filterer) {
987
+        if (!$filterer) {
988 988
             $filterer = $this->getDefaultFilterer();
989 989
         }
990 990
         elseif (is_callable($filterer)) {
991 991
             $filterer = new CustomizableFilterer($filterer);
992 992
         }
993
-        elseif ( ! $filterer instanceof Filterer) {
993
+        elseif (!$filterer instanceof Filterer) {
994 994
             throw new \InvalidArgumentException(
995 995
                  "The given \$filterer must be null or a callable or a instance "
996 996
                 ."of Filterer instead of: ".var_export($filterer, true)
997 997
             );
998 998
         }
999 999
 
1000
-        return $filterer->hasMatchingCase( $this, $value_to_check, $key_to_check );
1000
+        return $filterer->hasMatchingCase($this, $value_to_check, $key_to_check);
1001 1001
     }
1002 1002
 
1003 1003
     /**/
Please login to merge, or discard this patch.
Braces   +28 added lines, -56 removed lines patch added patch discarded remove patch
@@ -55,8 +55,7 @@  discard block
 block discarded – undo
55 55
     {
56 56
         if ($rules instanceof AbstractRule) {
57 57
             $rules = $rules->copy();
58
-        }
59
-        elseif ( ! is_null($rules) && ! is_array($rules)) {
58
+        } elseif ( ! is_null($rules) && ! is_array($rules)) {
60 59
             throw new \InvalidArgumentException(
61 60
                 "\$rules must be a rules description or an AbstractRule instead of"
62 61
                 .var_export($rules, true)
@@ -148,13 +147,11 @@  discard block
 block discarded – undo
148 147
             if (AndRule::operator == $operation) {
149 148
                 // A && True <=> A
150 149
                 return $this;
151
-            }
152
-            elseif (OrRule::operator == $operation) {
150
+            } elseif (OrRule::operator == $operation) {
153 151
                 // A || True <=> True
154 152
                 $this->rules = null;
155 153
                 return $this;
156
-            }
157
-            else {
154
+            } else {
158 155
                 throw new InvalidArgumentException(
159 156
                     "Unhandled operation '$operation'"
160 157
                 );
@@ -174,8 +171,7 @@  discard block
 block discarded – undo
174 171
             );
175 172
 
176 173
             $this->addRule($new_rule, $operation);
177
-        }
178
-        elseif (count($rules_description) == count(array_filter($rules_description, function($arg) {
174
+        } elseif (count($rules_description) == count(array_filter($rules_description, function($arg) {
179 175
             return $arg instanceof LogicalFilter;
180 176
         })) ) {
181 177
             // Already instanciated rules
@@ -185,16 +181,14 @@  discard block
 block discarded – undo
185 181
                     $this->addRule( $rules, $operation);
186 182
                 }
187 183
             }
188
-        }
189
-        elseif (count($rules_description) == count(array_filter($rules_description, function($arg) {
184
+        } elseif (count($rules_description) == count(array_filter($rules_description, function($arg) {
190 185
             return $arg instanceof AbstractRule;
191 186
         })) ) {
192 187
             // Already instanciated rules
193 188
             foreach ($rules_description as $i => $new_rule) {
194 189
                 $this->addRule( $new_rule, $operation);
195 190
             }
196
-        }
197
-        elseif (1 == count($rules_description) && is_array($rules_description[0])) {
191
+        } elseif (1 == count($rules_description) && is_array($rules_description[0])) {
198 192
             if (count($rules_description[0]) == count(array_filter($rules_description[0], function($arg) {
199 193
                 return $arg instanceof AbstractRule;
200 194
             })) ) {
@@ -202,8 +196,7 @@  discard block
 block discarded – undo
202 196
                 foreach ($rules_description[0] as $i => $new_rule) {
203 197
                     $this->addRule( $new_rule, $operation );
204 198
                 }
205
-            }
206
-            else {
199
+            } else {
207 200
                 $fake_root = new AndRule;
208 201
 
209 202
                 $this->addCompositeRule_recursion(
@@ -213,8 +206,7 @@  discard block
 block discarded – undo
213 206
 
214 207
                 $this->addRule( $fake_root->getOperands()[0], $operation );
215 208
             }
216
-        }
217
-        else {
209
+        } else {
218 210
             throw new \InvalidArgumentException(
219 211
                 "Bad set of arguments provided for rules addition: "
220 212
                 .var_export($rules_description, true)
@@ -245,24 +237,20 @@  discard block
 block discarded – undo
245 237
 
246 238
         if (null === $this->rules) {
247 239
             $this->rules = $rule;
248
-        }
249
-        elseif (($tmp_rules = $this->rules) // $this->rules::operator not supported in PHP 5.6
240
+        } elseif (($tmp_rules = $this->rules) // $this->rules::operator not supported in PHP 5.6
250 241
             && ($tmp_rules::operator != $operation)
251 242
         ) {
252 243
             if (AndRule::operator == $operation) {
253 244
                 $this->rules = new AndRule([$this->rules, $rule]);
254
-            }
255
-            elseif (OrRule::operator == $operation) {
245
+            } elseif (OrRule::operator == $operation) {
256 246
                 $this->rules = new OrRule([$this->rules, $rule]);
257
-            }
258
-            else {
247
+            } else {
259 248
                 throw new \InvalidArgumentException(
260 249
                     "\$operation must be '".AndRule::operator."' or '".OrRule::operator
261 250
                     ."' instead of: ".var_export($operation, true)
262 251
                 );
263 252
             }
264
-        }
265
-        else {
253
+        } else {
266 254
             $this->rules->addOperand($rule);
267 255
         }
268 256
 
@@ -292,8 +280,7 @@  discard block
 block discarded – undo
292 280
                 "Please provide an operator for the operation: \n"
293 281
                 .var_export($rules_composition, true)
294 282
             );
295
-        }
296
-        elseif ( 3 == count($rules_composition)
283
+        } elseif ( 3 == count($rules_composition)
297 284
             && ! in_array( AndRule::operator, $rules_composition, true )
298 285
             && ! in_array( OrRule::operator,  $rules_composition, true )
299 286
             && ! in_array( NotRule::operator, $rules_composition, true )
@@ -310,22 +297,18 @@  discard block
 block discarded – undo
310 297
                 $operand_left, $operation, $operand_right, $this->getOptions()
311 298
             );
312 299
             $recursion_position->addOperand( $rule );
313
-        }
314
-        else {
300
+        } else {
315 301
             // operations
316 302
             if (   NotRule::operator == $rules_composition[0]
317 303
                 || $rules_composition[0] == AbstractRule::findSymbolicOperator( NotRule::operator ) ) {
318 304
                 $rule = new NotRule();
319
-            }
320
-            elseif (in_array( AndRule::operator, $rules_composition )
305
+            } elseif (in_array( AndRule::operator, $rules_composition )
321 306
                 || in_array( AbstractRule::findSymbolicOperator( AndRule::operator ), $rules_composition )) {
322 307
                 $rule = new AndRule();
323
-            }
324
-            elseif (in_array( OrRule::operator, $rules_composition )
308
+            } elseif (in_array( OrRule::operator, $rules_composition )
325 309
                 || in_array( AbstractRule::findSymbolicOperator( OrRule::operator ), $rules_composition ) ) {
326 310
                 $rule = new OrRule();
327
-            }
328
-            else {
311
+            } else {
329 312
                 throw new \InvalidArgumentException(
330 313
                     "A rule description seems to be an operation but do "
331 314
                     ."not contains a valid operator: ".var_export($rules_composition, true)
@@ -353,8 +336,7 @@  discard block
 block discarded – undo
353 336
             foreach ($operands_descriptions as $i => $operands_description) {
354 337
                 if (false === $operands_description) {
355 338
                     $operands_descriptions[ $i ] = ['and']; // FalseRule hack
356
-                }
357
-                elseif (null === $operands_description || true === $operands_description) {
339
+                } elseif (null === $operands_description || true === $operands_description) {
358 340
                     $operands_description = ['and'];
359 341
                     if ( ! $non_true_rule_descriptions) {
360 342
                         throw new \LogicException(
@@ -395,11 +377,9 @@  discard block
 block discarded – undo
395 377
             foreach ($operands_descriptions as $operands_description) {
396 378
                 if ($operands_description instanceof AbstractRule) {
397 379
                     $rule->addOperand($operands_description);
398
-                }
399
-                elseif ($operands_description instanceof LogicalFilter) {
380
+                } elseif ($operands_description instanceof LogicalFilter) {
400 381
                     $rule->addOperand($operands_description->getRules());
401
-                }
402
-                else {
382
+                } else {
403 383
                     $this->addCompositeRule_recursion(
404 384
                         $operands_description,
405 385
                         $rule
@@ -634,8 +614,7 @@  discard block
 block discarded – undo
634 614
     {
635 615
         if (method_exists($this->rules, 'renameField')) {
636 616
             $this->rules->renameField($renamings);
637
-        }
638
-        elseif ($this->rules) {
617
+        } elseif ($this->rules) {
639 618
             $this->rules->renameFields($renamings);
640 619
         }
641 620
 
@@ -902,8 +881,7 @@  discard block
 block discarded – undo
902 881
 
903 882
         if ($this->rules) {
904 883
             $this->rules->dump($exit, $options);
905
-        }
906
-        else {
884
+        } else {
907 885
             // TODO dump a TrueRule
908 886
             $bt     = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth);
909 887
             $caller = $bt[ $callstack_depth - 2 ];
@@ -920,8 +898,7 @@  discard block
 block discarded – undo
920 898
             try {
921 899
                 echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n";
922 900
                 var_export($this->toArray($options));
923
-            }
924
-            catch (\Exception $e) {
901
+            } catch (\Exception $e) {
925 902
                 echo "\nError while dumping: " . $e->getMessage() . "\n";
926 903
                 var_export($caller);
927 904
                 echo "\n\n";
@@ -951,11 +928,9 @@  discard block
 block discarded – undo
951 928
     {
952 929
         if ( ! $filterer) {
953 930
             $filterer = $this->getDefaultFilterer();
954
-        }
955
-        elseif (is_callable($filterer)) {
931
+        } elseif (is_callable($filterer)) {
956 932
             $filterer = new CustomizableFilterer($filterer);
957
-        }
958
-        elseif ( ! $filterer instanceof Filterer) {
933
+        } elseif ( ! $filterer instanceof Filterer) {
959 934
             throw new \InvalidArgumentException(
960 935
                  "The given \$filterer must be null or a callable or a instance "
961 936
                 ."of Filterer instead of: ".var_export($filterer, true)
@@ -965,8 +940,7 @@  discard block
 block discarded – undo
965 940
         if ($data_to_filter instanceof LogicalFilter) {
966 941
             $filtered_rules = $filterer->apply( $this, $data_to_filter->getRules() );
967 942
             return $data_to_filter->flushRules()->addRule( $filtered_rules );
968
-        }
969
-        else {
943
+        } else {
970 944
             return $filterer->apply( $this, $data_to_filter );
971 945
         }
972 946
     }
@@ -986,11 +960,9 @@  discard block
 block discarded – undo
986 960
     {
987 961
         if ( ! $filterer) {
988 962
             $filterer = $this->getDefaultFilterer();
989
-        }
990
-        elseif (is_callable($filterer)) {
963
+        } elseif (is_callable($filterer)) {
991 964
             $filterer = new CustomizableFilterer($filterer);
992
-        }
993
-        elseif ( ! $filterer instanceof Filterer) {
965
+        } elseif ( ! $filterer instanceof Filterer) {
994 966
             throw new \InvalidArgumentException(
995 967
                  "The given \$filterer must be null or a callable or a instance "
996 968
                 ."of Filterer instead of: ".var_export($filterer, true)
Please login to merge, or discard this patch.
src/Filterer/Filterer.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
      */
47 47
     public function onRowMatches(&$row, $key, &$rows, $matching_case, $options)
48 48
     {
49
-        if (isset($options[ self::on_row_matches ])) {
50
-            $callback = $options[ self::on_row_matches ];
49
+        if (isset($options[self::on_row_matches])) {
50
+            $callback = $options[self::on_row_matches];
51 51
         }
52
-        elseif (isset($this->custom_actions[ self::on_row_matches ])) {
53
-            $callback = $this->custom_actions[ self::on_row_matches ];
52
+        elseif (isset($this->custom_actions[self::on_row_matches])) {
53
+            $callback = $this->custom_actions[self::on_row_matches];
54 54
         }
55 55
         else {
56 56
             return;
@@ -72,20 +72,20 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function onRowMismatches(&$row, $key, &$rows, $matching_case, $options)
74 74
     {
75
-        if (   ! $this->custom_actions
76
-            && ! isset($options[self::on_row_mismatches])
77
-            && ! isset($options[self::on_row_matches])
75
+        if (!$this->custom_actions
76
+            && !isset($options[self::on_row_mismatches])
77
+            && !isset($options[self::on_row_matches])
78 78
         ) {
79 79
             // Unset by default ONLY if NO custom action defined
80 80
             unset($rows[$key]);
81 81
             return;
82 82
         }
83 83
 
84
-        if (isset($options[ self::on_row_mismatches ])) {
85
-            $callback = $options[ self::on_row_mismatches ];
84
+        if (isset($options[self::on_row_mismatches])) {
85
+            $callback = $options[self::on_row_mismatches];
86 86
         }
87
-        elseif (isset($this->custom_actions[ self::on_row_mismatches ])) {
88
-            $callback = $this->custom_actions[ self::on_row_mismatches ];
87
+        elseif (isset($this->custom_actions[self::on_row_mismatches])) {
88
+            $callback = $this->custom_actions[self::on_row_mismatches];
89 89
         }
90 90
         else {
91 91
             return;
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      * @param Iterable        $tree_to_filter
123 123
      * @param array           $options
124 124
      */
125
-    public function apply( LogicalFilter $filter, $tree_to_filter, $options=[] )
125
+    public function apply(LogicalFilter $filter, $tree_to_filter, $options = [])
126 126
     {
127 127
         $root_OrRule = $filter
128 128
             ->simplify(['force_logical_core' => true])
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             ;
132 132
 
133 133
         if (null !== $root_OrRule) {
134
-            if ( ! $root_OrRule->hasSolution()) {
134
+            if (!$root_OrRule->hasSolution()) {
135 135
                 return null;
136 136
             }
137 137
 
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
             $root_cases = [];
142 142
         }
143 143
 
144
-        if ( ! isset($options['recurse'])) {
144
+        if (!isset($options['recurse'])) {
145 145
             $options['recurse'] = 'before';
146 146
         }
147
-        elseif ( ! in_array($options['recurse'], ['before', 'after', null])) {
147
+        elseif (!in_array($options['recurse'], ['before', 'after', null])) {
148 148
             throw new \InvalidArgumentException(
149 149
                 "Invalid value for 'recurse' option: "
150 150
                 .var_export($options['recurse'], true)
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
         return $this->foreachRow(
156 156
             $root_cases,
157 157
             $tree_to_filter,
158
-            $path=[],
158
+            $path = [],
159 159
             $options
160 160
         );
161 161
     }
162 162
 
163 163
     /**
164 164
      */
165
-    protected function foreachRow(array $root_cases, $tree_to_filter, array $path, $options=[])
165
+    protected function foreachRow(array $root_cases, $tree_to_filter, array $path, $options = [])
166 166
     {
167 167
         // Once the rules are prepared, we parse the data
168 168
         foreach ($tree_to_filter as $row_index => $row_to_filter) {
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
      *
222 222
      * @return bool
223 223
      */
224
-    public function hasMatchingCase( LogicalFilter $filter, $row_to_check, $key_to_check, $options=[] )
224
+    public function hasMatchingCase(LogicalFilter $filter, $row_to_check, $key_to_check, $options = [])
225 225
     {
226 226
         $root_OrRule = $filter
227 227
             ->simplify(['force_logical_core' => true])
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
             ;
231 231
 
232 232
         if (null !== $root_OrRule) {
233
-            if ( ! $root_OrRule->hasSolution()) {
233
+            if (!$root_OrRule->hasSolution()) {
234 234
                 return null;
235 235
             }
236 236
 
@@ -243,24 +243,24 @@  discard block
 block discarded – undo
243 243
         return $this->applyOnRow(
244 244
             $root_cases,
245 245
             $row_to_check,
246
-            $path=[$key_to_check],
246
+            $path = [$key_to_check],
247 247
             $options
248 248
         );
249 249
     }
250 250
 
251 251
     /**
252 252
      */
253
-    protected function applyOnRow(array $root_cases, $row_to_filter, array $path, $options=[])
253
+    protected function applyOnRow(array $root_cases, $row_to_filter, array $path, $options = [])
254 254
     {
255 255
         $operands_validation_row_cache = [];
256 256
 
257
-        if ( ! $root_cases) {
257
+        if (!$root_cases) {
258 258
             $matching_case = true;
259 259
         }
260 260
         else {
261 261
             $matching_case = null;
262 262
             foreach ($root_cases as $and_case_index => $and_case) {
263
-                if ( ! empty($options['debug'])) {
263
+                if (!empty($options['debug'])) {
264 264
                     var_dump("Case $and_case_index: ".$and_case);
265 265
                 }
266 266
 
@@ -288,8 +288,8 @@  discard block
 block discarded – undo
288 288
 
289 289
                     $cache_key = $and_case_index.'~|~'.$field.'~|~'.$operator;
290 290
 
291
-                    if ( ! empty($operands_validation_row_cache[ $cache_key ])) {
292
-                        $is_valid = $operands_validation_row_cache[ $cache_key ];
291
+                    if (!empty($operands_validation_row_cache[$cache_key])) {
292
+                        $is_valid = $operands_validation_row_cache[$cache_key];
293 293
                     }
294 294
                     else {
295 295
                         $is_valid = $this->validateRule(
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
                             $options
303 303
                         );
304 304
 
305
-                        $operands_validation_row_cache[ $cache_key ] = $is_valid;
305
+                        $operands_validation_row_cache[$cache_key] = $is_valid;
306 306
                     }
307 307
 
308 308
                     if (false === $is_valid) {
Please login to merge, or discard this patch.
Braces   +16 added lines, -32 removed lines patch added patch discarded remove patch
@@ -48,11 +48,9 @@  discard block
 block discarded – undo
48 48
     {
49 49
         if (isset($options[ self::on_row_matches ])) {
50 50
             $callback = $options[ self::on_row_matches ];
51
-        }
52
-        elseif (isset($this->custom_actions[ self::on_row_matches ])) {
51
+        } elseif (isset($this->custom_actions[ self::on_row_matches ])) {
53 52
             $callback = $this->custom_actions[ self::on_row_matches ];
54
-        }
55
-        else {
53
+        } else {
56 54
             return;
57 55
         }
58 56
 
@@ -83,11 +81,9 @@  discard block
 block discarded – undo
83 81
 
84 82
         if (isset($options[ self::on_row_mismatches ])) {
85 83
             $callback = $options[ self::on_row_mismatches ];
86
-        }
87
-        elseif (isset($this->custom_actions[ self::on_row_mismatches ])) {
84
+        } elseif (isset($this->custom_actions[ self::on_row_mismatches ])) {
88 85
             $callback = $this->custom_actions[ self::on_row_mismatches ];
89
-        }
90
-        else {
86
+        } else {
91 87
             return;
92 88
         }
93 89
 
@@ -136,15 +132,13 @@  discard block
 block discarded – undo
136 132
             }
137 133
 
138 134
             $root_cases = $root_OrRule->getOperands();
139
-        }
140
-        else {
135
+        } else {
141 136
             $root_cases = [];
142 137
         }
143 138
 
144 139
         if ( ! isset($options['recurse'])) {
145 140
             $options['recurse'] = 'before';
146
-        }
147
-        elseif ( ! in_array($options['recurse'], ['before', 'after', null])) {
141
+        } elseif ( ! in_array($options['recurse'], ['before', 'after', null])) {
148 142
             throw new \InvalidArgumentException(
149 143
                 "Invalid value for 'recurse' option: "
150 144
                 .var_export($options['recurse'], true)
@@ -185,12 +179,10 @@  discard block
 block discarded – undo
185 179
 
186 180
             if ($matching_case) {
187 181
                 $this->onRowMatches($row_to_filter, $row_index, $tree_to_filter, $matching_case, $options);
188
-            }
189
-            elseif (false === $matching_case) {
182
+            } elseif (false === $matching_case) {
190 183
                 // No case match the rule
191 184
                 $this->onRowMismatches($row_to_filter, $row_index, $tree_to_filter, $matching_case, $options);
192
-            }
193
-            elseif (null === $matching_case) {
185
+            } elseif (null === $matching_case) {
194 186
                 // We simply avoid rules
195 187
                 // row out of scope
196 188
             }
@@ -235,8 +227,7 @@  discard block
 block discarded – undo
235 227
             }
236 228
 
237 229
             $root_cases = $root_OrRule->getOperands();
238
-        }
239
-        else {
230
+        } else {
240 231
             $root_cases = [];
241 232
         }
242 233
 
@@ -256,8 +247,7 @@  discard block
 block discarded – undo
256 247
 
257 248
         if ( ! $root_cases) {
258 249
             $matching_case = true;
259
-        }
260
-        else {
250
+        } else {
261 251
             $matching_case = null;
262 252
             foreach ($root_cases as $and_case_index => $and_case) {
263 253
                 if ( ! empty($options['debug'])) {
@@ -269,16 +259,14 @@  discard block
 block discarded – undo
269 259
                     if ($rule instanceof OrRule && $rule instanceof AndRule) {
270 260
                         $field = null;
271 261
                         $value = $rule->getOperands();
272
-                    }
273
-                    elseif ($rule instanceof NotEqualRule
262
+                    } elseif ($rule instanceof NotEqualRule
274 263
                         || $rule instanceof AbstractAtomicRule
275 264
                         || $rule instanceof InRule
276 265
                         || $rule instanceof NotInRule
277 266
                     ) {
278 267
                         $field = $rule->getField();
279 268
                         $value = $rule->getValues();
280
-                    }
281
-                    else {
269
+                    } else {
282 270
                         throw new \LogicException(
283 271
                             "Filtering with a rule which has not been simplified: $rule"
284 272
                         );
@@ -290,8 +278,7 @@  discard block
 block discarded – undo
290 278
 
291 279
                     if ( ! empty($operands_validation_row_cache[ $cache_key ])) {
292 280
                         $is_valid = $operands_validation_row_cache[ $cache_key ];
293
-                    }
294
-                    else {
281
+                    } else {
295 282
                         $is_valid = $this->validateRule(
296 283
                             $field,
297 284
                             $operator,
@@ -310,8 +297,7 @@  discard block
 block discarded – undo
310 297
                         // so all the and_case is invalid
311 298
                         $case_is_good = false;
312 299
                         break;
313
-                    }
314
-                    elseif (true === $is_valid) {
300
+                    } elseif (true === $is_valid) {
315 301
                         // one of the rules of the and_case do not validate
316 302
                         // so all the and_case is invalid
317 303
                         $case_is_good = true;
@@ -322,11 +308,9 @@  discard block
 block discarded – undo
322 308
                     // at least one and_case works so we can stop here
323 309
                     $matching_case = $and_case;
324 310
                     break;
325
-                }
326
-                elseif (false === $case_is_good) {
311
+                } elseif (false === $case_is_good) {
327 312
                     $matching_case = false;
328
-                }
329
-                elseif (null === $case_is_good) {
313
+                } elseif (null === $case_is_good) {
330 314
                     // row out of scope
331 315
                 }
332 316
             }
Please login to merge, or discard this patch.
src/Filterer/RuleFilterer.php 2 patches
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
 
60 60
     /**
61 61
      */
62
-    public function setChildren( &$row, $filtered_children ) // strict issue if forcing  AbstractRule with php 5.6 here
62
+    public function setChildren(&$row, $filtered_children) // strict issue if forcing  AbstractRule with php 5.6 here
63 63
     {
64 64
         if ($row instanceof AbstractOperationRule) {
65
-            return $row->setOperandsOrReplaceByOperation( $filtered_children, [] ); // no simplification options?
65
+            return $row->setOperandsOrReplaceByOperation($filtered_children, []); // no simplification options?
66 66
         }
67 67
     }
68 68
 
@@ -70,17 +70,17 @@  discard block
 block discarded – undo
70 70
      *
71 71
      * @return true | false | null
72 72
      */
73
-    public function validateRule ($field, $operator, $value, $rule, array $path, $all_operands, $options)
73
+    public function validateRule($field, $operator, $value, $rule, array $path, $all_operands, $options)
74 74
     {
75
-        if (    ! empty($options[ Filterer::leaves_only ])
76
-            && in_array( get_class($rule), [OrRule::class, AndRule::class, NotRule::class] )
75
+        if (!empty($options[Filterer::leaves_only])
76
+            && in_array(get_class($rule), [OrRule::class, AndRule::class, NotRule::class])
77 77
         ) {
78 78
             // return true;
79 79
             return null;
80 80
         }
81 81
 
82 82
         if (self::field === $field) {
83
-            if ( ! method_exists($rule, 'getField')) {
83
+            if (!method_exists($rule, 'getField')) {
84 84
                 // if (in_array( get_class($rule), [AndRule::class, OrRule::class]))
85 85
                 return null; // The filter cannot be applied to this rule
86 86
             }
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
         elseif (self::value === $field) {
101 101
             $description = $rule->toArray();
102 102
 
103
-            if (    3 === count($description)
103
+            if (3 === count($description)
104 104
                 && is_string($description[0])
105
-                && is_string($description[1]) ) {
105
+                && is_string($description[1])) {
106 106
                 $value_to_compare = $description[2];
107 107
             }
108 108
             else {
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
             throw new \InvalidArgumentException('Path rule uppport not implemented');
122 122
         }
123 123
         elseif (self::children === $field) {
124
-            if ( ! method_exists($rule, 'getOperands')) {
124
+            if (!method_exists($rule, 'getOperands')) {
125 125
                 return null; // The filter cannot be applied to this rule
126 126
             }
127
-            $value_to_compare = count( $rule->getOperands() );
127
+            $value_to_compare = count($rule->getOperands());
128 128
         }
129 129
         else {
130 130
             throw new \InvalidArgumentException(
@@ -173,27 +173,27 @@  discard block
 block discarded – undo
173 173
         }
174 174
         elseif (NotEqualRule::operator === $operator) {
175 175
             if (null === $value) {
176
-                $out = ! is_null($value_to_compare);
176
+                $out = !is_null($value_to_compare);
177 177
             }
178 178
             else {
179 179
                 $out = $value != $value_to_compare;
180 180
             }
181 181
         }
182 182
         elseif (NotInRule::operator === $operator) {
183
-            $out = ! in_array($value_to_compare, $value);
183
+            $out = !in_array($value_to_compare, $value);
184 184
         }
185 185
         else {
186 186
             throw new \InvalidArgumentException(
187
-                "Unhandled operator: " . $operator
187
+                "Unhandled operator: ".$operator
188 188
             );
189 189
         }
190 190
 
191
-        if ( ! empty($options['debug'])) {
191
+        if (!empty($options['debug'])) {
192 192
             var_dump(
193
-                "$field, $operator, " . var_export($value, true)
194
-                 . ' ||  '. $value_to_compare . ' => ' . var_export($out, true)
195
-                 . "\n" . get_class($rule)
196
-                 . "\n" . var_export($options, true)
193
+                "$field, $operator, ".var_export($value, true)
194
+                 . ' ||  '.$value_to_compare.' => '.var_export($out, true)
195
+                 . "\n".get_class($rule)
196
+                 . "\n".var_export($options, true)
197 197
             );
198 198
             // $rule->dump();
199 199
         }
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
      * @param array|AbstractRule $ruleTree_to_filter
207 207
      * @param array              $options leaves_only | debug
208 208
      */
209
-    public function apply( LogicalFilter $filter, $ruleTree_to_filter, $options=[] )
209
+    public function apply(LogicalFilter $filter, $ruleTree_to_filter, $options = [])
210 210
     {
211
-        if ( ! $ruleTree_to_filter) {
211
+        if (!$ruleTree_to_filter) {
212 212
             return $ruleTree_to_filter;
213 213
         }
214 214
 
@@ -216,17 +216,17 @@  discard block
 block discarded – undo
216 216
             $ruleTree_to_filter = [$ruleTree_to_filter];
217 217
         }
218 218
 
219
-        if ( ! is_array($ruleTree_to_filter)) {
219
+        if (!is_array($ruleTree_to_filter)) {
220 220
             throw new \InvalidArgumentException(
221 221
                 "\$ruleTree_to_filter must be an array or an AbstractRule "
222
-                ."instead of: " . var_export($ruleTree_to_filter, true)
222
+                ."instead of: ".var_export($ruleTree_to_filter, true)
223 223
             );
224 224
         }
225 225
 
226 226
         // Produces "Only variables should be passed by reference" on Travis
227 227
         $result = parent::apply($filter, $ruleTree_to_filter, $options);
228 228
 
229
-        return reset( $result );
229
+        return reset($result);
230 230
     }
231 231
 
232 232
     /**/
Please login to merge, or discard this patch.
Braces   +18 added lines, -36 removed lines patch added patch discarded remove patch
@@ -87,46 +87,37 @@  discard block
 block discarded – undo
87 87
 
88 88
             try {
89 89
                 $value_to_compare = $rule->getField();
90
-            }
91
-            catch (\LogicException $e) {
90
+            } catch (\LogicException $e) {
92 91
                 // This is due to NotInRule.
93 92
                 // TODO replace it by a TrueRule in this case
94 93
                 return  null;
95 94
             }
96
-        }
97
-        elseif (self::operator === $field) {
95
+        } elseif (self::operator === $field) {
98 96
             $value_to_compare = $rule::operator;
99
-        }
100
-        elseif (self::value === $field) {
97
+        } elseif (self::value === $field) {
101 98
             $description = $rule->toArray();
102 99
 
103 100
             if (    3 === count($description)
104 101
                 && is_string($description[0])
105 102
                 && is_string($description[1]) ) {
106 103
                 $value_to_compare = $description[2];
107
-            }
108
-            else {
104
+            } else {
109 105
                 return null; // The filter cannot be applied to this rule
110 106
             }
111
-        }
112
-        elseif (self::description === $field) {
107
+        } elseif (self::description === $field) {
113 108
             $value_to_compare = $rule->toArray();
114
-        }
115
-        elseif (self::depth === $field) {
109
+        } elseif (self::depth === $field) {
116 110
             // original $depth is lost once the filter is simplified
117 111
             throw new \InvalidArgumentException('Depth rule uppport not implemented');
118
-        }
119
-        elseif (self::path === $field) {
112
+        } elseif (self::path === $field) {
120 113
             // TODO the description of its parents
121 114
             throw new \InvalidArgumentException('Path rule uppport not implemented');
122
-        }
123
-        elseif (self::children === $field) {
115
+        } elseif (self::children === $field) {
124 116
             if ( ! method_exists($rule, 'getOperands')) {
125 117
                 return null; // The filter cannot be applied to this rule
126 118
             }
127 119
             $value_to_compare = count( $rule->getOperands() );
128
-        }
129
-        else {
120
+        } else {
130 121
             throw new \InvalidArgumentException(
131 122
                 "Rule filters must belong to ["
132 123
                 . implode(', ', [
@@ -145,22 +136,17 @@  discard block
 block discarded – undo
145 136
         if (EqualRule::operator === $operator) {
146 137
             if (null === $value) {
147 138
                 $out = is_null($value_to_compare);
148
-            }
149
-            else {
139
+            } else {
150 140
                 // TODO support strict comparisons
151 141
                 $out = $value_to_compare == $value;
152 142
             }
153
-        }
154
-        elseif (InRule::operator === $operator) {
143
+        } elseif (InRule::operator === $operator) {
155 144
             $out = in_array($value_to_compare, $value);
156
-        }
157
-        elseif (BelowRule::operator === $operator) {
145
+        } elseif (BelowRule::operator === $operator) {
158 146
             $out = $value_to_compare < $value;
159
-        }
160
-        elseif (AboveRule::operator === $operator) {
147
+        } elseif (AboveRule::operator === $operator) {
161 148
             $out = $value_to_compare > $value;
162
-        }
163
-        elseif (RegexpRule::operator === $operator) {
149
+        } elseif (RegexpRule::operator === $operator) {
164 150
             // TODO support optionnal parameters
165 151
             $out = preg_match($value, $value_to_compare);
166 152
             if (false === $out) {
@@ -170,19 +156,15 @@  discard block
 block discarded – undo
170 156
                 );
171 157
             }
172 158
             $out = (bool) $out;
173
-        }
174
-        elseif (NotEqualRule::operator === $operator) {
159
+        } elseif (NotEqualRule::operator === $operator) {
175 160
             if (null === $value) {
176 161
                 $out = ! is_null($value_to_compare);
177
-            }
178
-            else {
162
+            } else {
179 163
                 $out = $value != $value_to_compare;
180 164
             }
181
-        }
182
-        elseif (NotInRule::operator === $operator) {
165
+        } elseif (NotInRule::operator === $operator) {
183 166
             $out = ! in_array($value_to_compare, $value);
184
-        }
185
-        else {
167
+        } else {
186 168
             throw new \InvalidArgumentException(
187 169
                 "Unhandled operator: " . $operator
188 170
             );
Please login to merge, or discard this patch.
src/Filterer/PhpFilterer.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -22,23 +22,23 @@  discard block
 block discarded – undo
22 22
 {
23 23
     /**
24 24
      */
25
-    public function validateRule ($field, $operator, $value, $row, array $path, $all_operands, $options)
25
+    public function validateRule($field, $operator, $value, $row, array $path, $all_operands, $options)
26 26
     {
27 27
         if ($field instanceof FilteredValue) {
28
-            $value_to_validate = $field( $row );
28
+            $value_to_validate = $field($row);
29 29
         }
30 30
         elseif ($field instanceof FilteredKey) {
31
-            $value_to_validate = $field( array_pop($path) );
31
+            $value_to_validate = $field(array_pop($path));
32 32
         }
33
-        elseif ( ! isset($row[(string) $field])) {
33
+        elseif (!isset($row[(string) $field])) {
34 34
             $value_to_validate = null;
35 35
         }
36 36
         else {
37
-            $value_to_validate = $row[ $field ];
37
+            $value_to_validate = $row[$field];
38 38
         }
39 39
 
40 40
         if (EqualRule::operator === $operator) {
41
-            if ( ! isset($value_to_validate)) {
41
+            if (!isset($value_to_validate)) {
42 42
                 // ['field', '=', null] <=> isset($row['field'])
43 43
                 // [row, '=', null] <=> $row !== null
44 44
                 $result = null === $value;
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
             }
50 50
         }
51 51
         elseif (InRule::operator === $operator) {
52
-            if ( ! isset($value_to_validate)) {
52
+            if (!isset($value_to_validate)) {
53 53
                 $result = false;
54 54
             }
55 55
             else {
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
             }
58 58
         }
59 59
         elseif (BelowRule::operator === $operator) {
60
-            if ( ! isset($value_to_validate)) {
60
+            if (!isset($value_to_validate)) {
61 61
                 $result = false;
62 62
             }
63 63
             else {
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
             }
66 66
         }
67 67
         elseif (AboveRule::operator === $operator) {
68
-            if ( ! isset($value_to_validate)) {
68
+            if (!isset($value_to_validate)) {
69 69
                 $result = false;
70 70
             }
71 71
             else {
@@ -81,16 +81,16 @@  discard block
 block discarded – undo
81 81
             }
82 82
         }
83 83
         elseif (NotInRule::operator === $operator) {
84
-            if ( ! isset($value_to_validate)) {
84
+            if (!isset($value_to_validate)) {
85 85
                 $result = true;
86 86
             }
87 87
             else {
88
-                $result = ! in_array($value_to_validate, $value);
88
+                $result = !in_array($value_to_validate, $value);
89 89
             }
90 90
         }
91 91
         else {
92 92
             throw new \InvalidArgumentException(
93
-                "Unhandled operator: " . $operator
93
+                "Unhandled operator: ".$operator
94 94
             );
95 95
         }
96 96
 
Please login to merge, or discard this patch.
Braces   +15 added lines, -30 removed lines patch added patch discarded remove patch
@@ -26,14 +26,11 @@  discard block
 block discarded – undo
26 26
     {
27 27
         if ($field instanceof FilteredValue) {
28 28
             $value_to_validate = $field( $row );
29
-        }
30
-        elseif ($field instanceof FilteredKey) {
29
+        } elseif ($field instanceof FilteredKey) {
31 30
             $value_to_validate = $field( array_pop($path) );
32
-        }
33
-        elseif ( ! isset($row[(string) $field])) {
31
+        } elseif ( ! isset($row[(string) $field])) {
34 32
             $value_to_validate = null;
35
-        }
36
-        else {
33
+        } else {
37 34
             $value_to_validate = $row[ $field ];
38 35
         }
39 36
 
@@ -42,53 +39,41 @@  discard block
 block discarded – undo
42 39
                 // ['field', '=', null] <=> isset($row['field'])
43 40
                 // [row, '=', null] <=> $row !== null
44 41
                 $result = null === $value;
45
-            }
46
-            else {
42
+            } else {
47 43
                 // TODO support strict comparisons
48 44
                 $result = $value_to_validate == $value;
49 45
             }
50
-        }
51
-        elseif (InRule::operator === $operator) {
46
+        } elseif (InRule::operator === $operator) {
52 47
             if ( ! isset($value_to_validate)) {
53 48
                 $result = false;
54
-            }
55
-            else {
49
+            } else {
56 50
                 $result = in_array($value_to_validate, $value);
57 51
             }
58
-        }
59
-        elseif (BelowRule::operator === $operator) {
52
+        } elseif (BelowRule::operator === $operator) {
60 53
             if ( ! isset($value_to_validate)) {
61 54
                 $result = false;
62
-            }
63
-            else {
55
+            } else {
64 56
                 $result = $value_to_validate < $value;
65 57
             }
66
-        }
67
-        elseif (AboveRule::operator === $operator) {
58
+        } elseif (AboveRule::operator === $operator) {
68 59
             if ( ! isset($value_to_validate)) {
69 60
                 $result = false;
70
-            }
71
-            else {
61
+            } else {
72 62
                 $result = $value_to_validate > $value;
73 63
             }
74
-        }
75
-        elseif (NotEqualRule::operator === $operator) {
64
+        } elseif (NotEqualRule::operator === $operator) {
76 65
             if (null === $value) {
77 66
                 $result = isset($value_to_validate);
78
-            }
79
-            else {
67
+            } else {
80 68
                 $result = $value_to_validate != $value;
81 69
             }
82
-        }
83
-        elseif (NotInRule::operator === $operator) {
70
+        } elseif (NotInRule::operator === $operator) {
84 71
             if ( ! isset($value_to_validate)) {
85 72
                 $result = true;
86
-            }
87
-            else {
73
+            } else {
88 74
                 $result = ! in_array($value_to_validate, $value);
89 75
             }
90
-        }
91
-        else {
76
+        } else {
92 77
             throw new \InvalidArgumentException(
93 78
                 "Unhandled operator: " . $operator
94 79
             );
Please login to merge, or discard this patch.
src/Rule/BelowOrEqualRule.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
18 18
      * @param string $field The field to apply the rule on.
19 19
      * @param array  $value The value the field can below to.
20 20
      */
21
-    public function __construct($field, $maximum, array $options=[])
21
+    public function __construct($field, $maximum, array $options = [])
22 22
     {
23
-        if ( ! empty($options)) {
23
+        if (!empty($options)) {
24 24
             $this->setOptions($options);
25 25
         }
26 26
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     /**
64 64
      * @return bool
65 65
      */
66
-    public function isNormalizationAllowed(array $contextual_options=[])
66
+    public function isNormalizationAllowed(array $contextual_options = [])
67 67
     {
68 68
         return $this->getOption('below_or_equal.normalization', $contextual_options);
69 69
     }
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      */
74 74
     public function getOperands()
75 75
     {
76
-        if ( ! empty($this->cache['operands'])) {
76
+        if (!empty($this->cache['operands'])) {
77 77
             return $this->cache['operands'];
78 78
         }
79 79
 
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
             }
106 106
         }
107 107
 
108
-        if (   2 != count($operands)
109
-            || ! isset($equalRuleValue)
110
-            || ! isset($belowRuleValue)
108
+        if (2 != count($operands)
109
+            || !isset($equalRuleValue)
110
+            || !isset($belowRuleValue)
111 111
             || $belowRuleValue != $equalRuleValue
112 112
             || $belowRuleField != $equalRuleField
113 113
         ) {
@@ -136,14 +136,14 @@  discard block
 block discarded – undo
136 136
      *
137 137
      * @return array
138 138
      */
139
-    public function toArray(array $options=[])
139
+    public function toArray(array $options = [])
140 140
     {
141 141
         $default_options = [
142 142
             'show_instance' => false,
143 143
         ];
144 144
         foreach ($default_options as $default_option => &$default_value) {
145
-            if ( ! isset($options[ $default_option ])) {
146
-                $options[ $default_option ] = $default_value;
145
+            if (!isset($options[$default_option])) {
146
+                $options[$default_option] = $default_value;
147 147
             }
148 148
         }
149 149
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 
163 163
     /**
164 164
      */
165
-    public function toString(array $options=[])
165
+    public function toString(array $options = [])
166 166
     {
167 167
         if (isset($this->cache['string'])) {
168 168
             return $this->cache['string'];
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 
171 171
         $operator = self::operator;
172 172
 
173
-        return $this->cache['string'] = "['{$this->getField()}', '$operator', " . var_export($this->getValues(), true). "]";
173
+        return $this->cache['string'] = "['{$this->getField()}', '$operator', ".var_export($this->getValues(), true)."]";
174 174
     }
175 175
 
176 176
     /**/
Please login to merge, or discard this patch.
src/Rule/AbstractOperationRule.php 1 patch
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     const remove_negations        = 'remove_negations';
21 21
     const rootify_disjunctions    = 'rootify_disjunctions';
22 22
     const unify_atomic_operands   = 'unify_atomic_operands';
23
-    const remove_invalid_branches = 'remove_invalid_branches';    // simplified after this step
23
+    const remove_invalid_branches = 'remove_invalid_branches'; // simplified after this step
24 24
 
25 25
     const simplified              = self::remove_invalid_branches;
26 26
 
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 
44 44
     /**
45 45
      */
46
-    public function __construct( array $operands=[] )
46
+    public function __construct(array $operands = [])
47 47
     {
48
-        $this->setOperands( $operands );
48
+        $this->setOperands($operands);
49 49
         $this->flushCache();
50 50
     }
51 51
 
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
      *
65 65
      * @return $this
66 66
      */
67
-    public function addOperand( AbstractRule $new_operand )
67
+    public function addOperand(AbstractRule $new_operand)
68 68
     {
69
-        if ( ! isset($this->operands[ $id = $new_operand->getSemanticId() ])) {
70
-            $this->operands[ $id ] = $new_operand;
69
+        if (!isset($this->operands[$id = $new_operand->getSemanticId()])) {
70
+            $this->operands[$id] = $new_operand;
71 71
 
72 72
             if ($this->current_simplification_step) {
73 73
                 $this->current_simplification_step = null;
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function getOperands()
86 86
     {
87
-        return array_values( $this->operands );
87
+        return array_values($this->operands);
88 88
     }
89 89
 
90 90
     /**
@@ -128,30 +128,30 @@  discard block
 block discarded – undo
128 128
      * @param array  $simplification_options
129 129
      * @param bool   $force
130 130
      */
131
-    public function moveSimplificationStepForward($step_to_go_to, array $simplification_options, $force=false)
131
+    public function moveSimplificationStepForward($step_to_go_to, array $simplification_options, $force = false)
132 132
     {
133
-        if ( ! in_array($step_to_go_to, self::simplification_steps)) {
133
+        if (!in_array($step_to_go_to, self::simplification_steps)) {
134 134
             throw new \InvalidArgumentException(
135 135
                 "Invalid simplification step to go to: ".$step_to_go_to
136 136
             );
137 137
         }
138 138
 
139 139
         // if ($this->isNormalizationAllowed($simplification_options) && !$force && $this->current_simplification_step != null) {
140
-        if ( ! $force && null !== $this->current_simplification_step) {
140
+        if (!$force && null !== $this->current_simplification_step) {
141 141
             $steps_indices = array_flip(self::simplification_steps);
142 142
 
143
-            $current_index = $steps_indices[ $this->current_simplification_step ];
144
-            $target_index  = $steps_indices[ $step_to_go_to ];
143
+            $current_index = $steps_indices[$this->current_simplification_step];
144
+            $target_index  = $steps_indices[$step_to_go_to];
145 145
 
146
-            if ( $current_index >= $target_index ) {
146
+            if ($current_index >= $target_index) {
147 147
                 // allow recall of previous step without going back
148 148
                 return;
149 149
             }
150
-            elseif ( $current_index < $target_index - 1 ) {
150
+            elseif ($current_index < $target_index - 1) {
151 151
                 throw new \LogicException(
152
-                    "$step_to_go_to MUST be fullfilled after " . self::simplification_steps[$target_index - 1]
153
-                    . " instead of the current step: " . $this->current_simplification_step
154
-                    ."\nfor: " . $this
152
+                    "$step_to_go_to MUST be fullfilled after ".self::simplification_steps[$target_index - 1]
153
+                    . " instead of the current step: ".$this->current_simplification_step
154
+                    ."\nfor: ".$this
155 155
                 );
156 156
             }
157 157
         }
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public function simplicationStepReached($step)
170 170
     {
171
-        if ( ! in_array($step, self::simplification_steps)) {
171
+        if (!in_array($step, self::simplification_steps)) {
172 172
             throw new \InvalidArgumentException(
173 173
                 "Invalid simplification step: ".$step
174 174
             );
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
 
181 181
         $steps_indices = array_flip(self::simplification_steps);
182 182
 
183
-        $current_index = $steps_indices[ $this->current_simplification_step ];
184
-        $step_index    = $steps_indices[ $step ];
183
+        $current_index = $steps_indices[$this->current_simplification_step];
184
+        $step_index    = $steps_indices[$step];
185 185
 
186 186
         return $current_index >= $step_index;
187 187
     }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      */
194 194
     public function removeNegations(array $contextual_options)
195 195
     {
196
-        if ( ! $this->isNormalizationAllowed($contextual_options)) {
196
+        if (!$this->isNormalizationAllowed($contextual_options)) {
197 197
             return $this;
198 198
         }
199 199
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
                 }
208 208
 
209 209
                 if ($operands[$i] instanceof AbstractOperationRule) {
210
-                    $operands[$i]->removeNegations( $contextual_options );
210
+                    $operands[$i]->removeNegations($contextual_options);
211 211
                 }
212 212
             }
213 213
 
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
      *
228 228
      * @return $this;
229 229
      */
230
-    public function cleanOperations($simplification_options, $recurse=true)
230
+    public function cleanOperations($simplification_options, $recurse = true)
231 231
     {
232 232
         if ($recurse) {
233 233
             foreach ($this->operands as $i => $operand) {
234
-                if ( $operand instanceof AbstractOperationRule
235
-                && ! $operand instanceof InRule
236
-                && ! $operand instanceof NotEqualRule
237
-                && ! $operand instanceof NotInRule
234
+                if ($operand instanceof AbstractOperationRule
235
+                && !$operand instanceof InRule
236
+                && !$operand instanceof NotEqualRule
237
+                && !$operand instanceof NotInRule
238 238
             ) {
239 239
                     $this->operands[$i] = $operand->cleanOperations($simplification_options);
240 240
                 }
@@ -273,11 +273,11 @@  discard block
 block discarded – undo
273 273
     public function removeMonooperandOperationsOperands(array $simplification_options)
274 274
     {
275 275
         foreach ($this->operands as $i => $operand) {
276
-            if ( ! $operand instanceof AbstractOperationRule || $operand instanceof NotRule) {
276
+            if (!$operand instanceof AbstractOperationRule || $operand instanceof NotRule) {
277 277
                 continue;
278 278
             }
279 279
 
280
-            if ($operand instanceof InRule && ! $operand->isNormalizationAllowed($simplification_options)) {
280
+            if ($operand instanceof InRule && !$operand->isNormalizationAllowed($simplification_options)) {
281 281
                 $count = count($operand->getPossibilities());
282 282
             }
283 283
             else {
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
             }
295 295
         }
296 296
 
297
-        return ! empty($has_been_changed);
297
+        return !empty($has_been_changed);
298 298
     }
299 299
 
300 300
     /**
@@ -305,12 +305,12 @@  discard block
 block discarded – undo
305 305
     public function unifyAtomicOperands($simplification_strategy_step = false, array $contextual_options)
306 306
     {
307 307
         if ($simplification_strategy_step) {
308
-            $this->moveSimplificationStepForward( self::unify_atomic_operands, $contextual_options );
308
+            $this->moveSimplificationStepForward(self::unify_atomic_operands, $contextual_options);
309 309
         }
310 310
 
311 311
         // $this->dump(true);
312 312
 
313
-        if ( ! $this->isNormalizationAllowed($contextual_options)) {
313
+        if (!$this->isNormalizationAllowed($contextual_options)) {
314 314
             return $this;
315 315
         }
316 316
 
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
                 catch (\Exception $e) {
342 342
                     VisibilityViolator::setHiddenProperty(
343 343
                         $e, 'message',
344
-                        $e->getMessage() . "\n" . var_export($operandsByOperator, true)
344
+                        $e->getMessage()."\n".var_export($operandsByOperator, true)
345 345
                     );
346 346
 
347 347
                     throw $e;
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
             }
350 350
         }
351 351
 
352
-        return $this->setOperandsOrReplaceByOperation( $unifiedOperands, $contextual_options );
352
+        return $this->setOperandsOrReplaceByOperation($unifiedOperands, $contextual_options);
353 353
     }
354 354
 
355 355
     private static $simplification_cache = [];
@@ -365,13 +365,13 @@  discard block
 block discarded – undo
365 365
      *
366 366
      * @return AbstractRule the simplified rule
367 367
      */
368
-    final public function simplify($options=[])
368
+    final public function simplify($options = [])
369 369
     {
370
-        $step_to_stop_before = ! empty($options['stop_before'])        ? $options['stop_before'] : null;
371
-        $step_to_stop_after  = ! empty($options['stop_after'])         ? $options['stop_after']  : null;
372
-        $force_logical_core  = ! empty($options['force_logical_core']) ? $options['force_logical_core'] : false;
370
+        $step_to_stop_before = !empty($options['stop_before']) ? $options['stop_before'] : null;
371
+        $step_to_stop_after  = !empty($options['stop_after']) ? $options['stop_after'] : null;
372
+        $force_logical_core  = !empty($options['force_logical_core']) ? $options['force_logical_core'] : false;
373 373
 
374
-        if ($step_to_stop_before && ! in_array($step_to_stop_before, self::simplification_steps)) {
374
+        if ($step_to_stop_before && !in_array($step_to_stop_before, self::simplification_steps)) {
375 375
             throw new \InvalidArgumentException(
376 376
                 "Invalid simplification step to stop at: ".$step_to_stop_before
377 377
             );
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
         // $instance->dump(true);
407 407
 
408 408
         if (self::remove_negations == $step_to_stop_after ||
409
-            self::rootify_disjunctions == $step_to_stop_before ) {
409
+            self::rootify_disjunctions == $step_to_stop_before) {
410 410
             return $instance;
411 411
         }
412 412
 
@@ -418,18 +418,18 @@  discard block
 block discarded – undo
418 418
         // $instance->dump(true);
419 419
 
420 420
         if (self::rootify_disjunctions == $step_to_stop_after ||
421
-            self::unify_atomic_operands == $step_to_stop_before ) {
421
+            self::unify_atomic_operands == $step_to_stop_before) {
422 422
             return $instance;
423 423
         }
424 424
 
425
-        if ( ! $instance instanceof AbstractAtomicRule) {
425
+        if (!$instance instanceof AbstractAtomicRule) {
426 426
             $instance->cleanOperations($options);
427 427
             $instance->unifyAtomicOperands(true, $options);
428 428
 
429 429
             // $instance->dump(true);
430 430
 
431 431
             if (self::unify_atomic_operands == $step_to_stop_after ||
432
-                self::remove_invalid_branches == $step_to_stop_before ) {
432
+                self::remove_invalid_branches == $step_to_stop_before) {
433 433
                 return $instance;
434 434
             }
435 435
 
@@ -446,8 +446,8 @@  discard block
 block discarded – undo
446 446
         // last non recursive clean
447 447
         // TODO kind of monad|become|cese
448 448
         //@see https://github.com/jclaveau/php-logical-filter/issues/20
449
-        if ($instance instanceof AndRule || $instance instanceof OrRule ) {
450
-            if ( ! $instance->getOperands()) {
449
+        if ($instance instanceof AndRule || $instance instanceof OrRule) {
450
+            if (!$instance->getOperands()) {
451 451
                 return $instance;
452 452
             }
453 453
 
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
             $instance = $instance->forceLogicalCore();
467 467
             // for the simplification status at
468 468
             foreach ($operands = $instance->getOperands() as $andOperand) {
469
-                if ( ! $andOperand instanceof AndRule) {
469
+                if (!$andOperand instanceof AndRule) {
470 470
                     throw new \LogicException(
471 471
                         "A rule is intended to be an and case: \n"
472 472
                         .$andOperand
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 
487 487
         $cache_keys[] = $instance->getSemanticId().'-'.$options_id;
488 488
         foreach ($cache_keys as $cache_key) {
489
-            self::$simplification_cache[ $cache_key ] = $instance;
489
+            self::$simplification_cache[$cache_key] = $instance;
490 490
         }
491 491
 
492 492
         return $instance->copy();
@@ -509,15 +509,15 @@  discard block
 block discarded – undo
509 509
             // For FilteredValue and FilteredKey
510 510
             $field = (string) $field;
511 511
 
512
-            if ( ! isset($operandsByFields[ $field ])) {
513
-                $operandsByFields[ $field ] = [];
512
+            if (!isset($operandsByFields[$field])) {
513
+                $operandsByFields[$field] = [];
514 514
             }
515 515
 
516
-            if ( ! isset($operandsByFields[ $field ][ $operand::operator ])) {
517
-                $operandsByFields[ $field ][ $operand::operator ] = [];
516
+            if (!isset($operandsByFields[$field][$operand::operator])) {
517
+                $operandsByFields[$field][$operand::operator] = [];
518 518
             }
519 519
 
520
-            $operandsByFields[ $field ][ $operand::operator ][] = $operand;
520
+            $operandsByFields[$field][$operand::operator][] = $operand;
521 521
         }
522 522
 
523 523
         return $operandsByFields;
@@ -540,15 +540,15 @@  discard block
 block discarded – undo
540 540
             // For FilteredValue and FilteredKey
541 541
             $field = (string) $field;
542 542
 
543
-            if ( ! isset($operandsByFields[ $field ])) {
544
-                $operandsByFields[ $field ] = [];
543
+            if (!isset($operandsByFields[$field])) {
544
+                $operandsByFields[$field] = [];
545 545
             }
546 546
 
547
-            if ( ! isset($operandsByFields[ $field ][ $operand::operator ])) {
548
-                $operandsByFields[ $field ][ $operand::operator ] = [];
547
+            if (!isset($operandsByFields[$field][$operand::operator])) {
548
+                $operandsByFields[$field][$operand::operator] = [];
549 549
             }
550 550
 
551
-            $operandsByFields[ $field ][ $operand::operator ][] = $operand;
551
+            $operandsByFields[$field][$operand::operator][] = $operand;
552 552
         }
553 553
 
554 554
         return $operandsByFields;
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
      *
587 587
      * @return AbstractRule|null The operand if it exists or null
588 588
      */
589
-    protected function getOperandAt($index=0)
589
+    protected function getOperandAt($index = 0)
590 590
     {
591 591
         $operands = array_values($this->operands);
592 592
         if (isset($operands[$index])) {
Please login to merge, or discard this patch.
src/Rule/AbstractRule.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public static function findSymbolicOperator($english_operator)
35 35
     {
36
-        $association = array_flip( self::$ruleAliases );
37
-        if (isset($association[ $english_operator ])) {
38
-            return $association[ $english_operator ];
36
+        $association = array_flip(self::$ruleAliases);
37
+        if (isset($association[$english_operator])) {
38
+            return $association[$english_operator];
39 39
         }
40 40
 
41 41
         return $english_operator;
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
     public static function findEnglishOperator($symbolic_operator)
47 47
     {
48 48
         $association = self::$ruleAliases;
49
-        if (isset($association[ $symbolic_operator ])) {
50
-            return $association[ $symbolic_operator ];
49
+        if (isset($association[$symbolic_operator])) {
50
+            return $association[$symbolic_operator];
51 51
         }
52 52
 
53 53
         return $symbolic_operator;
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
      *
66 66
      * @return $this
67 67
      */
68
-    public static function generateSimpleRule($field, $type, $values, array $options=[])
68
+    public static function generateSimpleRule($field, $type, $values, array $options = [])
69 69
     {
70
-        $cache_key = hash('md4', serialize( func_get_args()) );
70
+        $cache_key = hash('md4', serialize(func_get_args()));
71 71
         if (isset(self::$static_cache['rules_generation'][$cache_key])) {
72 72
             return self::$static_cache['rules_generation'][$cache_key]->copy();
73 73
         }
74 74
 
75 75
         $ruleClass = self::getRuleClass($type);
76 76
 
77
-        return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass( $field, $values, $options );
77
+        return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass($field, $values, $options);
78 78
     }
79 79
 
80 80
     /**
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
             . str_replace('_', '', ucwords($english_rule_operator, '_'))
92 92
             . 'Rule';
93 93
 
94
-        if ( ! class_exists( $rule_class)) {
94
+        if (!class_exists($rule_class)) {
95 95
             throw new \InvalidArgumentException(
96 96
                 "The class '$rule_class' corresponding to the  operator "
97 97
                 ."'$rule_operator' / '$english_rule_operator' cannot be found."
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      *
121 121
      * @return $this
122 122
      */
123
-    final public function dump($exit=false, array $options=[])
123
+    final public function dump($exit = false, array $options = [])
124 124
     {
125 125
         $default_options = [
126 126
             'callstack_depth' => 2,
@@ -128,18 +128,18 @@  discard block
 block discarded – undo
128 128
             // 'show_instance'   => false,
129 129
         ];
130 130
         foreach ($default_options as $default_option => &$default_value) {
131
-            if ( ! isset($options[ $default_option ])) {
132
-                $options[ $default_option ] = $default_value;
131
+            if (!isset($options[$default_option])) {
132
+                $options[$default_option] = $default_value;
133 133
             }
134 134
         }
135 135
         extract($options);
136 136
 
137 137
         $bt     = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth);
138
-        $caller = $bt[ $callstack_depth - 2 ];
138
+        $caller = $bt[$callstack_depth - 2];
139 139
 
140
-        echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n";
140
+        echo "\n".$caller['file'].':'.$caller['line']."\n";
141 141
         if ('string' == $mode) {
142
-            if ( ! isset($options['indent_unit'])) {
142
+            if (!isset($options['indent_unit'])) {
143 143
                 $options['indent_unit'] = "    ";
144 144
             }
145 145
 
@@ -157,10 +157,10 @@  discard block
 block discarded – undo
157 157
             }
158 158
         }
159 159
         elseif ('xdebug' == $mode) {
160
-            if ( ! function_exists('xdebug_is_enabled')) {
160
+            if (!function_exists('xdebug_is_enabled')) {
161 161
                 throw new \RuntimeException("Xdebug is not installed");
162 162
             }
163
-            if ( ! xdebug_is_enabled()) {
163
+            if (!xdebug_is_enabled()) {
164 164
                 throw new \RuntimeException("Xdebug is disabled");
165 165
             }
166 166
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         else {
181 181
             throw new \InvalidArgumentException(
182 182
                  "'mode' option must belong to ['string', 'export', 'dump'] "
183
-                ."instead of " . var_export($mode, true)
183
+                ."instead of ".var_export($mode, true)
184 184
             );
185 185
         }
186 186
         echo "\n\n";
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
         }
263 263
 
264 264
         // return hash('crc32b', serialize( $this->toArray() ));
265
-        return hash('md4', serialize( $this->toArray(['semantic' => true]) ))  // faster but longer
265
+        return hash('md4', serialize($this->toArray(['semantic' => true])))  // faster but longer
266 266
               .'-'
267
-              .hash('md4', serialize( $this->options ))
267
+              .hash('md4', serialize($this->options))
268 268
               ;
269 269
     }
270 270
 
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
         }
297 297
         elseif ($this instanceof OrRule) {
298 298
             foreach ($this->operands as $i => $operand) {
299
-                if ( ! $operand instanceof AndRule) {
299
+                if (!$operand instanceof AndRule) {
300 300
                     $this->operands[$i] = new AndRule([$operand]);
301 301
                 }
302 302
             }
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -144,8 +144,7 @@  discard block
 block discarded – undo
144 144
             }
145 145
 
146 146
             echo ($this->toString($options));
147
-        }
148
-        elseif ('dump' == $mode) {
147
+        } elseif ('dump' == $mode) {
149 148
             if ($xdebug_enabled = ini_get('xdebug.overload_var_dump')) {
150 149
                 ini_set('xdebug.overload_var_dump', 0);
151 150
             }
@@ -155,8 +154,7 @@  discard block
 block discarded – undo
155 154
             if ($xdebug_enabled) {
156 155
                 ini_set('xdebug.overload_var_dump', 1);
157 156
             }
158
-        }
159
-        elseif ('xdebug' == $mode) {
157
+        } elseif ('xdebug' == $mode) {
160 158
             if ( ! function_exists('xdebug_is_enabled')) {
161 159
                 throw new \RuntimeException("Xdebug is not installed");
162 160
             }
@@ -173,11 +171,9 @@  discard block
 block discarded – undo
173 171
             if ($xdebug_enabled) {
174 172
                 ini_set('xdebug.overload_var_dump', 0);
175 173
             }
176
-        }
177
-        elseif ('export' == $mode) {
174
+        } elseif ('export' == $mode) {
178 175
             var_export($this->toArray($options));
179
-        }
180
-        else {
176
+        } else {
181 177
             throw new \InvalidArgumentException(
182 178
                  "'mode' option must belong to ['string', 'export', 'dump'] "
183 179
                 ."instead of " . var_export($mode, true)
@@ -288,21 +284,18 @@  discard block
 block discarded – undo
288 284
                     $this,
289 285
                 ]),
290 286
             ]);
291
-        }
292
-        elseif ($this instanceof AndRule) {
287
+        } elseif ($this instanceof AndRule) {
293 288
             $ruleTree = new OrRule([
294 289
                 $this,
295 290
             ]);
296
-        }
297
-        elseif ($this instanceof OrRule) {
291
+        } elseif ($this instanceof OrRule) {
298 292
             foreach ($this->operands as $i => $operand) {
299 293
                 if ( ! $operand instanceof AndRule) {
300 294
                     $this->operands[$i] = new AndRule([$operand]);
301 295
                 }
302 296
             }
303 297
             $ruleTree = $this;
304
-        }
305
-        else {
298
+        } else {
306 299
             throw new \LogicException(
307 300
                 "Unhandled type of simplified rules provided for conversion: "
308 301
                 .$this
Please login to merge, or discard this patch.
src/Rule/NotRule.php 1 patch
Braces   +14 added lines, -28 removed lines patch added patch discarded remove patch
@@ -60,37 +60,30 @@  discard block
 block discarded – undo
60 60
                 new BelowRule($field, $operand->getMinimum()),
61 61
                 new EqualRule($field, $operand->getMinimum()),
62 62
             ]);
63
-        }
64
-        elseif ($operand instanceof BelowRule) {
63
+        } elseif ($operand instanceof BelowRule) {
65 64
             // ! (v >  a) : v <= a : (v < a || a = v)
66 65
             $new_rule = new OrRule([
67 66
                 new AboveRule($field, $operand->getMaximum()),
68 67
                 new EqualRule($field, $operand->getMaximum()),
69 68
             ]);
70
-        }
71
-        elseif ($operand instanceof NotRule) {
69
+        } elseif ($operand instanceof NotRule) {
72 70
             // ! (  !  a) : a
73 71
             $new_rule = $operand->getOperandAt(0);
74
-        }
75
-        elseif ($operand instanceof EqualRule && null === $operand->getValue()) {
72
+        } elseif ($operand instanceof EqualRule && null === $operand->getValue()) {
76 73
             $new_rule = new NotEqualRule($field, null);
77
-        }
78
-        elseif ($operand instanceof EqualRule) {
74
+        } elseif ($operand instanceof EqualRule) {
79 75
             // ! (v =  a) : (v < a) || (v > a)
80 76
             if ($this->getOption('not_equal.normalization', $current_simplification_options)) {
81 77
                 $new_rule = new OrRule([
82 78
                     new AboveRule($field, $operand->getValue()),
83 79
                     new BelowRule($field, $operand->getValue()),
84 80
                 ]);
85
-            }
86
-            else {
81
+            } else {
87 82
                 $new_rule = new NotEqualRule( $field, $operand->getValue() );
88 83
             }
89
-        }
90
-        elseif ($operand instanceof NotEqualRule) {
84
+        } elseif ($operand instanceof NotEqualRule) {
91 85
             $new_rule = new EqualRule( $field, $operand->getValue() );
92
-        }
93
-        elseif ($operand instanceof AndRule) {
86
+        } elseif ($operand instanceof AndRule) {
94 87
             // @see https://github.com/jclaveau/php-logical-filter/issues/40
95 88
             // ! (B && A) : (!B && A) || (B && !A) || (!B && !A)
96 89
             // ! (A && B && C) :
@@ -138,8 +131,7 @@  discard block
 block discarded – undo
138 131
             $new_rule->setOperands( $combinations )
139 132
                 // ->dump(true)
140 133
                 ;
141
-        }
142
-        elseif ($operand instanceof OrRule) {
134
+        } elseif ($operand instanceof OrRule) {
143 135
 
144 136
             // $operand->dump(true);
145 137
             if (     $operand instanceof InRule
@@ -150,8 +142,7 @@  discard block
 block discarded – undo
150 142
                     $operand->getField(),
151 143
                     $operand->getPossibilities()
152 144
                 );
153
-            }
154
-            else {
145
+            } else {
155 146
                 // ! (A || B) : !A && !B
156 147
                 // ! (A || B || C || D) : !A && !B && !C && !D
157 148
                 $new_rule = new AndRule;
@@ -165,8 +156,7 @@  discard block
 block discarded – undo
165 156
                 }
166 157
             }
167 158
             // $new_rule->dump(!true);
168
-        }
169
-        else {
159
+        } else {
170 160
             throw new \LogicException(
171 161
                 'Removing NotRule(' . var_export($operand, true) . ') '
172 162
                 . ' not implemented'
@@ -250,8 +240,7 @@  discard block
 block discarded – undo
250 240
         // TODO make a dedicated cache entry for semantic array?
251 241
         if ( ! $options['show_instance'] && ! $options['semantic']) {
252 242
             return $this->cache['array'] = $array;
253
-        }
254
-        else {
243
+        } else {
255 244
             return $array;
256 245
         }
257 246
     }
@@ -307,19 +296,16 @@  discard block
 block discarded – undo
307 296
         if ($new_operand instanceof NotRule) {
308 297
             $operands = $new_operand->getOperands();
309 298
             return reset( $operands );
310
-        }
311
-        elseif ($new_operand instanceof EqualRule && ! $this->getOption('not_equal.normalization', $contextual_options)) {
299
+        } elseif ($new_operand instanceof EqualRule && ! $this->getOption('not_equal.normalization', $contextual_options)) {
312 300
             return new NotEqualRule( $new_operand->getField(), $new_operand->getValue(), $this->options );
313
-        }
314
-        elseif ($new_operand instanceof InRule && ! $this->getOption('not_in.normalization', $contextual_options)) {
301
+        } elseif ($new_operand instanceof InRule && ! $this->getOption('not_in.normalization', $contextual_options)) {
315 302
             return new NotInRule( $new_operand->getField(), $new_operand->getPossibilities(), $this->options );
316 303
         }
317 304
 
318 305
         try {
319 306
             // Don't use addOperand here to allow inheritance for optimizations (e.g. NotInRule)
320 307
             $out = $this->setOperands( $new_operands );
321
-        }
322
-        catch (\LogicException $e) {
308
+        } catch (\LogicException $e) {
323 309
             $out = new NotRule( $new_operand );
324 310
         }
325 311
 
Please login to merge, or discard this patch.
src/Rule/AboveOrEqualRule.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
18 18
      * @param string $field The field to apply the rule on.
19 19
      * @param array  $value The value the field can below to.
20 20
      */
21
-    public function __construct($field, $minimum, array $options=[])
21
+    public function __construct($field, $minimum, array $options = [])
22 22
     {
23
-        if ( ! empty($options)) {
23
+        if (!empty($options)) {
24 24
             $this->setOptions($options);
25 25
         }
26 26
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     /**
64 64
      * @return bool
65 65
      */
66
-    public function isNormalizationAllowed(array $contextual_options=[])
66
+    public function isNormalizationAllowed(array $contextual_options = [])
67 67
     {
68 68
         return $this->getOption('above_or_equal.normalization', $contextual_options);
69 69
     }
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      */
74 74
     public function getOperands()
75 75
     {
76
-        if ( ! empty($this->cache['operands'])) {
76
+        if (!empty($this->cache['operands'])) {
77 77
             return $this->cache['operands'];
78 78
         }
79 79
 
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
             }
106 106
         }
107 107
 
108
-        if (   2 != count($operands)
109
-            || ! isset($equalRuleValue)
110
-            || ! isset($aboveRuleValue)
108
+        if (2 != count($operands)
109
+            || !isset($equalRuleValue)
110
+            || !isset($aboveRuleValue)
111 111
             || $aboveRuleValue != $equalRuleValue
112 112
             || $aboveRuleField != $equalRuleField
113 113
         ) {
@@ -136,14 +136,14 @@  discard block
 block discarded – undo
136 136
      *
137 137
      * @return array
138 138
      */
139
-    public function toArray(array $options=[])
139
+    public function toArray(array $options = [])
140 140
     {
141 141
         $default_options = [
142 142
             'show_instance' => false,
143 143
         ];
144 144
         foreach ($default_options as $default_option => &$default_value) {
145
-            if ( ! isset($options[ $default_option ])) {
146
-                $options[ $default_option ] = $default_value;
145
+            if (!isset($options[$default_option])) {
146
+                $options[$default_option] = $default_value;
147 147
             }
148 148
         }
149 149
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 
163 163
     /**
164 164
      */
165
-    public function toString(array $options=[])
165
+    public function toString(array $options = [])
166 166
     {
167 167
         if (isset($this->cache['string'])) {
168 168
             return $this->cache['string'];
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 
171 171
         $operator = self::operator;
172 172
 
173
-        return $this->cache['string'] = "['{$this->getField()}', '$operator', " . var_export($this->getValues(), true). "]";
173
+        return $this->cache['string'] = "['{$this->getField()}', '$operator', ".var_export($this->getValues(), true)."]";
174 174
     }
175 175
 
176 176
     /**/
Please login to merge, or discard this patch.