Passed
Push — master ( d2428f...19906d )
by Jean
02:52
created
src/Filterer/FiltererInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
      * @param LogicalFilter $filter
17 17
      * @param Iterable      $data_to_filter
18 18
      */
19
-    public function apply( LogicalFilter $filter, $tree_to_filter, $options=[] );
19
+    public function apply(LogicalFilter $filter, $tree_to_filter, $options = []);
20 20
 
21 21
     public function validateRule($field, $operator, $value, $row, array $path, $all_operands, $options);
22 22
 
Please login to merge, or discard this patch.
src/Filterer/Filterer.php 2 patches
Spacing   +20 added lines, -20 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])
@@ -154,14 +154,14 @@  discard block
 block discarded – undo
154 154
         return $this->foreachRow(
155 155
             $root_cases,
156 156
             $tree_to_filter,
157
-            $path=[],
157
+            $path = [],
158 158
             $options
159 159
         );
160 160
     }
161 161
 
162 162
     /**
163 163
      */
164
-    protected function foreachRow(array $root_cases, $tree_to_filter, array $path, $options=[])
164
+    protected function foreachRow(array $root_cases, $tree_to_filter, array $path, $options = [])
165 165
     {
166 166
         // Once the rules are prepared, we parse the data
167 167
         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])
@@ -242,14 +242,14 @@  discard block
 block discarded – undo
242 242
         return $this->applyOnRow(
243 243
             $root_cases,
244 244
             $row_to_check,
245
-            $path=[$key_to_check],
245
+            $path = [$key_to_check],
246 246
             $options
247 247
         );
248 248
     }
249 249
 
250 250
     /**
251 251
      */
252
-    protected function applyOnRow(array $root_cases, $row_to_filter, array $path, $options=[])
252
+    protected function applyOnRow(array $root_cases, $row_to_filter, array $path, $options = [])
253 253
     {
254 254
         $operands_validation_row_cache = [];
255 255
 
@@ -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 ($is_valid === false) {
Please login to merge, or discard this patch.
Braces   +25 added lines, -38 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
 
@@ -131,19 +127,18 @@  discard block
 block discarded – undo
131 127
             ;
132 128
 
133 129
         if ($root_OrRule !== null) {
134
-            if (!$root_OrRule->hasSolution())
135
-                return null;
130
+            if (!$root_OrRule->hasSolution()) {
131
+                            return null;
132
+            }
136 133
 
137 134
             $root_cases = $root_OrRule->getOperands();
138
-        }
139
-        else {
135
+        } else {
140 136
             $root_cases = [];
141 137
         }
142 138
 
143 139
         if (!isset($options['recurse'])) {
144 140
             $options['recurse'] = 'before';
145
-        }
146
-        elseif (!in_array($options['recurse'], ['before', 'after', null])) {
141
+        } elseif (!in_array($options['recurse'], ['before', 'after', null])) {
147 142
             throw new \InvalidArgumentException(
148 143
                 "Invalid value for 'recurse' option: "
149 144
                 .var_export($options['recurse'], true)
@@ -185,12 +180,10 @@  discard block
 block discarded – undo
185 180
 
186 181
             if ($matching_case) {
187 182
                 $this->onRowMatches($row_to_filter, $row_index, $tree_to_filter, $matching_case, $options);
188
-            }
189
-            elseif ($matching_case === false) {
183
+            } elseif ($matching_case === false) {
190 184
                 // No case match the rule
191 185
                 $this->onRowMismatches($row_to_filter, $row_index, $tree_to_filter, $matching_case, $options);
192
-            }
193
-            elseif ($matching_case === null) {
186
+            } elseif ($matching_case === null) {
194 187
                 // We simply avoid rules
195 188
                 // row out of scope
196 189
             }
@@ -230,12 +223,12 @@  discard block
 block discarded – undo
230 223
             ;
231 224
 
232 225
         if ($root_OrRule !== null) {
233
-            if (!$root_OrRule->hasSolution())
234
-                return null;
226
+            if (!$root_OrRule->hasSolution()) {
227
+                            return null;
228
+            }
235 229
 
236 230
             $root_cases = $root_OrRule->getOperands();
237
-        }
238
-        else {
231
+        } else {
239 232
             $root_cases = [];
240 233
         }
241 234
 
@@ -255,13 +248,13 @@  discard block
 block discarded – undo
255 248
 
256 249
         if (!$root_cases) {
257 250
             $matching_case = true;
258
-        }
259
-        else {
251
+        } else {
260 252
             $matching_case = null;
261 253
             foreach ($root_cases as $and_case_index => $and_case) {
262 254
 
263
-                if (!empty($options['debug']))
264
-                    var_dump("Case $and_case_index: ".$and_case);
255
+                if (!empty($options['debug'])) {
256
+                                    var_dump("Case $and_case_index: ".$and_case);
257
+                }
265 258
 
266 259
                 $case_is_good = null;
267 260
                 foreach ($and_case->getOperands() as $i => $rule) {
@@ -269,16 +262,14 @@  discard block
 block discarded – undo
269 262
                     if ($rule instanceof OrRule && $rule instanceof AndRule) {
270 263
                         $field = null;
271 264
                         $value = $rule->getOperands();
272
-                    }
273
-                    elseif ($rule instanceof NotEqualRule
265
+                    } elseif ($rule instanceof NotEqualRule
274 266
                         ||  $rule instanceof AbstractAtomicRule
275 267
                         ||  $rule instanceof InRule
276 268
                         ||  $rule instanceof NotInRule
277 269
                     ) {
278 270
                         $field = $rule->getField();
279 271
                         $value = $rule->getValues();
280
-                    }
281
-                    else {
272
+                    } else {
282 273
                         throw new \LogicException(
283 274
                             "Filtering with a rule which has not been simplified: $rule"
284 275
                         );
@@ -290,8 +281,7 @@  discard block
 block discarded – undo
290 281
 
291 282
                     if (!empty($operands_validation_row_cache[ $cache_key ])) {
292 283
                         $is_valid = $operands_validation_row_cache[ $cache_key ];
293
-                    }
294
-                    else {
284
+                    } else {
295 285
                         $is_valid = $this->validateRule(
296 286
                             $field,
297 287
                             $operator,
@@ -310,8 +300,7 @@  discard block
 block discarded – undo
310 300
                         // so all the and_case is invalid
311 301
                         $case_is_good = false;
312 302
                         break;
313
-                    }
314
-                    elseif ($is_valid === true) {
303
+                    } elseif ($is_valid === true) {
315 304
                         // one of the rules of the and_case do not validate
316 305
                         // so all the and_case is invalid
317 306
                         $case_is_good = true;
@@ -322,11 +311,9 @@  discard block
 block discarded – undo
322 311
                     // at least one and_case works so we can stop here
323 312
                     $matching_case = $and_case;
324 313
                     break;
325
-                }
326
-                elseif ($case_is_good === false) {
314
+                } elseif ($case_is_good === false) {
327 315
                     $matching_case = false;
328
-                }
329
-                elseif ($case_is_good === null) {
316
+                } elseif ($case_is_good === null) {
330 317
                     // row out of scope
331 318
                 }
332 319
             }
Please login to merge, or discard this patch.
src/Filterer/CustomizableFilterer.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
     /**
18 18
      */
19
-    public function __construct( callable $rule_validator )
19
+    public function __construct(callable $rule_validator)
20 20
     {
21 21
         $this->rule_validator = $rule_validator;
22 22
     }
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      */
26 26
     public function validateRule($field, $operator, $value, $row, array $path, $all_operands, $options)
27 27
     {
28
-        return call_user_func_array( $this->rule_validator, get_defined_vars() );
28
+        return call_user_func_array($this->rule_validator, get_defined_vars());
29 29
     }
30 30
 
31 31
     /**/
Please login to merge, or discard this patch.
src/Filterer/PhpFilterer.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 
40 40
         if ($operator === EqualRule::operator) {
41 41
             if (!isset($value_to_validate)) {
42
-                 // ['field', '=', null] <=> isset($row['field'])
43
-                 // [row, '=', null] <=> $row !== null
42
+                    // ['field', '=', null] <=> isset($row['field'])
43
+                    // [row, '=', null] <=> $row !== null
44 44
                 $result = $value === null;
45 45
             }
46 46
             else {
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
 
97 97
         // var_dump(
98 98
             // "$field, $operator, " . var_export($value, true)
99
-             // . ' vs ' . var_export($value_to_validate, true) . ' => ' . var_export($result, true)
100
-             // . "\n\n"
101
-             // . var_export($row, true)
99
+                // . ' vs ' . var_export($value_to_validate, true) . ' => ' . var_export($result, true)
100
+                // . "\n\n"
101
+                // . var_export($row, true)
102 102
         // );
103 103
         // exit;
104 104
         return $result;
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,19 +22,19 @@  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 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 ($operator === EqualRule::operator) {
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
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 = $value === null;
45
-            }
46
-            else {
42
+            } else {
47 43
                 // TODO support strict comparisons
48 44
                 $result = $value_to_validate == $value;
49 45
             }
50
-        }
51
-        elseif ($operator === InRule::operator) {
46
+        } elseif ($operator === InRule::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 ($operator === BelowRule::operator) {
52
+        } elseif ($operator === BelowRule::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 ($operator === AboveRule::operator) {
58
+        } elseif ($operator === AboveRule::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 ($operator === NotEqualRule::operator) {
64
+        } elseif ($operator === NotEqualRule::operator) {
76 65
             if ($value === null) {
77 66
                 $result = isset($value_to_validate);
78
-            }
79
-            else {
67
+            } else {
80 68
                 $result = $value_to_validate != $value;
81 69
             }
82
-        }
83
-        elseif ($operator === NotInRule::operator) {
70
+        } elseif ($operator === NotInRule::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/Filterer/RuleFilterer.php 3 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -189,9 +189,9 @@
 block discarded – undo
189 189
         if (!empty($options['debug'])) {
190 190
             var_dump(
191 191
                 "$field, $operator, " . var_export($value, true)
192
-                 . ' ||  '. $value_to_compare . ' => ' . var_export($out, true)
193
-                 . "\n" . get_class($rule)
194
-                 . "\n" . var_export($options, true)
192
+                    . ' ||  '. $value_to_compare . ' => ' . var_export($out, true)
193
+                    . "\n" . get_class($rule)
194
+                    . "\n" . var_export($options, true)
195 195
             );
196 196
             // $rule->dump();
197 197
         }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class RuleFilterer extends Filterer
34 34
 {
35
-    const this       = 'instance';
35
+    const this = 'instance';
36 36
     const field       = 'field';
37 37
     const operator    = 'operator';
38 38
     const value       = 'value';
@@ -59,20 +59,20 @@  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
     /**
69 69
      *
70 70
      * @return true | false | null
71 71
      */
72
-    public function validateRule ($field, $operator, $value, $rule, array $path, $all_operands, $options)
72
+    public function validateRule($field, $operator, $value, $rule, array $path, $all_operands, $options)
73 73
     {
74
-        if (    !empty($options[ Filterer::leaves_only ])
75
-            && in_array( get_class($rule), [OrRule::class, AndRule::class, NotRule::class] )
74
+        if (!empty($options[Filterer::leaves_only])
75
+            && in_array(get_class($rule), [OrRule::class, AndRule::class, NotRule::class])
76 76
         ) {
77 77
             // return true;
78 78
             return null;
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
         elseif ($field === self::value) {
99 99
             $description = $rule->toArray();
100 100
 
101
-            if (    count($description) === 3
101
+            if (count($description) === 3
102 102
                 &&  is_string($description[0])
103
-                &&  is_string($description[1]) ) {
103
+                &&  is_string($description[1])) {
104 104
                 $value_to_compare = $description[2];
105 105
             }
106 106
             else {
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         elseif ($field === self::children) {
123 123
             if (!method_exists($rule, 'getOperands'))
124 124
                 return null; // The filter cannot be applied to this rule
125
-            $value_to_compare = count( $rule->getOperands() );
125
+            $value_to_compare = count($rule->getOperands());
126 126
         }
127 127
         else {
128 128
             throw new \InvalidArgumentException(
@@ -182,16 +182,16 @@  discard block
 block discarded – undo
182 182
         }
183 183
         else {
184 184
             throw new \InvalidArgumentException(
185
-                "Unhandled operator: " . $operator
185
+                "Unhandled operator: ".$operator
186 186
             );
187 187
         }
188 188
 
189 189
         if (!empty($options['debug'])) {
190 190
             var_dump(
191
-                "$field, $operator, " . var_export($value, true)
192
-                 . ' ||  '. $value_to_compare . ' => ' . var_export($out, true)
193
-                 . "\n" . get_class($rule)
194
-                 . "\n" . var_export($options, true)
191
+                "$field, $operator, ".var_export($value, true)
192
+                 . ' ||  '.$value_to_compare.' => '.var_export($out, true)
193
+                 . "\n".get_class($rule)
194
+                 . "\n".var_export($options, true)
195 195
             );
196 196
             // $rule->dump();
197 197
         }
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      * @param array|AbstractRule $ruleTree_to_filter
205 205
      * @param array              $options leaves_only | debug
206 206
      */
207
-    public function apply( LogicalFilter $filter, $ruleTree_to_filter, $options=[] )
207
+    public function apply(LogicalFilter $filter, $ruleTree_to_filter, $options = [])
208 208
     {
209 209
         if (!$ruleTree_to_filter)
210 210
             return $ruleTree_to_filter;
@@ -215,14 +215,14 @@  discard block
 block discarded – undo
215 215
         if (!is_array($ruleTree_to_filter)) {
216 216
             throw new \InvalidArgumentException(
217 217
                 "\$ruleTree_to_filter must be an array or an AbstractRule "
218
-                ."instead of: " . var_export($ruleTree_to_filter, true)
218
+                ."instead of: ".var_export($ruleTree_to_filter, true)
219 219
             );
220 220
         }
221 221
 
222 222
         // Produces "Only variables should be passed by reference" on Travis
223 223
         $result = parent::apply($filter, $ruleTree_to_filter, $options);
224 224
 
225
-        return reset( $result );
225
+        return reset($result);
226 226
     }
227 227
 
228 228
     /**/
Please login to merge, or discard this patch.
Braces   +37 added lines, -47 removed lines patch added patch discarded remove patch
@@ -61,8 +61,10 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function setChildren( &$row, $filtered_children ) // strict issue if forcing  AbstractRule with php 5.6 here
63 63
     {
64
-        if ($row instanceof AbstractOperationRule)
65
-            return $row->setOperandsOrReplaceByOperation( $filtered_children, [] ); // no simplification options?
64
+        if ($row instanceof AbstractOperationRule) {
65
+                    return $row->setOperandsOrReplaceByOperation( $filtered_children, [] );
66
+        }
67
+        // no simplification options?
66 68
     }
67 69
 
68 70
     /**
@@ -79,52 +81,47 @@  discard block
 block discarded – undo
79 81
         }
80 82
 
81 83
         if ($field === self::field) {
82
-            if (!method_exists($rule, 'getField'))
83
-            // if (in_array( get_class($rule), [AndRule::class, OrRule::class]))
84
-                return null; // The filter cannot be applied to this rule
84
+            if (!method_exists($rule, 'getField')) {
85
+                        // if (in_array( get_class($rule), [AndRule::class, OrRule::class]))
86
+                return null;
87
+            }
88
+            // The filter cannot be applied to this rule
85 89
 
86 90
             try {
87 91
                 $value_to_compare = $rule->getField();
88
-            }
89
-            catch (\LogicException $e) {
92
+            } catch (\LogicException $e) {
90 93
                 // This is due to NotInRule.
91 94
                 // TODO replace it by a TrueRule in this case
92 95
                 return  null;
93 96
             }
94
-        }
95
-        elseif ($field === self::operator) {
97
+        } elseif ($field === self::operator) {
96 98
             $value_to_compare = $rule::operator;
97
-        }
98
-        elseif ($field === self::value) {
99
+        } elseif ($field === self::value) {
99 100
             $description = $rule->toArray();
100 101
 
101 102
             if (    count($description) === 3
102 103
                 &&  is_string($description[0])
103 104
                 &&  is_string($description[1]) ) {
104 105
                 $value_to_compare = $description[2];
105
-            }
106
-            else {
106
+            } else {
107 107
                 return null; // The filter cannot be applied to this rule
108 108
             }
109
-        }
110
-        elseif ($field === self::description) {
109
+        } elseif ($field === self::description) {
111 110
             $value_to_compare = $rule->toArray();
112
-        }
113
-        elseif ($field === self::depth) {
111
+        } elseif ($field === self::depth) {
114 112
             // original $depth is lost once the filter is simplified
115 113
             throw new \InvalidArgumentException('Depth rule uppport not implemented');
116 114
             // $value_to_compare = $depth;
117
-        }
118
-        elseif ($field === self::path) {
115
+        } elseif ($field === self::path) {
119 116
             // TODO the description of its parents
120 117
             throw new \InvalidArgumentException('Path rule uppport not implemented');
121
-        }
122
-        elseif ($field === self::children) {
123
-            if (!method_exists($rule, 'getOperands'))
124
-                return null; // The filter cannot be applied to this rule
118
+        } elseif ($field === self::children) {
119
+            if (!method_exists($rule, 'getOperands')) {
120
+                            return null;
121
+            }
122
+            // The filter cannot be applied to this rule
125 123
             $value_to_compare = count( $rule->getOperands() );
126
-        }
127
-        else {
124
+        } else {
128 125
             throw new \InvalidArgumentException(
129 126
                 "Rule filters must belong to ["
130 127
                 . implode(', ', [
@@ -143,22 +140,17 @@  discard block
 block discarded – undo
143 140
         if ($operator === EqualRule::operator) {
144 141
             if ($value === null) {
145 142
                 $out = is_null($value_to_compare);
146
-            }
147
-            else {
143
+            } else {
148 144
                 // TODO support strict comparisons
149 145
                 $out = $value_to_compare == $value;
150 146
             }
151
-        }
152
-        elseif ($operator === InRule::operator) {
147
+        } elseif ($operator === InRule::operator) {
153 148
             $out = in_array($value_to_compare, $value);
154
-        }
155
-        elseif ($operator === BelowRule::operator) {
149
+        } elseif ($operator === BelowRule::operator) {
156 150
             $out = $value_to_compare < $value;
157
-        }
158
-        elseif ($operator === AboveRule::operator) {
151
+        } elseif ($operator === AboveRule::operator) {
159 152
             $out = $value_to_compare > $value;
160
-        }
161
-        elseif ($operator === RegexpRule::operator) {
153
+        } elseif ($operator === RegexpRule::operator) {
162 154
             // TODO support optionnal parameters
163 155
             $out = preg_match($value, $value_to_compare);
164 156
             if ($out === false) {
@@ -168,19 +160,15 @@  discard block
 block discarded – undo
168 160
                 );
169 161
             }
170 162
             $out = (bool) $out;
171
-        }
172
-        elseif ($operator === NotEqualRule::operator) {
163
+        } elseif ($operator === NotEqualRule::operator) {
173 164
             if ($value === null) {
174 165
                 $out = !is_null($value_to_compare);
175
-            }
176
-            else {
166
+            } else {
177 167
                 $out = $value != $value_to_compare;
178 168
             }
179
-        }
180
-        elseif ($operator === NotInRule::operator) {
169
+        } elseif ($operator === NotInRule::operator) {
181 170
             $out = !in_array($value_to_compare, $value);
182
-        }
183
-        else {
171
+        } else {
184 172
             throw new \InvalidArgumentException(
185 173
                 "Unhandled operator: " . $operator
186 174
             );
@@ -206,11 +194,13 @@  discard block
 block discarded – undo
206 194
      */
207 195
     public function apply( LogicalFilter $filter, $ruleTree_to_filter, $options=[] )
208 196
     {
209
-        if (!$ruleTree_to_filter)
210
-            return $ruleTree_to_filter;
197
+        if (!$ruleTree_to_filter) {
198
+                    return $ruleTree_to_filter;
199
+        }
211 200
 
212
-        if ($ruleTree_to_filter instanceof AbstractRule)
213
-            $ruleTree_to_filter = [$ruleTree_to_filter];
201
+        if ($ruleTree_to_filter instanceof AbstractRule) {
202
+                    $ruleTree_to_filter = [$ruleTree_to_filter];
203
+        }
214 204
 
215 205
         if (!is_array($ruleTree_to_filter)) {
216 206
             throw new \InvalidArgumentException(
Please login to merge, or discard this patch.
src/Converter/ConverterInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
     /**
35 35
      * @param LogicalFilter $filter
36 36
      */
37
-    public function convert( LogicalFilter $filter );
37
+    public function convert(LogicalFilter $filter);
38 38
 
39 39
     /**/
40 40
 }
Please login to merge, or discard this patch.
src/Converter/MinimalConverter.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
                 foreach ($operandsByOperator as $operator => $operandsOfOperator) {
39 39
                     if (count($operandsOfOperator) != 1) {
40 40
                         throw new \RuntimeException(
41
-                             "Once a logical filter is simplified, there MUST be "
41
+                                "Once a logical filter is simplified, there MUST be "
42 42
                             ."no more than one operand by operator instead of for '$field' / '$operator': "
43 43
                             .var_export($operandsOfOperator, true)
44 44
                         );
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
     /**
19 19
      * @param LogicalFilter $filter
20 20
      */
21
-    public function convert( LogicalFilter $filter )
21
+    public function convert(LogicalFilter $filter)
22 22
     {
23 23
         $rootOr = $filter->simplify(['force_logical_core' => true])->getRules();
24 24
 
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
                         );
45 45
                     }
46 46
 
47
-                    $operandsByFields[ $field ][ $operator ] = $operandsOfOperator[0];
47
+                    $operandsByFields[$field][$operator] = $operandsOfOperator[0];
48 48
                 }
49 49
             }
50 50
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -23,11 +23,13 @@
 block discarded – undo
23 23
         $rootOr = $filter->simplify(['force_logical_core' => true])->getRules();
24 24
 
25 25
         // TODO remove this once TrueRule implemented https://github.com/jclaveau/php-logical-filter/issues/59
26
-        if ($rootOr === null)
27
-            return $this;
26
+        if ($rootOr === null) {
27
+                    return $this;
28
+        }
28 29
 
29
-        if (!$rootOr->hasSolution())
30
-            return $this;
30
+        if (!$rootOr->hasSolution()) {
31
+                    return $this;
32
+        }
31 33
 
32 34
         foreach ($rootOr->getOperands() as $andOperand) {
33 35
 
Please login to merge, or discard this patch.
src/Converter/CustomizableMinimalConverter.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,14 +30,14 @@  discard block
 block discarded – undo
30 30
      */
31 31
     public function onOpenOr()
32 32
     {
33
-        call_user_func( $this->callbacks[ __FUNCTION__ ] );
33
+        call_user_func($this->callbacks[__FUNCTION__]);
34 34
     }
35 35
 
36 36
     /**
37 37
      */
38 38
     public function onCloseOr()
39 39
     {
40
-        call_user_func( $this->callbacks[ __FUNCTION__ ] );
40
+        call_user_func($this->callbacks[__FUNCTION__]);
41 41
     }
42 42
 
43 43
     /**
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     public function onAndPossibility($field, $operator, $operand, array $allOperandsByField)
48 48
     {
49 49
         call_user_func(
50
-            $this->callbacks[ __FUNCTION__ ],
50
+            $this->callbacks[__FUNCTION__],
51 51
             $field,
52 52
             $operator,
53 53
             $operand,
Please login to merge, or discard this patch.
src/Converter/ElasticSearchMinimalConverter.php 3 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
                 // https://www.elastic.co/guide/en/elasticsearch/guide/current/_dealing_with_null_values.html#_missing_query
65 65
                 $new_rule = [
66 66
                     'missing' => [
67
-                         'field' => $field,
67
+                            'field' => $field,
68 68
                     ],
69 69
                 ];
70 70
             }
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
             // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
106 106
             $new_rule = [
107 107
                 'exists' => [
108
-                     'field' => $field,
108
+                        'field' => $field,
109 109
                 ],
110 110
             ];
111 111
         }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
             // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
114 114
             $new_rule = [
115 115
                 'regexp' => [
116
-                     $field => [
116
+                        $field => [
117 117
                         'value' => $operand->getPattern()
118 118
                         // 'flags' => 'INTERSECTION|COMPLEMENT|EMPTY',
119 119
                         // 'max_determinized_states' => 2000
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     /**
20 20
      * @param LogicalFilter $filter
21 21
      */
22
-    public function convert( LogicalFilter $filter )
22
+    public function convert(LogicalFilter $filter)
23 23
     {
24 24
         $this->output = [
25 25
         ];
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
     protected function appendToLastOrOperandKey($rule)
145 145
     {
146 146
         $last_key = $this->getLastOrOperandKey();
147
-        $this->output[ $last_key ]['bool']['must'][] = $rule;
147
+        $this->output[$last_key]['bool']['must'][] = $rule;
148 148
     }
149 149
 
150 150
     /**/
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -67,23 +67,20 @@  discard block
 block discarded – undo
67 67
                          'field' => $field,
68 68
                     ],
69 69
                 ];
70
-            }
71
-            else {
70
+            } else {
72 71
                 $new_rule = [
73 72
                     'term' => [
74 73
                         $field => $operand->getValue()
75 74
                     ]
76 75
                 ];
77 76
             }
78
-        }
79
-        elseif ($operator == 'in') {
77
+        } elseif ($operator == 'in') {
80 78
             $new_rule = [
81 79
                 'terms' => [
82 80
                     $field => $operand->getPossibilities()
83 81
                 ]
84 82
             ];
85
-        }
86
-        elseif ($operator == '<') {
83
+        } elseif ($operator == '<') {
87 84
             $new_rule = [
88 85
                 'range' => [
89 86
                     $field => [
@@ -91,8 +88,7 @@  discard block
 block discarded – undo
91 88
                     ],
92 89
                 ]
93 90
             ];
94
-        }
95
-        elseif ($operator == '>') {
91
+        } elseif ($operator == '>') {
96 92
             $new_rule = [
97 93
                 'range' => [
98 94
                     $field => [
@@ -100,8 +96,7 @@  discard block
 block discarded – undo
100 96
                     ],
101 97
                 ]
102 98
             ];
103
-        }
104
-        elseif ($operator == '<=') {
99
+        } elseif ($operator == '<=') {
105 100
             $new_rule = [
106 101
                 'range' => [
107 102
                     $field => [
@@ -109,8 +104,7 @@  discard block
 block discarded – undo
109 104
                     ],
110 105
                 ]
111 106
             ];
112
-        }
113
-        elseif ($operator == '>=') {
107
+        } elseif ($operator == '>=') {
114 108
             $new_rule = [
115 109
                 'range' => [
116 110
                     $field => [
@@ -118,16 +112,14 @@  discard block
 block discarded – undo
118 112
                     ],
119 113
                 ]
120 114
             ];
121
-        }
122
-        elseif ($operator == '!=' && $operand->getValue() === null) {
115
+        } elseif ($operator == '!=' && $operand->getValue() === null) {
123 116
             // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
124 117
             $new_rule = [
125 118
                 'exists' => [
126 119
                      'field' => $field,
127 120
                 ],
128 121
             ];
129
-        }
130
-        elseif ($operator == 'regexp') {
122
+        } elseif ($operator == 'regexp') {
131 123
             // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
132 124
             $new_rule = [
133 125
                 'regexp' => [
@@ -138,8 +130,7 @@  discard block
 block discarded – undo
138 130
                     ],
139 131
                 ],
140 132
             ];
141
-        }
142
-        else {
133
+        } else {
143 134
             throw new \InvalidArgumentException(
144 135
                 "Unhandled operator '$operator' during ES query generation"
145 136
             );
Please login to merge, or discard this patch.