Completed
Branch master (d9626b)
by Jean
04:22
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/InlineSqlMinimalConverter.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
     /**
48 48
      * @param LogicalFilter $filter
49 49
      */
50
-    public function convert( LogicalFilter $filter )
50
+    public function convert(LogicalFilter $filter)
51 51
     {
52 52
         $this->output = [];
53 53
         parent::convert($filter);
54 54
         return [
55
-            'sql' => ! $this->output
55
+            'sql' => !$this->output
56 56
                    ? '1' // True
57 57
                    : '('.implode(') OR (', $this->output).')',
58 58
             'parameters' => $this->parameters,
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
     public function onCloseOr()
72 72
     {
73 73
         $last_key = $this->getLastOrOperandKey();
74
-        $this->output[ $last_key ] = implode(' AND ', $this->output[ $last_key ]);
74
+        $this->output[$last_key] = implode(' AND ', $this->output[$last_key]);
75 75
     }
76 76
 
77 77
     /**
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
             $value = $rule->getValue();
101 101
         }
102 102
         elseif ($rule instanceof RegexpRule) {
103
-            $value = RegexpRule::php2mariadbPCRE( $rule->getPattern() );
103
+            $value = RegexpRule::php2mariadbPCRE($rule->getPattern());
104 104
         }
105 105
         else {
106 106
             throw new \InvalidArgumentException(
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
             foreach ($value as $possibility) {
125 125
                 $sql_part[] = $this->addParameter($possibility);
126 126
             }
127
-            $value = '(' . implode(', ', $sql_part) . ')';
127
+            $value = '('.implode(', ', $sql_part).')';
128 128
         }
129 129
         elseif ($value === null) {
130 130
             $value = "NULL";
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
         }
143 143
         else {
144 144
             throw new \InvalidArgumentException(
145
-                "Unhandled type of value: ".gettype($value). ' | ' .var_export($value, true)
145
+                "Unhandled type of value: ".gettype($value).' | '.var_export($value, true)
146 146
             );
147 147
         }
148 148
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
     protected function appendToLastOrOperandKey($rule)
168 168
     {
169 169
         $last_key = $this->getLastOrOperandKey();
170
-        $this->output[ $last_key ][] = $rule;
170
+        $this->output[$last_key][] = $rule;
171 171
     }
172 172
 
173 173
     /**/
Please login to merge, or discard this patch.
Braces   +21 added lines, -34 removed lines patch added patch discarded remove patch
@@ -31,13 +31,15 @@  discard block
 block discarded – undo
31 31
      */
32 32
     public function addParameter($value)
33 33
     {
34
-        if (is_numeric($value))
35
-            return $value;
34
+        if (is_numeric($value)) {
35
+                    return $value;
36
+        }
36 37
 
37 38
         $uid = 'param_'.hash('crc32b', serialize($value));
38 39
 
39
-        if (isset($this->parameters[$uid]))
40
-            return ':'.$uid;
40
+        if (isset($this->parameters[$uid])) {
41
+                    return ':'.$uid;
42
+        }
41 43
 
42 44
         $this->parameters[$uid] = $value;
43 45
 
@@ -82,65 +84,50 @@  discard block
 block discarded – undo
82 84
     {
83 85
         if ($rule instanceof EqualRule) {
84 86
             $value = $rule->getValue();
85
-        }
86
-        elseif ($rule instanceof InRule) {
87
+        } elseif ($rule instanceof InRule) {
87 88
             $value = $rule->getPossibilities();
88
-        }
89
-        elseif ($rule instanceof NotInRule) {
89
+        } elseif ($rule instanceof NotInRule) {
90 90
             $operator = 'NOT IN';
91 91
             $value = $rule->getPossibilities();
92
-        }
93
-        elseif ($rule instanceof AboveRule) {
92
+        } elseif ($rule instanceof AboveRule) {
94 93
             $value = $rule->getMinimum();
95
-        }
96
-        elseif ($rule instanceof BelowRule) {
94
+        } elseif ($rule instanceof BelowRule) {
97 95
             $value = $rule->getMaximum();
98
-        }
99
-        elseif ($rule instanceof NotEqualRule) {
96
+        } elseif ($rule instanceof NotEqualRule) {
100 97
             $value = $rule->getValue();
101
-        }
102
-        elseif ($rule instanceof RegexpRule) {
98
+        } elseif ($rule instanceof RegexpRule) {
103 99
             $value = RegexpRule::php2mariadbPCRE( $rule->getPattern() );
104
-        }
105
-        else {
100
+        } else {
106 101
             throw new \InvalidArgumentException(
107 102
                 "Unhandled operator '$operator' during SQL query generation"
108 103
             );
109 104
         }
110 105
 
111 106
         if (gettype($value) == 'integer') {
112
-        }
113
-        elseif (gettype($value) == 'double') {
107
+        } elseif (gettype($value) == 'double') {
114 108
             // TODO disable locale to handle separators
115
-        }
116
-        elseif ($value instanceof \DateTime) {
109
+        } elseif ($value instanceof \DateTime) {
117 110
             $value = $value->format('Y-m-d H:i:s');
118
-        }
119
-        elseif (gettype($value) == 'string') {
111
+        } elseif (gettype($value) == 'string') {
120 112
             $value = $this->addParameter($value);
121
-        }
122
-        elseif (gettype($value) == 'array') {
113
+        } elseif (gettype($value) == 'array') {
123 114
             $sql_part = [];
124 115
             foreach ($value as $possibility) {
125 116
                 $sql_part[] = $this->addParameter($possibility);
126 117
             }
127 118
             $value = '(' . implode(', ', $sql_part) . ')';
128
-        }
129
-        elseif ($value === null) {
119
+        } elseif ($value === null) {
130 120
             $value = "NULL";
131 121
             if ($rule instanceof EqualRule) {
132 122
                 $operator = 'IS';
133
-            }
134
-            elseif ($rule instanceof NotEqualRule) {
123
+            } elseif ($rule instanceof NotEqualRule) {
135 124
                 $operator = 'IS NOT';
136
-            }
137
-            else {
125
+            } else {
138 126
                 throw new \InvalidArgumentException(
139 127
                     "NULL is only handled for equality / difference"
140 128
                 );
141 129
             }
142
-        }
143
-        else {
130
+        } else {
144 131
             throw new \InvalidArgumentException(
145 132
                 "Unhandled type of value: ".gettype($value). ' | ' .var_export($value, true)
146 133
             );
Please login to merge, or discard this patch.