Test Failed
Push — master ( 6c792f...176748 )
by Jean
02:26
created
src/Rule/AbstractOperationRule.php 2 patches
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     const remove_negations        = 'remove_negations';
21 21
     const rootify_disjunctions    = 'rootify_disjunctions';
22 22
     const unify_atomic_operands   = 'unify_atomic_operands';
23
-    const remove_invalid_branches = 'remove_invalid_branches';    // simplified after this step
23
+    const remove_invalid_branches = 'remove_invalid_branches'; // simplified after this step
24 24
 
25 25
     const simplified              = self::remove_invalid_branches;
26 26
 
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 
44 44
     /**
45 45
      */
46
-    public function __construct( array $operands=[] )
46
+    public function __construct(array $operands = [])
47 47
     {
48
-        $this->setOperands( $operands );
48
+        $this->setOperands($operands);
49 49
         $this->flushCache();
50 50
     }
51 51
 
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
      *
65 65
      * @return $this
66 66
      */
67
-    public function addOperand( AbstractRule $new_operand )
67
+    public function addOperand(AbstractRule $new_operand)
68 68
     {
69
-        if (!isset($this->operands[ $id = $new_operand->getSemanticId() ])) {
70
-            $this->operands[ $id ] = $new_operand;
69
+        if (!isset($this->operands[$id = $new_operand->getSemanticId()])) {
70
+            $this->operands[$id] = $new_operand;
71 71
 
72 72
             if ($this->current_simplification_step)
73 73
                 $this->current_simplification_step = null;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public function getOperands()
85 85
     {
86
-        return array_values( $this->operands );
86
+        return array_values($this->operands);
87 87
     }
88 88
 
89 89
     /**
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
     /**
124 124
      * @param string $step_to_go_to
125 125
      */
126
-    public function moveSimplificationStepForward($step_to_go_to, array $simplification_options, $force=false)
126
+    public function moveSimplificationStepForward($step_to_go_to, array $simplification_options, $force = false)
127 127
     {
128 128
         if (!in_array($step_to_go_to, self::simplification_steps)) {
129 129
             throw new \InvalidArgumentException(
@@ -135,18 +135,18 @@  discard block
 block discarded – undo
135 135
         if (!$force && $this->current_simplification_step != null) {
136 136
             $steps_indices = array_flip(self::simplification_steps);
137 137
 
138
-            $current_index = $steps_indices[ $this->current_simplification_step ];
139
-            $target_index  = $steps_indices[ $step_to_go_to ];
138
+            $current_index = $steps_indices[$this->current_simplification_step];
139
+            $target_index  = $steps_indices[$step_to_go_to];
140 140
 
141
-            if ( $current_index >= $target_index ) {
141
+            if ($current_index >= $target_index) {
142 142
                 // allow recall of previous step without going back
143 143
                 return;
144 144
             }
145
-            elseif ( $current_index < $target_index - 1 ) {
145
+            elseif ($current_index < $target_index - 1) {
146 146
                 throw new \LogicException(
147
-                    "$step_to_go_to MUST be fullfilled after " . self::simplification_steps[$target_index - 1]
148
-                    . " instead of the current step: " . $this->current_simplification_step
149
-                    ."\nfor: " . $this
147
+                    "$step_to_go_to MUST be fullfilled after ".self::simplification_steps[$target_index - 1]
148
+                    . " instead of the current step: ".$this->current_simplification_step
149
+                    ."\nfor: ".$this
150 150
                 );
151 151
             }
152 152
         }
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
 
175 175
         $steps_indices = array_flip(self::simplification_steps);
176 176
 
177
-        $current_index = $steps_indices[ $this->current_simplification_step ];
178
-        $step_index    = $steps_indices[ $step ];
177
+        $current_index = $steps_indices[$this->current_simplification_step];
178
+        $step_index    = $steps_indices[$step];
179 179
 
180 180
         return $current_index >= $step_index;
181 181
     }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
                 }
203 203
 
204 204
                 if ($operands[$i] instanceof AbstractOperationRule) {
205
-                    $operands[$i]->removeNegations( $contextual_options );
205
+                    $operands[$i]->removeNegations($contextual_options);
206 206
                 }
207 207
             }
208 208
 
@@ -222,10 +222,10 @@  discard block
 block discarded – undo
222 222
      *
223 223
      * @return $this;
224 224
      */
225
-    public function cleanOperations($simplification_options, $recurse=true)
225
+    public function cleanOperations($simplification_options, $recurse = true)
226 226
     {
227 227
         if ($recurse) foreach ($this->operands as $i => $operand) {
228
-            if (    $operand instanceof AbstractOperationRule
228
+            if ($operand instanceof AbstractOperationRule
229 229
                 && !$operand instanceof InRule
230 230
                 && !$operand instanceof NotEqualRule
231 231
                 && !$operand instanceof NotInRule
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
     public function unifyAtomicOperands($simplification_strategy_step = false, array $contextual_options)
295 295
     {
296 296
         if ($simplification_strategy_step)
297
-            $this->moveSimplificationStepForward( self::unify_atomic_operands, $contextual_options );
297
+            $this->moveSimplificationStepForward(self::unify_atomic_operands, $contextual_options);
298 298
 
299 299
         // $this->dump(true);
300 300
 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                 catch (\Exception $e) {
329 329
                     VisibilityViolator::setHiddenProperty(
330 330
                         $e, 'message',
331
-                        $e->getMessage() . "\n" . var_export($operandsByOperator, true)
331
+                        $e->getMessage()."\n".var_export($operandsByOperator, true)
332 332
                     );
333 333
 
334 334
                     throw $e;
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
             }
337 337
         }
338 338
 
339
-        return $this->setOperandsOrReplaceByOperation( $unifiedOperands, $contextual_options );
339
+        return $this->setOperandsOrReplaceByOperation($unifiedOperands, $contextual_options);
340 340
     }
341 341
 
342 342
     private static $simplification_cache = [];
@@ -352,10 +352,10 @@  discard block
 block discarded – undo
352 352
      *
353 353
      * @return AbstractRule the simplified rule
354 354
      */
355
-    public final function simplify($options=[])
355
+    public final function simplify($options = [])
356 356
     {
357
-        $step_to_stop_before = !empty($options['stop_before'])        ? $options['stop_before'] : null;
358
-        $step_to_stop_after  = !empty($options['stop_after'])         ? $options['stop_after']  : null;
357
+        $step_to_stop_before = !empty($options['stop_before']) ? $options['stop_before'] : null;
358
+        $step_to_stop_after  = !empty($options['stop_after']) ? $options['stop_after'] : null;
359 359
         $force_logical_core  = !empty($options['force_logical_core']) ? $options['force_logical_core'] : false;
360 360
 
361 361
         if ($step_to_stop_before && !in_array($step_to_stop_before, self::simplification_steps)) {
@@ -390,8 +390,8 @@  discard block
 block discarded – undo
390 390
 
391 391
         // $instance->dump(true);
392 392
 
393
-        if ($step_to_stop_after  == self::remove_negations ||
394
-            $step_to_stop_before == self::rootify_disjunctions )
393
+        if ($step_to_stop_after == self::remove_negations ||
394
+            $step_to_stop_before == self::rootify_disjunctions)
395 395
             return $instance;
396 396
 
397 397
         // $instance->dump(true);
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
 
404 404
         // $instance->dump(true);
405 405
 
406
-        if ($step_to_stop_after  == self::rootify_disjunctions ||
407
-            $step_to_stop_before == self::unify_atomic_operands )
406
+        if ($step_to_stop_after == self::rootify_disjunctions ||
407
+            $step_to_stop_before == self::unify_atomic_operands)
408 408
             return $instance;
409 409
 
410 410
         if (!$instance instanceof AbstractAtomicRule) {
@@ -414,8 +414,8 @@  discard block
 block discarded – undo
414 414
 
415 415
             // $instance->dump(true);
416 416
 
417
-            if ($step_to_stop_after  == self::unify_atomic_operands ||
418
-                $step_to_stop_before == self::remove_invalid_branches )
417
+            if ($step_to_stop_after == self::unify_atomic_operands ||
418
+                $step_to_stop_before == self::remove_invalid_branches)
419 419
                 return $instance;
420 420
 
421 421
             $instance->cleanOperations($options);
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
         // last non recursive clean
432 432
         // TODO kind of monad|become|cese
433 433
         //@see https://github.com/jclaveau/php-logical-filter/issues/20
434
-        if ($instance instanceof AndRule || $instance instanceof OrRule ) {
434
+        if ($instance instanceof AndRule || $instance instanceof OrRule) {
435 435
 
436 436
             if (!$instance->getOperands())
437 437
                 return $instance;
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 
471 471
         $cache_keys[] = $instance->getSemanticId().'-'.$options_id;
472 472
         foreach ($cache_keys as $cache_key) {
473
-            self::$simplification_cache[ $cache_key ] = $instance;
473
+            self::$simplification_cache[$cache_key] = $instance;
474 474
         }
475 475
 
476 476
         return $instance->copy();
@@ -493,13 +493,13 @@  discard block
 block discarded – undo
493 493
             // For FilteredValue and FilteredKey
494 494
             $field = (string) $field;
495 495
 
496
-            if (!isset($operandsByFields[ $field ]))
497
-                $operandsByFields[ $field ] = [];
496
+            if (!isset($operandsByFields[$field]))
497
+                $operandsByFields[$field] = [];
498 498
 
499
-            if (!isset($operandsByFields[ $field ][ $operand::operator ]))
500
-                $operandsByFields[ $field ][ $operand::operator ] = [];
499
+            if (!isset($operandsByFields[$field][$operand::operator]))
500
+                $operandsByFields[$field][$operand::operator] = [];
501 501
 
502
-            $operandsByFields[ $field ][ $operand::operator ][] = $operand;
502
+            $operandsByFields[$field][$operand::operator][] = $operand;
503 503
         }
504 504
 
505 505
         return $operandsByFields;
@@ -522,13 +522,13 @@  discard block
 block discarded – undo
522 522
             // For FilteredValue and FilteredKey
523 523
             $field = (string) $field;
524 524
 
525
-            if (!isset($operandsByFields[ $field ]))
526
-                $operandsByFields[ $field ] = [];
525
+            if (!isset($operandsByFields[$field]))
526
+                $operandsByFields[$field] = [];
527 527
 
528
-            if (!isset($operandsByFields[ $field ][ $operand::operator ]))
529
-                $operandsByFields[ $field ][ $operand::operator ] = [];
528
+            if (!isset($operandsByFields[$field][$operand::operator]))
529
+                $operandsByFields[$field][$operand::operator] = [];
530 530
 
531
-            $operandsByFields[ $field ][ $operand::operator ][] = $operand;
531
+            $operandsByFields[$field][$operand::operator][] = $operand;
532 532
         }
533 533
 
534 534
         return $operandsByFields;
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
      *
567 567
      * @return AbstractRule|null The operand if it exists or null
568 568
      */
569
-    protected function getOperandAt($index=0)
569
+    protected function getOperandAt($index = 0)
570 570
     {
571 571
         $operands = array_values($this->operands);
572 572
         if (isset($operands[$index]))
Please login to merge, or discard this patch.
Braces   +74 added lines, -53 removed lines patch added patch discarded remove patch
@@ -69,8 +69,9 @@  discard block
 block discarded – undo
69 69
         if (!isset($this->operands[ $id = $new_operand->getSemanticId() ])) {
70 70
             $this->operands[ $id ] = $new_operand;
71 71
 
72
-            if ($this->current_simplification_step)
73
-                $this->current_simplification_step = null;
72
+            if ($this->current_simplification_step) {
73
+                            $this->current_simplification_step = null;
74
+            }
74 75
 
75 76
             $this->flushCache();
76 77
         }
@@ -108,10 +109,11 @@  discard block
 block discarded – undo
108 109
     public function renameFields($renamings)
109 110
     {
110 111
         foreach ($this->operands as $operand) {
111
-            if (method_exists($operand, 'renameField'))
112
-                $operand->renameField($renamings);
113
-            else
114
-                $operand->renameFields($renamings);
112
+            if (method_exists($operand, 'renameField')) {
113
+                            $operand->renameField($renamings);
114
+            } else {
115
+                            $operand->renameFields($renamings);
116
+            }
115 117
         }
116 118
 
117 119
         // TODO flush cache only in case of change?
@@ -141,8 +143,7 @@  discard block
 block discarded – undo
141 143
             if ( $current_index >= $target_index ) {
142 144
                 // allow recall of previous step without going back
143 145
                 return;
144
-            }
145
-            elseif ( $current_index < $target_index - 1 ) {
146
+            } elseif ( $current_index < $target_index - 1 ) {
146 147
                 throw new \LogicException(
147 148
                     "$step_to_go_to MUST be fullfilled after " . self::simplification_steps[$target_index - 1]
148 149
                     . " instead of the current step: " . $this->current_simplification_step
@@ -169,8 +170,9 @@  discard block
 block discarded – undo
169 170
             );
170 171
         }
171 172
 
172
-        if ($this->current_simplification_step == null)
173
-            return false;
173
+        if ($this->current_simplification_step == null) {
174
+                    return false;
175
+        }
174 176
 
175 177
         $steps_indices = array_flip(self::simplification_steps);
176 178
 
@@ -187,8 +189,9 @@  discard block
 block discarded – undo
187 189
      */
188 190
     public function removeNegations(array $contextual_options)
189 191
     {
190
-        if (!$this->isNormalizationAllowed($contextual_options))
191
-            return $this;
192
+        if (!$this->isNormalizationAllowed($contextual_options)) {
193
+                    return $this;
194
+        }
192 195
 
193 196
         $this->moveSimplificationStepForward(self::remove_negations, $contextual_options);
194 197
 
@@ -224,28 +227,33 @@  discard block
 block discarded – undo
224 227
      */
225 228
     public function cleanOperations($simplification_options, $recurse=true)
226 229
     {
227
-        if ($recurse) foreach ($this->operands as $i => $operand) {
230
+        if ($recurse) {
231
+            foreach ($this->operands as $i => $operand) {
228 232
             if (    $operand instanceof AbstractOperationRule
229 233
                 && !$operand instanceof InRule
230 234
                 && !$operand instanceof NotEqualRule
231 235
                 && !$operand instanceof NotInRule
232 236
             ) {
233 237
                 $this->operands[$i] = $operand->cleanOperations($simplification_options);
238
+        }
234 239
             }
235 240
         }
236 241
 
237
-        if ($this instanceof NotRule)
238
-            return $this;
242
+        if ($this instanceof NotRule) {
243
+                    return $this;
244
+        }
239 245
 
240 246
         $is_modified = true;
241 247
         while ($is_modified) {
242 248
             $is_modified = false;
243 249
 
244
-            if ($this->removeMonooperandOperationsOperands($simplification_options))
245
-                $is_modified = true;
250
+            if ($this->removeMonooperandOperationsOperands($simplification_options)) {
251
+                            $is_modified = true;
252
+            }
246 253
 
247
-            if ($this->removeSameOperationOperands($simplification_options))
248
-                $is_modified = true;
254
+            if ($this->removeSameOperationOperands($simplification_options)) {
255
+                            $is_modified = true;
256
+            }
249 257
         }
250 258
 
251 259
         return $this;
@@ -263,13 +271,13 @@  discard block
 block discarded – undo
263 271
     public function removeMonooperandOperationsOperands(array $simplification_options)
264 272
     {
265 273
         foreach ($this->operands as $i => $operand) {
266
-            if (!$operand instanceof AbstractOperationRule || $operand instanceof NotRule)
267
-                continue;
274
+            if (!$operand instanceof AbstractOperationRule || $operand instanceof NotRule) {
275
+                            continue;
276
+            }
268 277
 
269 278
             if ($operand instanceof InRule && !$operand->isNormalizationAllowed($simplification_options)) {
270 279
                 $count = count($operand->getPossibilities());
271
-            }
272
-            else {
280
+            } else {
273 281
                 $count = count($operand->getOperands());
274 282
             }
275 283
 
@@ -293,13 +301,15 @@  discard block
 block discarded – undo
293 301
      */
294 302
     public function unifyAtomicOperands($simplification_strategy_step = false, array $contextual_options)
295 303
     {
296
-        if ($simplification_strategy_step)
297
-            $this->moveSimplificationStepForward( self::unify_atomic_operands, $contextual_options );
304
+        if ($simplification_strategy_step) {
305
+                    $this->moveSimplificationStepForward( self::unify_atomic_operands, $contextual_options );
306
+        }
298 307
 
299 308
         // $this->dump(true);
300 309
 
301
-        if (!$this->isNormalizationAllowed($contextual_options))
302
-            return $this;
310
+        if (!$this->isNormalizationAllowed($contextual_options)) {
311
+                    return $this;
312
+        }
303 313
 
304 314
         $operands = $this->getOperands();
305 315
         foreach ($operands as &$operand) {
@@ -324,8 +334,7 @@  discard block
 block discarded – undo
324 334
             foreach ($operandsByOperator as $operator => $operands) {
325 335
                 try {
326 336
                     $unifiedOperands = array_merge($unifiedOperands, $operands);
327
-                }
328
-                catch (\Exception $e) {
337
+                } catch (\Exception $e) {
329 338
                     VisibilityViolator::setHiddenProperty(
330 339
                         $e, 'message',
331 340
                         $e->getMessage() . "\n" . var_export($operandsByOperator, true)
@@ -368,8 +377,9 @@  discard block
 block discarded – undo
368 377
         $options_id = hash('md4', serialize($options));
369 378
 
370 379
         $id = $this->getSemanticId().'-'.$options_id;
371
-        if (isset(self::$simplification_cache[$id]))
372
-            return self::$simplification_cache[$id]->copy();
380
+        if (isset(self::$simplification_cache[$id])) {
381
+                    return self::$simplification_cache[$id]->copy();
382
+        }
373 383
 
374 384
         $this->flushCache();
375 385
 
@@ -382,8 +392,9 @@  discard block
 block discarded – undo
382 392
 
383 393
         $cache_keys[] = $instance->getSemanticId().'-'.$options_id;
384 394
 
385
-        if ($step_to_stop_before == self::remove_negations)
386
-            return $instance;
395
+        if ($step_to_stop_before == self::remove_negations) {
396
+                    return $instance;
397
+        }
387 398
 
388 399
         // $this->dump(!true);
389 400
         $instance = $instance->removeNegations($options);
@@ -391,8 +402,9 @@  discard block
 block discarded – undo
391 402
         // $instance->dump(true);
392 403
 
393 404
         if ($step_to_stop_after  == self::remove_negations ||
394
-            $step_to_stop_before == self::rootify_disjunctions )
395
-            return $instance;
405
+            $step_to_stop_before == self::rootify_disjunctions ) {
406
+                    return $instance;
407
+        }
396 408
 
397 409
         // $instance->dump(true);
398 410
 
@@ -404,8 +416,9 @@  discard block
 block discarded – undo
404 416
         // $instance->dump(true);
405 417
 
406 418
         if ($step_to_stop_after  == self::rootify_disjunctions ||
407
-            $step_to_stop_before == self::unify_atomic_operands )
408
-            return $instance;
419
+            $step_to_stop_before == self::unify_atomic_operands ) {
420
+                    return $instance;
421
+        }
409 422
 
410 423
         if (!$instance instanceof AbstractAtomicRule) {
411 424
 
@@ -415,8 +428,9 @@  discard block
 block discarded – undo
415 428
             // $instance->dump(true);
416 429
 
417 430
             if ($step_to_stop_after  == self::unify_atomic_operands ||
418
-                $step_to_stop_before == self::remove_invalid_branches )
419
-                return $instance;
431
+                $step_to_stop_before == self::remove_invalid_branches ) {
432
+                            return $instance;
433
+            }
420 434
 
421 435
             $instance->cleanOperations($options);
422 436
             if (method_exists($instance, 'removeInvalidBranches')) {
@@ -433,16 +447,18 @@  discard block
 block discarded – undo
433 447
         //@see https://github.com/jclaveau/php-logical-filter/issues/20
434 448
         if ($instance instanceof AndRule || $instance instanceof OrRule ) {
435 449
 
436
-            if (!$instance->getOperands())
437
-                return $instance;
450
+            if (!$instance->getOperands()) {
451
+                            return $instance;
452
+            }
438 453
 
439 454
             $operands = (new AndRule([$instance]))
440 455
                 ->cleanOperations($options, false)
441 456
                 // ->dump(true)
442 457
                 ->getOperands();
443 458
 
444
-            if (count($operands) == 1)
445
-                $instance = reset($operands);
459
+            if (count($operands) == 1) {
460
+                            $instance = reset($operands);
461
+            }
446 462
         }
447 463
 
448 464
 
@@ -493,11 +509,13 @@  discard block
 block discarded – undo
493 509
             // For FilteredValue and FilteredKey
494 510
             $field = (string) $field;
495 511
 
496
-            if (!isset($operandsByFields[ $field ]))
497
-                $operandsByFields[ $field ] = [];
512
+            if (!isset($operandsByFields[ $field ])) {
513
+                            $operandsByFields[ $field ] = [];
514
+            }
498 515
 
499
-            if (!isset($operandsByFields[ $field ][ $operand::operator ]))
500
-                $operandsByFields[ $field ][ $operand::operator ] = [];
516
+            if (!isset($operandsByFields[ $field ][ $operand::operator ])) {
517
+                            $operandsByFields[ $field ][ $operand::operator ] = [];
518
+            }
501 519
 
502 520
             $operandsByFields[ $field ][ $operand::operator ][] = $operand;
503 521
         }
@@ -522,11 +540,13 @@  discard block
 block discarded – undo
522 540
             // For FilteredValue and FilteredKey
523 541
             $field = (string) $field;
524 542
 
525
-            if (!isset($operandsByFields[ $field ]))
526
-                $operandsByFields[ $field ] = [];
543
+            if (!isset($operandsByFields[ $field ])) {
544
+                            $operandsByFields[ $field ] = [];
545
+            }
527 546
 
528
-            if (!isset($operandsByFields[ $field ][ $operand::operator ]))
529
-                $operandsByFields[ $field ][ $operand::operator ] = [];
547
+            if (!isset($operandsByFields[ $field ][ $operand::operator ])) {
548
+                            $operandsByFields[ $field ][ $operand::operator ] = [];
549
+            }
530 550
 
531 551
             $operandsByFields[ $field ][ $operand::operator ][] = $operand;
532 552
         }
@@ -569,8 +589,9 @@  discard block
 block discarded – undo
569 589
     protected function getOperandAt($index=0)
570 590
     {
571 591
         $operands = array_values($this->operands);
572
-        if (isset($operands[$index]))
573
-            return $operands[$index];
592
+        if (isset($operands[$index])) {
593
+                    return $operands[$index];
594
+        }
574 595
     }
575 596
 
576 597
     /**/
Please login to merge, or discard this patch.
src/Rule/AndRule.php 2 patches
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
         if (!$this->isNormalizationAllowed($simplification_options))
25 25
             return $this;
26 26
 
27
-        $this->moveSimplificationStepForward( self::rootify_disjunctions, $simplification_options );
27
+        $this->moveSimplificationStepForward(self::rootify_disjunctions, $simplification_options);
28 28
 
29 29
         $upLiftedOperands = [];
30 30
         foreach ($this->getOperands() as $operand) {
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
         foreach ($upLiftedOperands as $i => $operand) {
56 56
 
57 57
             if ($operand instanceof NotRule) {
58
-                if (    ($operand instanceof NotEqualRule || $operand instanceof NotInRule)
59
-                    && ! $operand->isNormalizationAllowed($simplification_options)
58
+                if (($operand instanceof NotEqualRule || $operand instanceof NotInRule)
59
+                    && !$operand->isNormalizationAllowed($simplification_options)
60 60
                 ) {
61 61
                     foreach ($upLiftedOr->getOperands() as $upLifdtedOperand) {
62
-                        $upLifdtedOperand->addOperand( $operand->copy() );
62
+                        $upLifdtedOperand->addOperand($operand->copy());
63 63
                     }
64 64
                 }
65 65
                 else {
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
                 foreach ($operand->getOperands() as $subOperand) {
82 82
                     foreach ($upLiftedOr->getOperands() as $upLiftedOrSubOperand) {
83 83
                         $newUpLiftedOrSubOperand = $upLiftedOrSubOperand->copy();
84
-                        $newUpLiftedOrSubOperand->addOperand( $subOperand->copy() );
84
+                        $newUpLiftedOrSubOperand->addOperand($subOperand->copy());
85 85
                         if ($newUpLiftedOrSubOperand->simplify($simplification_options)->hasSolution($simplification_options))
86
-                            $newUpLiftedOr->addOperand( $newUpLiftedOrSubOperand );
86
+                            $newUpLiftedOr->addOperand($newUpLiftedOrSubOperand);
87 87
                     }
88 88
                 }
89 89
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
                         );
100 100
                     }
101 101
 
102
-                    $upLifdtedOperand->addOperand( $operand->copy() );
102
+                    $upLifdtedOperand->addOperand($operand->copy());
103 103
                 }
104 104
             }
105 105
         }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      *
115 115
      * @todo same as OrRule
116 116
      */
117
-    public function toArray(array $options=[])
117
+    public function toArray(array $options = [])
118 118
     {
119 119
         $default_options = [
120 120
             'show_instance' => false,
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
             'semantic'      => false,
123 123
         ];
124 124
         foreach ($default_options as $default_option => &$default_value) {
125
-            if (!isset($options[ $default_option ]))
126
-                $options[ $default_option ] = $default_value;
125
+            if (!isset($options[$default_option]))
126
+                $options[$default_option] = $default_value;
127 127
         }
128 128
 
129 129
         if (!$options['show_instance'] && !empty($this->cache['array']))
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 
158 158
     /**
159 159
      */
160
-    public function toString(array $options=[])
160
+    public function toString(array $options = [])
161 161
     {
162 162
         $operator = self::operator;
163 163
         if (!$this->operands) {
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
         foreach ($this->operands as $operand) {
173 173
             $out .= implode("\n", array_map(function($line) use (&$indent_unit) {
174 174
                 return $indent_unit.$line;
175
-            }, explode("\n", $operand->toString($options)) )) . ",$line_break";
175
+            }, explode("\n", $operand->toString($options)))).",$line_break";
176 176
         }
177 177
 
178 178
         $out .= ']';
@@ -186,15 +186,15 @@  discard block
 block discarded – undo
186 186
     public function removeSameOperationOperands()
187 187
     {
188 188
         foreach ($this->operands as $i => $operand) {
189
-            if ( ! is_a($operand, AndRule::class))
189
+            if (!is_a($operand, AndRule::class))
190 190
                 continue;
191 191
 
192
-            if ( ! $operands = $operand->getOperands())
192
+            if (!$operands = $operand->getOperands())
193 193
                 continue;
194 194
 
195 195
             // Id AND is an operand on AND they can be merge (and the same with OR)
196 196
             foreach ($operands as $sub_operand) {
197
-                $this->addOperand( $sub_operand->copy() );
197
+                $this->addOperand($sub_operand->copy());
198 198
             }
199 199
             unset($this->operands[$i]);
200 200
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 
221 221
         foreach ($this->operands as $i => $operand) {
222 222
             // if ($operand instanceof AndRule || $operand instanceof OrRule ) {
223
-            if ( in_array( get_class($operand), [AndRule::class, OrRule::class]) ) {
223
+            if (in_array(get_class($operand), [AndRule::class, OrRule::class])) {
224 224
                 $this->operands[$i] = $operand->removeInvalidBranches($simplification_options);
225 225
                 if (!$this->operands[$i]->hasSolution()) {
226 226
                     $this->operands = [];
@@ -235,9 +235,9 @@  discard block
 block discarded – undo
235 235
 
236 236
         foreach ($operandsByFields as $field => $operandsByOperator) {
237 237
 
238
-            if (!empty($operandsByOperator[ EqualRule::operator ])) {
238
+            if (!empty($operandsByOperator[EqualRule::operator])) {
239 239
 
240
-                foreach ($operandsByOperator[ EqualRule::operator ] as $equalRule) {
240
+                foreach ($operandsByOperator[EqualRule::operator] as $equalRule) {
241 241
                     // Multiple equal rules without the same value is invalid
242 242
                     if (isset($previousEqualRule) && $previousEqualRule->getValue() != $equalRule->getValue()) {
243 243
                         $this->operands = [];
@@ -247,55 +247,55 @@  discard block
 block discarded – undo
247 247
                 }
248 248
                 unset($previousEqualRule);
249 249
 
250
-                $equalRule = reset($operandsByOperator[ EqualRule::operator ]);
250
+                $equalRule = reset($operandsByOperator[EqualRule::operator]);
251 251
 
252
-                if (   !empty($operandsByOperator[ BelowRule::operator ])
252
+                if (!empty($operandsByOperator[BelowRule::operator])
253 253
                     && $equalRule->getValue() === null
254 254
                 ) {
255 255
                     $this->operands = [];
256 256
                     return $this;
257 257
                 }
258 258
 
259
-                if (   !empty($operandsByOperator[ BelowRule::operator ])
260
-                    && $equalRule->getValue() >= reset($operandsByOperator[ BelowRule::operator ])->getMaximum()
259
+                if (!empty($operandsByOperator[BelowRule::operator])
260
+                    && $equalRule->getValue() >= reset($operandsByOperator[BelowRule::operator])->getMaximum()
261 261
                 ) {
262 262
                     $this->operands = [];
263 263
                     return $this;
264 264
                 }
265 265
 
266
-                if (   !empty($operandsByOperator[ AboveRule::operator ])
266
+                if (!empty($operandsByOperator[AboveRule::operator])
267 267
                     && $equalRule->getValue() === null
268 268
                 ) {
269 269
                     $this->operands = [];
270 270
                     return $this;
271 271
                 }
272 272
 
273
-                if (   !empty($operandsByOperator[ AboveRule::operator ])
274
-                    && $equalRule->getValue() <= reset($operandsByOperator[ AboveRule::operator ])->getMinimum()
273
+                if (!empty($operandsByOperator[AboveRule::operator])
274
+                    && $equalRule->getValue() <= reset($operandsByOperator[AboveRule::operator])->getMinimum()
275 275
                 ) {
276 276
                     $this->operands = [];
277 277
                     return $this;
278 278
                 }
279 279
 
280
-                if (   !empty($operandsByOperator[ NotEqualRule::operator ])
281
-                    && $equalRule->getValue() == reset($operandsByOperator[ NotEqualRule::operator ])->getValue()
280
+                if (!empty($operandsByOperator[NotEqualRule::operator])
281
+                    && $equalRule->getValue() == reset($operandsByOperator[NotEqualRule::operator])->getValue()
282 282
                 ) {
283 283
                     $this->operands = [];
284 284
                     return $this;
285 285
                 }
286 286
 
287
-                if (   !empty($operandsByOperator[ NotEqualRule::operator ])
287
+                if (!empty($operandsByOperator[NotEqualRule::operator])
288 288
                     && $equalRule->getValue() === null
289
-                    && reset($operandsByOperator[ NotEqualRule::operator ])->getValue() === null
289
+                    && reset($operandsByOperator[NotEqualRule::operator])->getValue() === null
290 290
                 ) {
291 291
                     $this->operands = [];
292 292
                     return $this;
293 293
                 }
294 294
             }
295
-            elseif (   !empty($operandsByOperator[ BelowRule::operator ])
296
-                    && !empty($operandsByOperator[ AboveRule::operator ])) {
297
-                $aboveRule = reset($operandsByOperator[ AboveRule::operator ]);
298
-                $belowRule = reset($operandsByOperator[ BelowRule::operator ]);
295
+            elseif (!empty($operandsByOperator[BelowRule::operator])
296
+                    && !empty($operandsByOperator[AboveRule::operator])) {
297
+                $aboveRule = reset($operandsByOperator[AboveRule::operator]);
298
+                $belowRule = reset($operandsByOperator[BelowRule::operator]);
299 299
 
300 300
                 if ($belowRule->getMaximum() <= $aboveRule->getMinimum()) {
301 301
                     $this->operands = [];
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
      *
316 316
      * @return bool If the AndRule can have a solution or not
317 317
      */
318
-    public function hasSolution(array $contextual_options=[])
318
+    public function hasSolution(array $contextual_options = [])
319 319
     {
320 320
         if (!$this->simplicationStepReached(self::simplified)) {
321 321
             throw new \LogicException(
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 
349 349
                 try {
350 350
                     if ($operator == AboveRule::operator) {
351
-                        usort($operands, function( AboveRule $a, AboveRule $b ) {
351
+                        usort($operands, function(AboveRule $a, AboveRule $b) {
352 352
                             if ($a->getMinimum() === null)
353 353
                                 return 1;
354 354
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
                         $operands = [reset($operands)];
364 364
                     }
365 365
                     elseif ($operator == BelowRule::operator) {
366
-                        usort($operands, function( BelowRule $a, BelowRule $b ) {
366
+                        usort($operands, function(BelowRule $a, BelowRule $b) {
367 367
                             if ($a->getMaximum() === null)
368 368
                                 return 1;
369 369
 
@@ -405,10 +405,10 @@  discard block
 block discarded – undo
405 405
                             if ($first_in === $next_in)
406 406
                                 continue;
407 407
 
408
-                            $first_in->setPossibilities( array_intersect(
408
+                            $first_in->setPossibilities(array_intersect(
409 409
                                 $first_in->getPossibilities(),
410 410
                                 $next_in->getPossibilities()
411
-                            ) );
411
+                            ));
412 412
 
413 413
                             unset($operands[$i]);
414 414
                         }
@@ -424,17 +424,17 @@  discard block
 block discarded – undo
424 424
                             if ($first_not_in === $next_not_in)
425 425
                                 continue;
426 426
 
427
-                            $first_not_in->setPossibilities( array_merge(
427
+                            $first_not_in->setPossibilities(array_merge(
428 428
                                 $first_not_in->getPossibilities(),
429 429
                                 $next_not_in->getPossibilities()
430
-                            ) );
430
+                            ));
431 431
 
432 432
                             unset($operands[$i]);
433 433
                         }
434 434
                     }
435 435
                 }
436 436
                 catch (\Exception $e) {
437
-                    VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage() . "\n" . var_export([
437
+                    VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage()."\n".var_export([
438 438
                             'operands' => $operands,
439 439
                             // 'this'     => $this,
440 440
                         ], true)
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
                     throw $e;
445 445
                 }
446 446
 
447
-                $operandsByFields[ $field ][ $operator ] = $operands;
447
+                $operandsByFields[$field][$operator] = $operands;
448 448
             }
449 449
         }
450 450
 
@@ -468,14 +468,14 @@  discard block
 block discarded – undo
468 468
                 ]
469 469
                 as $unifyable_operator
470 470
             ) {
471
-                if (!empty($operandsByOperator[ $unifyable_operator ])) {
472
-                    if (count($operandsByOperator[ $unifyable_operator ]) != 1) {
471
+                if (!empty($operandsByOperator[$unifyable_operator])) {
472
+                    if (count($operandsByOperator[$unifyable_operator]) != 1) {
473 473
                         throw new \LogicException(
474
-                            __METHOD__ . " MUST be called after unifyAtomicOperands() "
474
+                            __METHOD__." MUST be called after unifyAtomicOperands() "
475 475
                             ."to have only one '$unifyable_operator' predicate istead of:\n"
476
-                            ."[\n".implode( ",\n", array_map(function ($rule) {
476
+                            ."[\n".implode(",\n", array_map(function($rule) {
477 477
                                     return $rule->toString();
478
-                                }, $operandsByOperator[ $unifyable_operator ])
478
+                                }, $operandsByOperator[$unifyable_operator])
479 479
                             )."\n]"
480 480
                         );
481 481
                     }
@@ -495,75 +495,75 @@  discard block
 block discarded – undo
495 495
     protected static function simplifyDifferentOperandsForField($field, array $operandsByOperator)
496 496
     {
497 497
         // EqualRule comparisons
498
-        if (!empty($operandsByOperator[ EqualRule::operator ])) {
498
+        if (!empty($operandsByOperator[EqualRule::operator])) {
499 499
 
500
-            $equalRule = reset( $operandsByOperator[ EqualRule::operator ] );
500
+            $equalRule = reset($operandsByOperator[EqualRule::operator]);
501 501
 
502
-            if (!empty($operandsByOperator[ NotEqualRule::operator ])) {
503
-                foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $not_equal_rule) {
502
+            if (!empty($operandsByOperator[NotEqualRule::operator])) {
503
+                foreach ($operandsByOperator[NotEqualRule::operator] as $i => $not_equal_rule) {
504 504
 
505 505
                     if ($equalRule->getValue() !== null) {
506 506
                         if ($not_equal_rule->getValue() === null) // means if exists <=> equals something
507
-                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
507
+                            unset($operandsByOperator[NotEqualRule::operator][$i]);
508 508
                         elseif ($not_equal_rule->getValue() != $equalRule->getValue())
509
-                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
509
+                            unset($operandsByOperator[NotEqualRule::operator][$i]);
510 510
                     }
511
-                    elseif ($equalRule->getValue() === null ) {
511
+                    elseif ($equalRule->getValue() === null) {
512 512
                         if ($not_equal_rule->getValue() !== null)
513
-                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
513
+                            unset($operandsByOperator[NotEqualRule::operator][$i]);
514 514
                         // else we let the "equal null" and the "not equal null" for the romeInvalidBranches step
515 515
                     }
516 516
                 }
517 517
             }
518 518
 
519
-            if (!empty($operandsByOperator[ AboveRule::operator ])) {
519
+            if (!empty($operandsByOperator[AboveRule::operator])) {
520 520
 
521
-                $aboveRule = reset($operandsByOperator[ AboveRule::operator ]);
521
+                $aboveRule = reset($operandsByOperator[AboveRule::operator]);
522 522
                 if ($equalRule->getValue() !== null && $aboveRule->getMinimum() < $equalRule->getValue())
523
-                    unset($operandsByOperator[ AboveRule::operator ]);
523
+                    unset($operandsByOperator[AboveRule::operator]);
524 524
             }
525 525
 
526
-            if (!empty($operandsByOperator[ BelowRule::operator ])) {
526
+            if (!empty($operandsByOperator[BelowRule::operator])) {
527 527
 
528
-                $belowRule = reset($operandsByOperator[ BelowRule::operator ]);
528
+                $belowRule = reset($operandsByOperator[BelowRule::operator]);
529 529
                 if ($equalRule->getValue() !== null && $belowRule->getMaximum() > $equalRule->getValue())
530
-                    unset($operandsByOperator[ BelowRule::operator ]);
530
+                    unset($operandsByOperator[BelowRule::operator]);
531 531
             }
532 532
 
533
-            if (!empty($operandsByOperator[ InRule::operator ])) {
533
+            if (!empty($operandsByOperator[InRule::operator])) {
534 534
 
535
-                $possibilities = reset($operandsByOperator[ InRule::operator ])->getPossibilities();
535
+                $possibilities = reset($operandsByOperator[InRule::operator])->getPossibilities();
536 536
 
537 537
                 if (in_array($equalRule->getValue(), $possibilities)) {
538
-                    unset($operandsByOperator[ InRule::operator ]);
538
+                    unset($operandsByOperator[InRule::operator]);
539 539
                 }
540 540
                 else {
541 541
                     // We flush possibilities of the InRule
542 542
                     // TODO Replace it by a FalseRule
543
-                    $operandsByOperator[ InRule::operator ][0]->setPossibilities([]);
543
+                    $operandsByOperator[InRule::operator][0]->setPossibilities([]);
544 544
                     // and also remove the equal rule to shorten the reste of the simplification process
545
-                    unset($operandsByOperator[ EqualRule::operator ]);
545
+                    unset($operandsByOperator[EqualRule::operator]);
546 546
                 }
547 547
             }
548 548
 
549
-            if (!empty($operandsByOperator[ NotInRule::operator ])) {
549
+            if (!empty($operandsByOperator[NotInRule::operator])) {
550 550
 
551
-                $notInRule = reset($operandsByOperator[ NotInRule::operator ]);
551
+                $notInRule = reset($operandsByOperator[NotInRule::operator]);
552 552
                 if (in_array($equalRule->getValue(), $notInRule->getPossibilities())) {
553 553
                     // ['field', '=', 4] && ['field', '!in', [4]...] <=> false
554 554
                     return [];
555 555
                 }
556 556
                 else {
557
-                    unset($operandsByOperator[ NotInRule::operator ]);
557
+                    unset($operandsByOperator[NotInRule::operator]);
558 558
                 }
559 559
                 // $notInRule->dump(true);
560 560
             }
561 561
 
562
-            if (!empty($operandsByOperator[ BelowOrEqualRule::operator ])) {
562
+            if (!empty($operandsByOperator[BelowOrEqualRule::operator])) {
563 563
 
564
-                $belowOrEqualRule = reset($operandsByOperator[ BelowOrEqualRule::operator ]);
564
+                $belowOrEqualRule = reset($operandsByOperator[BelowOrEqualRule::operator]);
565 565
                 if ($equalRule->getValue() <= $belowOrEqualRule->getMaximum()) {
566
-                    unset($operandsByOperator[ BelowOrEqualRule::operator ]);
566
+                    unset($operandsByOperator[BelowOrEqualRule::operator]);
567 567
                 }
568 568
                 else {
569 569
                     // ['field', '=', 4] && ['field', '<=', [3]...] <=> false
@@ -571,11 +571,11 @@  discard block
 block discarded – undo
571 571
                 }
572 572
             }
573 573
 
574
-            if (!empty($operandsByOperator[ AboveOrEqualRule::operator ])) {
574
+            if (!empty($operandsByOperator[AboveOrEqualRule::operator])) {
575 575
 
576
-                $aboveOrEqualRule = reset($operandsByOperator[ AboveOrEqualRule::operator ]);
576
+                $aboveOrEqualRule = reset($operandsByOperator[AboveOrEqualRule::operator]);
577 577
                 if ($equalRule->getValue() >= $aboveOrEqualRule->getMinimum()) {
578
-                    unset($operandsByOperator[ AboveOrEqualRule::operator ]);
578
+                    unset($operandsByOperator[AboveOrEqualRule::operator]);
579 579
                 }
580 580
                 else {
581 581
                     // ['field', '=', 4] && ['field', '<=', [3]...] <=> false
@@ -585,52 +585,52 @@  discard block
 block discarded – undo
585 585
         }
586 586
 
587 587
         // NotEqualRule null comparisons
588
-        if (!empty($operandsByOperator[ NotEqualRule::operator ])) {
589
-            if (!empty($operandsByOperator[ NotEqualRule::operator ])) {
590
-                foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $notEqualRule) {
588
+        if (!empty($operandsByOperator[NotEqualRule::operator])) {
589
+            if (!empty($operandsByOperator[NotEqualRule::operator])) {
590
+                foreach ($operandsByOperator[NotEqualRule::operator] as $i => $notEqualRule) {
591 591
 
592 592
                     if ($notEqualRule->getValue() === null) {
593
-                        if (!empty($operandsByOperator[ AboveRule::operator ])) {
594
-                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
593
+                        if (!empty($operandsByOperator[AboveRule::operator])) {
594
+                            unset($operandsByOperator[NotEqualRule::operator][$i]);
595 595
                         }
596 596
 
597
-                        if (!empty($operandsByOperator[ BelowRule::operator ])) {
598
-                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
597
+                        if (!empty($operandsByOperator[BelowRule::operator])) {
598
+                            unset($operandsByOperator[NotEqualRule::operator][$i]);
599 599
                         }
600 600
 
601
-                        if (!empty($operandsByOperator[ EqualRule::operator ])) {
602
-                            if (reset($operandsByOperator[ EqualRule::operator ])->getValue() !== null)
603
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
601
+                        if (!empty($operandsByOperator[EqualRule::operator])) {
602
+                            if (reset($operandsByOperator[EqualRule::operator])->getValue() !== null)
603
+                                unset($operandsByOperator[NotEqualRule::operator][$i]);
604 604
                         }
605 605
                     }
606 606
                     else {
607
-                        if (!empty($operandsByOperator[ AboveRule::operator ])) {
608
-                            if ($operandsByOperator[ AboveRule::operator ][0]->getMinimum() >= $notEqualRule->getValue())
609
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
607
+                        if (!empty($operandsByOperator[AboveRule::operator])) {
608
+                            if ($operandsByOperator[AboveRule::operator][0]->getMinimum() >= $notEqualRule->getValue())
609
+                                unset($operandsByOperator[NotEqualRule::operator][$i]);
610 610
                         }
611 611
 
612
-                        if (!empty($operandsByOperator[ BelowRule::operator ])) {
613
-                            if ($operandsByOperator[ BelowRule::operator ][0]->getMaximum() <= $notEqualRule->getValue())
614
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
612
+                        if (!empty($operandsByOperator[BelowRule::operator])) {
613
+                            if ($operandsByOperator[BelowRule::operator][0]->getMaximum() <= $notEqualRule->getValue())
614
+                                unset($operandsByOperator[NotEqualRule::operator][$i]);
615 615
                         }
616 616
                     }
617 617
 
618
-                    if (!empty($operandsByOperator[ NotInRule::operator ])) {
619
-                        $notInRule = reset($operandsByOperator[ NotInRule::operator ]);
618
+                    if (!empty($operandsByOperator[NotInRule::operator])) {
619
+                        $notInRule = reset($operandsByOperator[NotInRule::operator]);
620 620
                         if (!in_array($notEqualRule->getValue(), $notInRule->getPossibilities())) {
621 621
                             // TODO Replace it by a FalseRule
622
-                            $operandsByOperator[ NotInRule::operator ][0]->setPossibilities(
622
+                            $operandsByOperator[NotInRule::operator][0]->setPossibilities(
623 623
                                 array_merge($notInRule->getPossibilities(), [$notEqualRule->getValue()])
624 624
                             );
625 625
                         }
626 626
 
627
-                        unset($operandsByOperator[ NotEqualRule::operator ][$i]);
627
+                        unset($operandsByOperator[NotEqualRule::operator][$i]);
628 628
                     }
629 629
 
630
-                    if (!empty($operandsByOperator[ InRule::operator ])) {
631
-                        $inRule = reset($operandsByOperator[ InRule::operator ]);
630
+                    if (!empty($operandsByOperator[InRule::operator])) {
631
+                        $inRule = reset($operandsByOperator[InRule::operator]);
632 632
 
633
-                        $operandsByOperator[ InRule::operator ][0]->setPossibilities(
633
+                        $operandsByOperator[InRule::operator][0]->setPossibilities(
634 634
                             array_diff($inRule->getPossibilities(), [$notEqualRule->getValue()])
635 635
                         );
636 636
                     }
@@ -640,61 +640,61 @@  discard block
 block discarded – undo
640 640
 
641 641
         // Comparison between InRules and NotInRules
642 642
         // This is an optimization to avoid NotIn explosion
643
-        if (!empty($operandsByOperator[ InRule::operator ])) {
644
-            $inRule = $operandsByOperator[ InRule::operator ][0];
643
+        if (!empty($operandsByOperator[InRule::operator])) {
644
+            $inRule = $operandsByOperator[InRule::operator][0];
645 645
 
646
-            if (!empty($operandsByOperator[ NotInRule::operator ])) {
647
-                $notInRule = reset($operandsByOperator[ NotInRule::operator ]);
648
-                $operandsByOperator[ InRule::operator ][0]->setPossibilities(
649
-                    array_diff( $inRule->getPossibilities(), $notInRule->getPossibilities())
646
+            if (!empty($operandsByOperator[NotInRule::operator])) {
647
+                $notInRule = reset($operandsByOperator[NotInRule::operator]);
648
+                $operandsByOperator[InRule::operator][0]->setPossibilities(
649
+                    array_diff($inRule->getPossibilities(), $notInRule->getPossibilities())
650 650
                 );
651
-                unset($operandsByOperator[ NotInRule::operator ]);
651
+                unset($operandsByOperator[NotInRule::operator]);
652 652
             }
653 653
 
654
-            if (!empty($operandsByOperator[ BelowRule::operator ])) {
655
-                $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getMaximum();
654
+            if (!empty($operandsByOperator[BelowRule::operator])) {
655
+                $upper_limit = reset($operandsByOperator[BelowRule::operator])->getMaximum();
656 656
 
657
-                $operandsByOperator[ InRule::operator ][0]->setPossibilities(
658
-                    array_filter( $inRule->getPossibilities(), function ($possibility) use ($upper_limit) {
657
+                $operandsByOperator[InRule::operator][0]->setPossibilities(
658
+                    array_filter($inRule->getPossibilities(), function($possibility) use ($upper_limit) {
659 659
                         return $possibility < $upper_limit;
660 660
                     } )
661 661
                 );
662 662
 
663
-                unset($operandsByOperator[ BelowRule::operator ]);
663
+                unset($operandsByOperator[BelowRule::operator]);
664 664
             }
665 665
 
666
-            if (!empty($operandsByOperator[ AboveRule::operator ])) {
667
-                $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getMinimum();
666
+            if (!empty($operandsByOperator[AboveRule::operator])) {
667
+                $lower_limit = reset($operandsByOperator[AboveRule::operator])->getMinimum();
668 668
 
669
-                $operandsByOperator[ InRule::operator ][0]->setPossibilities(
670
-                    array_filter( $inRule->getPossibilities(), function ($possibility) use ($lower_limit) {
669
+                $operandsByOperator[InRule::operator][0]->setPossibilities(
670
+                    array_filter($inRule->getPossibilities(), function($possibility) use ($lower_limit) {
671 671
                         return $possibility > $lower_limit;
672 672
                     } )
673 673
                 );
674 674
 
675
-                unset($operandsByOperator[ AboveRule::operator ]);
675
+                unset($operandsByOperator[AboveRule::operator]);
676 676
             }
677 677
         }
678 678
 
679 679
         // Comparison between NotInRules and > or <
680
-        if (!empty($operandsByOperator[ NotInRule::operator ])) {
681
-            $notInRule = $operandsByOperator[ NotInRule::operator ][0];
680
+        if (!empty($operandsByOperator[NotInRule::operator])) {
681
+            $notInRule = $operandsByOperator[NotInRule::operator][0];
682 682
 
683
-            if (!empty($operandsByOperator[ BelowRule::operator ])) {
684
-                $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit();
683
+            if (!empty($operandsByOperator[BelowRule::operator])) {
684
+                $upper_limit = reset($operandsByOperator[BelowRule::operator])->getUpperLimit();
685 685
 
686
-                $operandsByOperator[ NotInRule::operator ][0]->setPossibilities(
687
-                    array_filter( $notInRule->getPossibilities(), function ($possibility) use ($upper_limit) {
686
+                $operandsByOperator[NotInRule::operator][0]->setPossibilities(
687
+                    array_filter($notInRule->getPossibilities(), function($possibility) use ($upper_limit) {
688 688
                         return $possibility < $upper_limit;
689 689
                     } )
690 690
                 );
691 691
             }
692 692
 
693
-            if (!empty($operandsByOperator[ AboveRule::operator ])) {
694
-                $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getMinimum();
693
+            if (!empty($operandsByOperator[AboveRule::operator])) {
694
+                $lower_limit = reset($operandsByOperator[AboveRule::operator])->getMinimum();
695 695
 
696
-                $operandsByOperator[ NotInRule::operator ][0]->setPossibilities(
697
-                    array_filter( $notInRule->getPossibilities(), function ($possibility) use ($lower_limit) {
696
+                $operandsByOperator[NotInRule::operator][0]->setPossibilities(
697
+                    array_filter($notInRule->getPossibilities(), function($possibility) use ($lower_limit) {
698 698
                         return $possibility > $lower_limit;
699 699
                     } )
700 700
                 );
@@ -702,25 +702,25 @@  discard block
 block discarded – undo
702 702
         }
703 703
 
704 704
         // Comparison between <= and > or <
705
-        if (!empty($operandsByOperator[ BelowOrEqualRule::operator ])) {
706
-            $belowOrEqualRule = $operandsByOperator[ BelowOrEqualRule::operator ][0];
705
+        if (!empty($operandsByOperator[BelowOrEqualRule::operator])) {
706
+            $belowOrEqualRule = $operandsByOperator[BelowOrEqualRule::operator][0];
707 707
 
708
-            if (!empty($operandsByOperator[ BelowRule::operator ])) {
709
-                $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit();
708
+            if (!empty($operandsByOperator[BelowRule::operator])) {
709
+                $upper_limit = reset($operandsByOperator[BelowRule::operator])->getUpperLimit();
710 710
 
711 711
                 if ($belowOrEqualRule->getMaximum() >= $upper_limit) {
712 712
                     // [field < 3] && [field <= 3]
713 713
                     // [field < 3] && [field <= 4]
714
-                    unset($operandsByOperator[ BelowOrEqualRule::operator ][0]);
714
+                    unset($operandsByOperator[BelowOrEqualRule::operator][0]);
715 715
                 }
716 716
                 else {
717 717
                     // [field < 3] && [field <= 2]
718
-                    unset($operandsByOperator[ BelowRule::operator ][0]);
718
+                    unset($operandsByOperator[BelowRule::operator][0]);
719 719
                 }
720 720
             }
721 721
 
722
-            if (!empty($operandsByOperator[ AboveRule::operator ])) {
723
-                $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getLowerLimit();
722
+            if (!empty($operandsByOperator[AboveRule::operator])) {
723
+                $lower_limit = reset($operandsByOperator[AboveRule::operator])->getLowerLimit();
724 724
 
725 725
                 if ($belowOrEqualRule->getMaximum() <= $lower_limit) {
726 726
                     // [field > 3] && [field <= 2] <=> false
@@ -728,8 +728,8 @@  discard block
 block discarded – undo
728 728
                 }
729 729
             }
730 730
 
731
-            if (!empty($operandsByOperator[ AboveOrEqualRule::operator ])) {
732
-                $minimum = reset($operandsByOperator[ AboveOrEqualRule::operator ])->getMinimum();
731
+            if (!empty($operandsByOperator[AboveOrEqualRule::operator])) {
732
+                $minimum = reset($operandsByOperator[AboveOrEqualRule::operator])->getMinimum();
733 733
 
734 734
                 if ($belowOrEqualRule->getMaximum() < $minimum) {
735 735
                     // [field <= 3] && [field >= 4] <=> false
@@ -737,11 +737,11 @@  discard block
 block discarded – undo
737 737
                 }
738 738
                 elseif ($belowOrEqualRule->getMaximum() == $minimum) {
739 739
                     // [field <= 3] && [field >= 3] <=> [field = 3]
740
-                    unset($operandsByOperator[ BelowOrEqualRule::operator ]);
741
-                    unset($operandsByOperator[ AboveOrEqualRule::operator ]);
742
-                    $operandsByOperator[ EqualRule::operator ][] = new EqualRule($field, $minimum);
740
+                    unset($operandsByOperator[BelowOrEqualRule::operator]);
741
+                    unset($operandsByOperator[AboveOrEqualRule::operator]);
742
+                    $operandsByOperator[EqualRule::operator][] = new EqualRule($field, $minimum);
743 743
 
744
-                    if (count($operandsByOperator[ EqualRule::operator ]) > 1) {
744
+                    if (count($operandsByOperator[EqualRule::operator]) > 1) {
745 745
                         $operandsByOperator = self::simplifyDifferentOperandsForField($field, $operandsByOperator);
746 746
                     }
747 747
                 }
@@ -760,10 +760,10 @@  discard block
 block discarded – undo
760 760
     public function setOperandsOrReplaceByOperation($new_operands)
761 761
     {
762 762
         try {
763
-            return $this->setOperands( $new_operands );
763
+            return $this->setOperands($new_operands);
764 764
         }
765 765
         catch (\LogicException $e) {
766
-            return new AndRule( $new_operands );
766
+            return new AndRule($new_operands);
767 767
         }
768 768
     }
769 769
 
Please login to merge, or discard this patch.
Braces   +106 added lines, -98 removed lines patch added patch discarded remove patch
@@ -21,16 +21,18 @@  discard block
 block discarded – undo
21 21
      */
22 22
     public function rootifyDisjunctions(array $simplification_options)
23 23
     {
24
-        if (!$this->isNormalizationAllowed($simplification_options))
25
-            return $this;
24
+        if (!$this->isNormalizationAllowed($simplification_options)) {
25
+                    return $this;
26
+        }
26 27
 
27 28
         $this->moveSimplificationStepForward( self::rootify_disjunctions, $simplification_options );
28 29
 
29 30
         $upLiftedOperands = [];
30 31
         foreach ($this->getOperands() as $operand) {
31 32
             $operand = $operand->copy();
32
-            if ($operand instanceof AbstractOperationRule)
33
-                $operand = $operand->rootifyDisjunctions($simplification_options);
33
+            if ($operand instanceof AbstractOperationRule) {
34
+                            $operand = $operand->rootifyDisjunctions($simplification_options);
35
+            }
34 36
 
35 37
             $upLiftedOperands[] = $operand;
36 38
         }
@@ -61,15 +63,13 @@  discard block
 block discarded – undo
61 63
                     foreach ($upLiftedOr->getOperands() as $upLifdtedOperand) {
62 64
                         $upLifdtedOperand->addOperand( $operand->copy() );
63 65
                     }
64
-                }
65
-                else {
66
+                } else {
66 67
                     throw new \LogicException(
67 68
                         "Rootifying disjunctions MUST be done after negations removal instead of '".$operand."' \n"
68 69
                         .$operand
69 70
                     );
70 71
                 }
71
-            }
72
-            elseif ($operand instanceof OrRule && $operand->isNormalizationAllowed($simplification_options)) {
72
+            } elseif ($operand instanceof OrRule && $operand->isNormalizationAllowed($simplification_options)) {
73 73
 
74 74
                 // If an operand is an Or, me transform the current
75 75
                 // (A' || A") && (B')       <=> (A' && B') || (A" && B');
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
                     foreach ($upLiftedOr->getOperands() as $upLiftedOrSubOperand) {
83 83
                         $newUpLiftedOrSubOperand = $upLiftedOrSubOperand->copy();
84 84
                         $newUpLiftedOrSubOperand->addOperand( $subOperand->copy() );
85
-                        if ($newUpLiftedOrSubOperand->simplify($simplification_options)->hasSolution($simplification_options))
86
-                            $newUpLiftedOr->addOperand( $newUpLiftedOrSubOperand );
85
+                        if ($newUpLiftedOrSubOperand->simplify($simplification_options)->hasSolution($simplification_options)) {
86
+                                                    $newUpLiftedOr->addOperand( $newUpLiftedOrSubOperand );
87
+                        }
87 88
                     }
88 89
                 }
89 90
 
90 91
                 $upLiftedOr = $newUpLiftedOr;
91
-            }
92
-            else {
92
+            } else {
93 93
                 // append the operand to all the operands of the $upLiftedOr
94 94
                 foreach ($upLiftedOr->getOperands() as $upLifdtedOperand) {
95 95
                     if (!$upLifdtedOperand instanceof AndRule) {
@@ -122,12 +122,14 @@  discard block
 block discarded – undo
122 122
             'semantic'      => false,
123 123
         ];
124 124
         foreach ($default_options as $default_option => &$default_value) {
125
-            if (!isset($options[ $default_option ]))
126
-                $options[ $default_option ] = $default_value;
125
+            if (!isset($options[ $default_option ])) {
126
+                            $options[ $default_option ] = $default_value;
127
+            }
127 128
         }
128 129
 
129
-        if (!$options['show_instance'] && !empty($this->cache['array']))
130
-            return $this->cache['array'];
130
+        if (!$options['show_instance'] && !empty($this->cache['array'])) {
131
+                    return $this->cache['array'];
132
+        }
131 133
 
132 134
         $operands_as_array = [
133 135
             $options['show_instance'] ? $this->getInstanceId() : self::operator,
@@ -143,15 +145,16 @@  discard block
 block discarded – undo
143 145
                 [self::operator],
144 146
                 $operands_semantic_ids
145 147
             );
146
-        }
147
-        else {
148
-            foreach ($operands as $operand)
149
-                $operands_as_array[] = $operand->toArray($options);
150
-
151
-            if (!$options['show_instance'])
152
-                return $this->cache['array'] = $operands_as_array;
153
-            else
154
-                return $operands_as_array;
148
+        } else {
149
+            foreach ($operands as $operand) {
150
+                            $operands_as_array[] = $operand->toArray($options);
151
+            }
152
+
153
+            if (!$options['show_instance']) {
154
+                            return $this->cache['array'] = $operands_as_array;
155
+            } else {
156
+                            return $operands_as_array;
157
+            }
155 158
         }
156 159
     }
157 160
 
@@ -186,11 +189,13 @@  discard block
 block discarded – undo
186 189
     public function removeSameOperationOperands()
187 190
     {
188 191
         foreach ($this->operands as $i => $operand) {
189
-            if ( ! is_a($operand, AndRule::class))
190
-                continue;
192
+            if ( ! is_a($operand, AndRule::class)) {
193
+                            continue;
194
+            }
191 195
 
192
-            if ( ! $operands = $operand->getOperands())
193
-                continue;
196
+            if ( ! $operands = $operand->getOperands()) {
197
+                            continue;
198
+            }
194 199
 
195 200
             // Id AND is an operand on AND they can be merge (and the same with OR)
196 201
             foreach ($operands as $sub_operand) {
@@ -213,8 +218,9 @@  discard block
 block discarded – undo
213 218
      */
214 219
     public function removeInvalidBranches(array $simplification_options)
215 220
     {
216
-        if (!$this->isNormalizationAllowed($simplification_options))
217
-            return $this;
221
+        if (!$this->isNormalizationAllowed($simplification_options)) {
222
+                    return $this;
223
+        }
218 224
 
219 225
         $this->moveSimplificationStepForward(self::remove_invalid_branches, $simplification_options);
220 226
 
@@ -291,8 +297,7 @@  discard block
 block discarded – undo
291 297
                     $this->operands = [];
292 298
                     return $this;
293 299
                 }
294
-            }
295
-            elseif (   !empty($operandsByOperator[ BelowRule::operator ])
300
+            } elseif (   !empty($operandsByOperator[ BelowRule::operator ])
296 301
                     && !empty($operandsByOperator[ AboveRule::operator ])) {
297 302
                 $aboveRule = reset($operandsByOperator[ AboveRule::operator ]);
298 303
                 $belowRule = reset($operandsByOperator[ BelowRule::operator ]);
@@ -326,8 +331,9 @@  discard block
 block discarded – undo
326 331
 
327 332
         // atomic rules
328 333
         foreach ($this->getOperands() as $operand) {
329
-            if (method_exists($operand, 'hasSolution') && !$operand->hasSolution())
330
-                return false;
334
+            if (method_exists($operand, 'hasSolution') && !$operand->hasSolution()) {
335
+                            return false;
336
+            }
331 337
         }
332 338
 
333 339
         return !empty($this->getOperands());
@@ -349,35 +355,39 @@  discard block
 block discarded – undo
349 355
                 try {
350 356
                     if ($operator == AboveRule::operator) {
351 357
                         usort($operands, function( AboveRule $a, AboveRule $b ) {
352
-                            if ($a->getMinimum() === null)
353
-                                return 1;
358
+                            if ($a->getMinimum() === null) {
359
+                                                            return 1;
360
+                            }
354 361
 
355
-                            if ($b->getMinimum() === null)
356
-                                return -1;
362
+                            if ($b->getMinimum() === null) {
363
+                                                            return -1;
364
+                            }
357 365
 
358
-                            if ($a->getMinimum() > $b->getMinimum())
359
-                                return -1;
366
+                            if ($a->getMinimum() > $b->getMinimum()) {
367
+                                                            return -1;
368
+                            }
360 369
 
361 370
                             return 1;
362 371
                         });
363 372
                         $operands = [reset($operands)];
364
-                    }
365
-                    elseif ($operator == BelowRule::operator) {
373
+                    } elseif ($operator == BelowRule::operator) {
366 374
                         usort($operands, function( BelowRule $a, BelowRule $b ) {
367
-                            if ($a->getMaximum() === null)
368
-                                return 1;
375
+                            if ($a->getMaximum() === null) {
376
+                                                            return 1;
377
+                            }
369 378
 
370
-                            if ($b->getMaximum() === null)
371
-                                return -1;
379
+                            if ($b->getMaximum() === null) {
380
+                                                            return -1;
381
+                            }
372 382
 
373
-                            if ($a->getMaximum() < $b->getMaximum())
374
-                                return -1;
383
+                            if ($a->getMaximum() < $b->getMaximum()) {
384
+                                                            return -1;
385
+                            }
375 386
 
376 387
                             return 1;
377 388
                         });
378 389
                         $operands = [reset($operands)];
379
-                    }
380
-                    elseif ($operator == EqualRule::operator) {
390
+                    } elseif ($operator == EqualRule::operator) {
381 391
                         // TODO add an option for the support strict comparison
382 392
                         foreach ($operands as $i => $operand) {
383 393
                             if (!isset($previous_operand)) {
@@ -388,8 +398,7 @@  discard block
 block discarded – undo
388 398
                             if ($previous_operand == $operand) {
389 399
                                 unset($operands[$i]);
390 400
                                 continue;
391
-                            }
392
-                            else {
401
+                            } else {
393 402
                                 // Same field expected to be two differents
394 403
                                 // values at the same time has no sens so
395 404
                                 // we remove all the operands of the current
@@ -397,13 +406,13 @@  discard block
 block discarded – undo
397 406
                                 return [];
398 407
                             }
399 408
                         }
400
-                    }
401
-                    elseif ($operator == InRule::operator) {
409
+                    } elseif ($operator == InRule::operator) {
402 410
                         $first_in = reset($operands);
403 411
 
404 412
                         foreach ($operands as $i => $next_in) {
405
-                            if ($first_in === $next_in)
406
-                                continue;
413
+                            if ($first_in === $next_in) {
414
+                                                            continue;
415
+                            }
407 416
 
408 417
                             $first_in->setPossibilities( array_intersect(
409 418
                                 $first_in->getPossibilities(),
@@ -414,15 +423,16 @@  discard block
 block discarded – undo
414 423
                         }
415 424
 
416 425
                         // [field in []] <=> false
417
-                        if (!$first_in->getPossibilities())
418
-                            return [];
419
-                    }
420
-                    elseif ($operator == NotInRule::operator) {
426
+                        if (!$first_in->getPossibilities()) {
427
+                                                    return [];
428
+                        }
429
+                    } elseif ($operator == NotInRule::operator) {
421 430
                         $first_not_in = reset($operands);
422 431
 
423 432
                         foreach ($operands as $i => $next_not_in) {
424
-                            if ($first_not_in === $next_not_in)
425
-                                continue;
433
+                            if ($first_not_in === $next_not_in) {
434
+                                                            continue;
435
+                            }
426 436
 
427 437
                             $first_not_in->setPossibilities( array_merge(
428 438
                                 $first_not_in->getPossibilities(),
@@ -432,8 +442,7 @@  discard block
 block discarded – undo
432 442
                             unset($operands[$i]);
433 443
                         }
434 444
                     }
435
-                }
436
-                catch (\Exception $e) {
445
+                } catch (\Exception $e) {
437 446
                     VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage() . "\n" . var_export([
438 447
                             'operands' => $operands,
439 448
                             // 'this'     => $this,
@@ -503,14 +512,16 @@  discard block
 block discarded – undo
503 512
                 foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $not_equal_rule) {
504 513
 
505 514
                     if ($equalRule->getValue() !== null) {
506
-                        if ($not_equal_rule->getValue() === null) // means if exists <=> equals something
507
-                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
508
-                        elseif ($not_equal_rule->getValue() != $equalRule->getValue())
509
-                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
510
-                    }
511
-                    elseif ($equalRule->getValue() === null ) {
512
-                        if ($not_equal_rule->getValue() !== null)
515
+                        if ($not_equal_rule->getValue() === null) {
516
+                            // means if exists <=> equals something
513 517
                             unset($operandsByOperator[ NotEqualRule::operator ][$i]);
518
+                        } elseif ($not_equal_rule->getValue() != $equalRule->getValue()) {
519
+                                                    unset($operandsByOperator[ NotEqualRule::operator ][$i]);
520
+                        }
521
+                    } elseif ($equalRule->getValue() === null ) {
522
+                        if ($not_equal_rule->getValue() !== null) {
523
+                                                    unset($operandsByOperator[ NotEqualRule::operator ][$i]);
524
+                        }
514 525
                         // else we let the "equal null" and the "not equal null" for the romeInvalidBranches step
515 526
                     }
516 527
                 }
@@ -519,15 +530,17 @@  discard block
 block discarded – undo
519 530
             if (!empty($operandsByOperator[ AboveRule::operator ])) {
520 531
 
521 532
                 $aboveRule = reset($operandsByOperator[ AboveRule::operator ]);
522
-                if ($equalRule->getValue() !== null && $aboveRule->getMinimum() < $equalRule->getValue())
523
-                    unset($operandsByOperator[ AboveRule::operator ]);
533
+                if ($equalRule->getValue() !== null && $aboveRule->getMinimum() < $equalRule->getValue()) {
534
+                                    unset($operandsByOperator[ AboveRule::operator ]);
535
+                }
524 536
             }
525 537
 
526 538
             if (!empty($operandsByOperator[ BelowRule::operator ])) {
527 539
 
528 540
                 $belowRule = reset($operandsByOperator[ BelowRule::operator ]);
529
-                if ($equalRule->getValue() !== null && $belowRule->getMaximum() > $equalRule->getValue())
530
-                    unset($operandsByOperator[ BelowRule::operator ]);
541
+                if ($equalRule->getValue() !== null && $belowRule->getMaximum() > $equalRule->getValue()) {
542
+                                    unset($operandsByOperator[ BelowRule::operator ]);
543
+                }
531 544
             }
532 545
 
533 546
             if (!empty($operandsByOperator[ InRule::operator ])) {
@@ -536,8 +549,7 @@  discard block
 block discarded – undo
536 549
 
537 550
                 if (in_array($equalRule->getValue(), $possibilities)) {
538 551
                     unset($operandsByOperator[ InRule::operator ]);
539
-                }
540
-                else {
552
+                } else {
541 553
                     // We flush possibilities of the InRule
542 554
                     // TODO Replace it by a FalseRule
543 555
                     $operandsByOperator[ InRule::operator ][0]->setPossibilities([]);
@@ -552,8 +564,7 @@  discard block
 block discarded – undo
552 564
                 if (in_array($equalRule->getValue(), $notInRule->getPossibilities())) {
553 565
                     // ['field', '=', 4] && ['field', '!in', [4]...] <=> false
554 566
                     return [];
555
-                }
556
-                else {
567
+                } else {
557 568
                     unset($operandsByOperator[ NotInRule::operator ]);
558 569
                 }
559 570
                 // $notInRule->dump(true);
@@ -564,8 +575,7 @@  discard block
 block discarded – undo
564 575
                 $belowOrEqualRule = reset($operandsByOperator[ BelowOrEqualRule::operator ]);
565 576
                 if ($equalRule->getValue() <= $belowOrEqualRule->getMaximum()) {
566 577
                     unset($operandsByOperator[ BelowOrEqualRule::operator ]);
567
-                }
568
-                else {
578
+                } else {
569 579
                     // ['field', '=', 4] && ['field', '<=', [3]...] <=> false
570 580
                     return [];
571 581
                 }
@@ -576,8 +586,7 @@  discard block
 block discarded – undo
576 586
                 $aboveOrEqualRule = reset($operandsByOperator[ AboveOrEqualRule::operator ]);
577 587
                 if ($equalRule->getValue() >= $aboveOrEqualRule->getMinimum()) {
578 588
                     unset($operandsByOperator[ AboveOrEqualRule::operator ]);
579
-                }
580
-                else {
589
+                } else {
581 590
                     // ['field', '=', 4] && ['field', '<=', [3]...] <=> false
582 591
                     return [];
583 592
                 }
@@ -599,19 +608,21 @@  discard block
 block discarded – undo
599 608
                         }
600 609
 
601 610
                         if (!empty($operandsByOperator[ EqualRule::operator ])) {
602
-                            if (reset($operandsByOperator[ EqualRule::operator ])->getValue() !== null)
603
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
611
+                            if (reset($operandsByOperator[ EqualRule::operator ])->getValue() !== null) {
612
+                                                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
613
+                            }
604 614
                         }
605
-                    }
606
-                    else {
615
+                    } else {
607 616
                         if (!empty($operandsByOperator[ AboveRule::operator ])) {
608
-                            if ($operandsByOperator[ AboveRule::operator ][0]->getMinimum() >= $notEqualRule->getValue())
609
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
617
+                            if ($operandsByOperator[ AboveRule::operator ][0]->getMinimum() >= $notEqualRule->getValue()) {
618
+                                                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
619
+                            }
610 620
                         }
611 621
 
612 622
                         if (!empty($operandsByOperator[ BelowRule::operator ])) {
613
-                            if ($operandsByOperator[ BelowRule::operator ][0]->getMaximum() <= $notEqualRule->getValue())
614
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
623
+                            if ($operandsByOperator[ BelowRule::operator ][0]->getMaximum() <= $notEqualRule->getValue()) {
624
+                                                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
625
+                            }
615 626
                         }
616 627
                     }
617 628
 
@@ -712,8 +723,7 @@  discard block
 block discarded – undo
712 723
                     // [field < 3] && [field <= 3]
713 724
                     // [field < 3] && [field <= 4]
714 725
                     unset($operandsByOperator[ BelowOrEqualRule::operator ][0]);
715
-                }
716
-                else {
726
+                } else {
717 727
                     // [field < 3] && [field <= 2]
718 728
                     unset($operandsByOperator[ BelowRule::operator ][0]);
719 729
                 }
@@ -734,8 +744,7 @@  discard block
 block discarded – undo
734 744
                 if ($belowOrEqualRule->getMaximum() < $minimum) {
735 745
                     // [field <= 3] && [field >= 4] <=> false
736 746
                     return [];
737
-                }
738
-                elseif ($belowOrEqualRule->getMaximum() == $minimum) {
747
+                } elseif ($belowOrEqualRule->getMaximum() == $minimum) {
739 748
                     // [field <= 3] && [field >= 3] <=> [field = 3]
740 749
                     unset($operandsByOperator[ BelowOrEqualRule::operator ]);
741 750
                     unset($operandsByOperator[ AboveOrEqualRule::operator ]);
@@ -761,8 +770,7 @@  discard block
 block discarded – undo
761 770
     {
762 771
         try {
763 772
             return $this->setOperands( $new_operands );
764
-        }
765
-        catch (\LogicException $e) {
773
+        } catch (\LogicException $e) {
766 774
             return new AndRule( $new_operands );
767 775
         }
768 776
     }
Please login to merge, or discard this patch.
src/Rule/AboveOrEqualRule.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
      * @param string $field The field to apply the rule on.
19 19
      * @param array  $value The value the field can below to.
20 20
      */
21
-    public function __construct($field, $minimum, array $options=[])
21
+    public function __construct($field, $minimum, array $options = [])
22 22
     {
23 23
         if (!empty($options)) {
24 24
             $this->setOptions($options);
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     /**
63 63
      * @return bool
64 64
      */
65
-    public function isNormalizationAllowed(array $contextual_options=[])
65
+    public function isNormalizationAllowed(array $contextual_options = [])
66 66
     {
67 67
         return $this->getOption('above_or_equal.normalization', $contextual_options);
68 68
     }
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function getOperands()
74 74
     {
75
-        if (! empty($this->cache['operands'])) {
75
+        if (!empty($this->cache['operands'])) {
76 76
             return $this->cache['operands'];
77 77
         }
78 78
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
             }
105 105
         }
106 106
 
107
-        if (    count($operands) != 2
107
+        if (count($operands) != 2
108 108
             || !isset($equalRuleValue)
109 109
             || !isset($aboveRuleValue)
110 110
             || $aboveRuleValue != $equalRuleValue
@@ -135,14 +135,14 @@  discard block
 block discarded – undo
135 135
      *
136 136
      * @return array
137 137
      */
138
-    public function toArray(array $options=[])
138
+    public function toArray(array $options = [])
139 139
     {
140 140
         $default_options = [
141 141
             'show_instance' => false,
142 142
         ];
143 143
         foreach ($default_options as $default_option => &$default_value) {
144
-            if (!isset($options[ $default_option ]))
145
-                $options[ $default_option ] = $default_value;
144
+            if (!isset($options[$default_option]))
145
+                $options[$default_option] = $default_value;
146 146
         }
147 147
 
148 148
         try {
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
 
161 161
     /**
162 162
      */
163
-    public function toString(array $options=[])
163
+    public function toString(array $options = [])
164 164
     {
165 165
         if (isset($this->cache['string']))
166 166
             return $this->cache['string'];
167 167
 
168 168
         $operator = self::operator;
169 169
 
170
-        return $this->cache['string'] = "['{$this->getField()}', '$operator', " . var_export($this->getValues(), true). "]";
170
+        return $this->cache['string'] = "['{$this->getField()}', '$operator', ".var_export($this->getValues(), true)."]";
171 171
     }
172 172
 
173 173
     /**/
Please login to merge, or discard this patch.
Braces   +11 added lines, -10 removed lines patch added patch discarded remove patch
@@ -50,8 +50,9 @@  discard block
 block discarded – undo
50 50
             );
51 51
         }
52 52
 
53
-        if ($this->minimum == $minimum)
54
-            return $this;
53
+        if ($this->minimum == $minimum) {
54
+                    return $this;
55
+        }
55 56
 
56 57
         $this->minimum = $minimum;
57 58
         $this->flushCache();
@@ -97,8 +98,7 @@  discard block
 block discarded – undo
97 98
             if ($operand instanceof EqualRule) {
98 99
                 $equalRuleField = $operand->getField();
99 100
                 $equalRuleValue = $operand->getValue();
100
-            }
101
-            elseif ($operand instanceof AboveRule) {
101
+            } elseif ($operand instanceof AboveRule) {
102 102
                 $aboveRuleField = $operand->getField();
103 103
                 $aboveRuleValue = $operand->getLowerLimit();
104 104
             }
@@ -141,8 +141,9 @@  discard block
 block discarded – undo
141 141
             'show_instance' => false,
142 142
         ];
143 143
         foreach ($default_options as $default_option => &$default_value) {
144
-            if (!isset($options[ $default_option ]))
145
-                $options[ $default_option ] = $default_value;
144
+            if (!isset($options[ $default_option ])) {
145
+                            $options[ $default_option ] = $default_value;
146
+            }
146 147
         }
147 148
 
148 149
         try {
@@ -152,8 +153,7 @@  discard block
 block discarded – undo
152 153
                 $options['show_instance'] ? $this->getInstanceId() : self::operator,
153 154
                 $this->getValues(),
154 155
             ];
155
-        }
156
-        catch (\RuntimeException $e) {
156
+        } catch (\RuntimeException $e) {
157 157
             return parent::toArray();
158 158
         }
159 159
     }
@@ -162,8 +162,9 @@  discard block
 block discarded – undo
162 162
      */
163 163
     public function toString(array $options=[])
164 164
     {
165
-        if (isset($this->cache['string']))
166
-            return $this->cache['string'];
165
+        if (isset($this->cache['string'])) {
166
+                    return $this->cache['string'];
167
+        }
167 168
 
168 169
         $operator = self::operator;
169 170
 
Please login to merge, or discard this patch.