Passed
Push — master ( dd4109...615914 )
by Jean
03:51 queued 36s
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,7 +352,7 @@  discard block
 block discarded – undo
352 352
 
353 353
             foreach ($operands_descriptions as $i => $operands_description) {
354 354
                 if (false === $operands_description) {
355
-                    $operands_descriptions[ $i ] = ['and']; // FalseRule hack
355
+                    $operands_descriptions[$i] = ['and']; // FalseRule hack
356 356
                 }
357 357
                 elseif (null === $operands_description || true === $operands_description) {
358 358
                     $operands_description = ['and'];
@@ -363,25 +363,25 @@  discard block
 block discarded – undo
363 363
                         );
364 364
                     }
365 365
 
366
-                    unset($operands_descriptions[ $i ]);
366
+                    unset($operands_descriptions[$i]);
367 367
                 }
368 368
             }
369 369
 
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
             );
379 379
 
380
-            if ( ! empty($remaining_operations)) {
380
+            if (!empty($remaining_operations)) {
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 (empty($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.