Test Failed
Push — master ( 14bb9e...d96886 )
by Jean
04:16
created
src/Rule/AndRule.php 2 patches
Spacing   +133 added lines, -133 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
                     }
@@ -483,79 +483,79 @@  discard block
 block discarded – undo
483 483
             }
484 484
 
485 485
             // EqualRule comparisons
486
-            if (!empty($operandsByOperator[ EqualRule::operator ])) {
487
-                if (count($operandsByOperator[ EqualRule::operator ]) != 1) {
486
+            if (!empty($operandsByOperator[EqualRule::operator])) {
487
+                if (count($operandsByOperator[EqualRule::operator]) != 1) {
488 488
                     // Multiple Equal rules for one field with different values has no sense
489 489
                     continue;
490 490
                 }
491 491
 
492
-                $equalRule = reset( $operandsByOperator[ EqualRule::operator ] );
492
+                $equalRule = reset($operandsByOperator[EqualRule::operator]);
493 493
 
494
-                if (!empty($operandsByOperator[ NotEqualRule::operator ])) {
495
-                    foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $not_equal_rule) {
494
+                if (!empty($operandsByOperator[NotEqualRule::operator])) {
495
+                    foreach ($operandsByOperator[NotEqualRule::operator] as $i => $not_equal_rule) {
496 496
 
497 497
                         if ($equalRule->getValue() !== null) {
498 498
                             if ($not_equal_rule->getValue() === null) // means if exists <=> equals something
499
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
499
+                                unset($operandsByOperator[NotEqualRule::operator][$i]);
500 500
                             elseif ($not_equal_rule->getValue() != $equalRule->getValue())
501
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
501
+                                unset($operandsByOperator[NotEqualRule::operator][$i]);
502 502
                         }
503
-                        elseif ($equalRule->getValue() === null ) {
503
+                        elseif ($equalRule->getValue() === null) {
504 504
                             if ($not_equal_rule->getValue() !== null)
505
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
505
+                                unset($operandsByOperator[NotEqualRule::operator][$i]);
506 506
                             // else we let the "equal null" and the "not equal null" for the romeInvalidBranches step
507 507
                         }
508 508
                     }
509 509
                 }
510 510
 
511
-                if (!empty($operandsByOperator[ AboveRule::operator ])) {
511
+                if (!empty($operandsByOperator[AboveRule::operator])) {
512 512
 
513
-                    $aboveRule = reset($operandsByOperator[ AboveRule::operator ]);
513
+                    $aboveRule = reset($operandsByOperator[AboveRule::operator]);
514 514
                     if ($equalRule->getValue() !== null && $aboveRule->getMinimum() < $equalRule->getValue())
515
-                        unset($operandsByOperator[ AboveRule::operator ]);
515
+                        unset($operandsByOperator[AboveRule::operator]);
516 516
                 }
517 517
 
518
-                if (!empty($operandsByOperator[ BelowRule::operator ])) {
518
+                if (!empty($operandsByOperator[BelowRule::operator])) {
519 519
 
520
-                    $belowRule = reset($operandsByOperator[ BelowRule::operator ]);
520
+                    $belowRule = reset($operandsByOperator[BelowRule::operator]);
521 521
                     if ($equalRule->getValue() !== null && $belowRule->getMaximum() > $equalRule->getValue())
522
-                        unset($operandsByOperator[ BelowRule::operator ]);
522
+                        unset($operandsByOperator[BelowRule::operator]);
523 523
                 }
524 524
 
525
-                if (!empty($operandsByOperator[ InRule::operator ])) {
525
+                if (!empty($operandsByOperator[InRule::operator])) {
526 526
 
527
-                    $possibilities = reset($operandsByOperator[ InRule::operator ])->getPossibilities();
527
+                    $possibilities = reset($operandsByOperator[InRule::operator])->getPossibilities();
528 528
 
529 529
                     if (in_array($equalRule->getValue(), $possibilities)) {
530
-                        unset($operandsByOperator[ InRule::operator ]);
530
+                        unset($operandsByOperator[InRule::operator]);
531 531
                     }
532 532
                     else {
533 533
                         // We flush possibilities of the InRule
534 534
                         // TODO Replace it by a FalseRule
535
-                        $operandsByOperator[ InRule::operator ][0]->setPossibilities([]);
535
+                        $operandsByOperator[InRule::operator][0]->setPossibilities([]);
536 536
                         // and also remove the equal rule to shorten the reste of the simplification process
537
-                        unset($operandsByOperator[ EqualRule::operator ]);
537
+                        unset($operandsByOperator[EqualRule::operator]);
538 538
                     }
539 539
                 }
540 540
 
541
-                if (!empty($operandsByOperator[ NotInRule::operator ])) {
541
+                if (!empty($operandsByOperator[NotInRule::operator])) {
542 542
 
543
-                    $notInRule = reset($operandsByOperator[ NotInRule::operator ]);
543
+                    $notInRule = reset($operandsByOperator[NotInRule::operator]);
544 544
                     if (in_array($equalRule->getValue(), $notInRule->getPossibilities())) {
545 545
                         // ['field', '=', 4] && ['field', '!in', [4]...] <=> false
546 546
                         return [];
547 547
                     }
548 548
                     else {
549
-                        unset($operandsByOperator[ NotInRule::operator ]);
549
+                        unset($operandsByOperator[NotInRule::operator]);
550 550
                     }
551 551
                     // $notInRule->dump(true);
552 552
                 }
553 553
 
554
-                if (!empty($operandsByOperator[ BelowOrEqualRule::operator ])) {
554
+                if (!empty($operandsByOperator[BelowOrEqualRule::operator])) {
555 555
 
556
-                    $belowOrEqualRule = reset($operandsByOperator[ BelowOrEqualRule::operator ]);
556
+                    $belowOrEqualRule = reset($operandsByOperator[BelowOrEqualRule::operator]);
557 557
                     if ($equalRule->getValue() <= $belowOrEqualRule->getMaximum()) {
558
-                        unset($operandsByOperator[ BelowOrEqualRule::operator ]);
558
+                        unset($operandsByOperator[BelowOrEqualRule::operator]);
559 559
                     }
560 560
                     else {
561 561
                         // ['field', '=', 4] && ['field', '<=', [3]...] <=> false
@@ -565,52 +565,52 @@  discard block
 block discarded – undo
565 565
             }
566 566
 
567 567
             // NotEqualRule null comparisons
568
-            if (!empty($operandsByOperator[ NotEqualRule::operator ])) {
569
-                if (!empty($operandsByOperator[ NotEqualRule::operator ])) {
570
-                    foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $notEqualRule) {
568
+            if (!empty($operandsByOperator[NotEqualRule::operator])) {
569
+                if (!empty($operandsByOperator[NotEqualRule::operator])) {
570
+                    foreach ($operandsByOperator[NotEqualRule::operator] as $i => $notEqualRule) {
571 571
 
572 572
                         if ($notEqualRule->getValue() === null) {
573
-                            if (!empty($operandsByOperator[ AboveRule::operator ])) {
574
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
573
+                            if (!empty($operandsByOperator[AboveRule::operator])) {
574
+                                unset($operandsByOperator[NotEqualRule::operator][$i]);
575 575
                             }
576 576
 
577
-                            if (!empty($operandsByOperator[ BelowRule::operator ])) {
578
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
577
+                            if (!empty($operandsByOperator[BelowRule::operator])) {
578
+                                unset($operandsByOperator[NotEqualRule::operator][$i]);
579 579
                             }
580 580
 
581
-                            if (!empty($operandsByOperator[ EqualRule::operator ])) {
582
-                                if (reset($operandsByOperator[ EqualRule::operator ])->getValue() !== null)
583
-                                    unset($operandsByOperator[ NotEqualRule::operator ][$i]);
581
+                            if (!empty($operandsByOperator[EqualRule::operator])) {
582
+                                if (reset($operandsByOperator[EqualRule::operator])->getValue() !== null)
583
+                                    unset($operandsByOperator[NotEqualRule::operator][$i]);
584 584
                             }
585 585
                         }
586 586
                         else {
587
-                            if (!empty($operandsByOperator[ AboveRule::operator ])) {
588
-                                if ($operandsByOperator[ AboveRule::operator ][0]->getMinimum() >= $notEqualRule->getValue())
589
-                                    unset($operandsByOperator[ NotEqualRule::operator ][$i]);
587
+                            if (!empty($operandsByOperator[AboveRule::operator])) {
588
+                                if ($operandsByOperator[AboveRule::operator][0]->getMinimum() >= $notEqualRule->getValue())
589
+                                    unset($operandsByOperator[NotEqualRule::operator][$i]);
590 590
                             }
591 591
 
592
-                            if (!empty($operandsByOperator[ BelowRule::operator ])) {
593
-                                if ($operandsByOperator[ BelowRule::operator ][0]->getMaximum() <= $notEqualRule->getValue())
594
-                                    unset($operandsByOperator[ NotEqualRule::operator ][$i]);
592
+                            if (!empty($operandsByOperator[BelowRule::operator])) {
593
+                                if ($operandsByOperator[BelowRule::operator][0]->getMaximum() <= $notEqualRule->getValue())
594
+                                    unset($operandsByOperator[NotEqualRule::operator][$i]);
595 595
                             }
596 596
                         }
597 597
 
598
-                        if (!empty($operandsByOperator[ NotInRule::operator ])) {
599
-                            $notInRule = reset($operandsByOperator[ NotInRule::operator ]);
598
+                        if (!empty($operandsByOperator[NotInRule::operator])) {
599
+                            $notInRule = reset($operandsByOperator[NotInRule::operator]);
600 600
                             if (!in_array($notEqualRule->getValue(), $notInRule->getPossibilities())) {
601 601
                                 // TODO Replace it by a FalseRule
602
-                                $operandsByFields[ $field ][ NotInRule::operator ][0]->setPossibilities(
602
+                                $operandsByFields[$field][NotInRule::operator][0]->setPossibilities(
603 603
                                     array_merge($notInRule->getPossibilities(), [$notEqualRule->getValue()])
604 604
                                 );
605 605
                             }
606 606
 
607
-                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
607
+                            unset($operandsByOperator[NotEqualRule::operator][$i]);
608 608
                         }
609 609
 
610
-                        if (!empty($operandsByOperator[ InRule::operator ])) {
611
-                            $inRule = reset($operandsByOperator[ InRule::operator ]);
610
+                        if (!empty($operandsByOperator[InRule::operator])) {
611
+                            $inRule = reset($operandsByOperator[InRule::operator]);
612 612
 
613
-                            $operandsByOperator[ InRule::operator ][0]->setPossibilities(
613
+                            $operandsByOperator[InRule::operator][0]->setPossibilities(
614 614
                                 array_diff($inRule->getPossibilities(), [$notEqualRule->getValue()])
615 615
                             );
616 616
                         }
@@ -620,61 +620,61 @@  discard block
 block discarded – undo
620 620
 
621 621
             // Comparison between InRules and NotInRules
622 622
             // This is an optimization to avoid NotIn explosion
623
-            if (!empty($operandsByOperator[ InRule::operator ])) {
624
-                $inRule = $operandsByOperator[ InRule::operator ][0];
623
+            if (!empty($operandsByOperator[InRule::operator])) {
624
+                $inRule = $operandsByOperator[InRule::operator][0];
625 625
 
626
-                if (!empty($operandsByOperator[ NotInRule::operator ])) {
627
-                    $notInRule = reset($operandsByOperator[ NotInRule::operator ]);
628
-                    $operandsByOperator[ InRule::operator ][0]->setPossibilities(
629
-                        array_diff( $inRule->getPossibilities(), $notInRule->getPossibilities())
626
+                if (!empty($operandsByOperator[NotInRule::operator])) {
627
+                    $notInRule = reset($operandsByOperator[NotInRule::operator]);
628
+                    $operandsByOperator[InRule::operator][0]->setPossibilities(
629
+                        array_diff($inRule->getPossibilities(), $notInRule->getPossibilities())
630 630
                     );
631
-                    unset($operandsByOperator[ NotInRule::operator ]);
631
+                    unset($operandsByOperator[NotInRule::operator]);
632 632
                 }
633 633
 
634
-                if (!empty($operandsByOperator[ BelowRule::operator ])) {
635
-                    $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getMaximum();
634
+                if (!empty($operandsByOperator[BelowRule::operator])) {
635
+                    $upper_limit = reset($operandsByOperator[BelowRule::operator])->getMaximum();
636 636
 
637
-                    $operandsByOperator[ InRule::operator ][0]->setPossibilities(
638
-                        array_filter( $inRule->getPossibilities(), function ($possibility) use ($upper_limit) {
637
+                    $operandsByOperator[InRule::operator][0]->setPossibilities(
638
+                        array_filter($inRule->getPossibilities(), function($possibility) use ($upper_limit) {
639 639
                             return $possibility < $upper_limit;
640 640
                         } )
641 641
                     );
642 642
 
643
-                    unset($operandsByOperator[ BelowRule::operator ]);
643
+                    unset($operandsByOperator[BelowRule::operator]);
644 644
                 }
645 645
 
646
-                if (!empty($operandsByOperator[ AboveRule::operator ])) {
647
-                    $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getMinimum();
646
+                if (!empty($operandsByOperator[AboveRule::operator])) {
647
+                    $lower_limit = reset($operandsByOperator[AboveRule::operator])->getMinimum();
648 648
 
649
-                    $operandsByOperator[ InRule::operator ][0]->setPossibilities(
650
-                        array_filter( $inRule->getPossibilities(), function ($possibility) use ($lower_limit) {
649
+                    $operandsByOperator[InRule::operator][0]->setPossibilities(
650
+                        array_filter($inRule->getPossibilities(), function($possibility) use ($lower_limit) {
651 651
                             return $possibility > $lower_limit;
652 652
                         } )
653 653
                     );
654 654
 
655
-                    unset($operandsByOperator[ AboveRule::operator ]);
655
+                    unset($operandsByOperator[AboveRule::operator]);
656 656
                 }
657 657
             }
658 658
 
659 659
             // Comparison between NotInRules and > or <
660
-            if (!empty($operandsByOperator[ NotInRule::operator ])) {
661
-                $notInRule = $operandsByOperator[ NotInRule::operator ][0];
660
+            if (!empty($operandsByOperator[NotInRule::operator])) {
661
+                $notInRule = $operandsByOperator[NotInRule::operator][0];
662 662
 
663
-                if (!empty($operandsByOperator[ BelowRule::operator ])) {
664
-                    $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit();
663
+                if (!empty($operandsByOperator[BelowRule::operator])) {
664
+                    $upper_limit = reset($operandsByOperator[BelowRule::operator])->getUpperLimit();
665 665
 
666
-                    $operandsByOperator[ NotInRule::operator ][0]->setPossibilities(
667
-                        array_filter( $notInRule->getPossibilities(), function ($possibility) use ($upper_limit) {
666
+                    $operandsByOperator[NotInRule::operator][0]->setPossibilities(
667
+                        array_filter($notInRule->getPossibilities(), function($possibility) use ($upper_limit) {
668 668
                             return $possibility < $upper_limit;
669 669
                         } )
670 670
                     );
671 671
                 }
672 672
 
673
-                if (!empty($operandsByOperator[ AboveRule::operator ])) {
674
-                    $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getMinimum();
673
+                if (!empty($operandsByOperator[AboveRule::operator])) {
674
+                    $lower_limit = reset($operandsByOperator[AboveRule::operator])->getMinimum();
675 675
 
676
-                    $operandsByOperator[ NotInRule::operator ][0]->setPossibilities(
677
-                        array_filter( $notInRule->getPossibilities(), function ($possibility) use ($lower_limit) {
676
+                    $operandsByOperator[NotInRule::operator][0]->setPossibilities(
677
+                        array_filter($notInRule->getPossibilities(), function($possibility) use ($lower_limit) {
678 678
                             return $possibility > $lower_limit;
679 679
                         } )
680 680
                     );
@@ -682,25 +682,25 @@  discard block
 block discarded – undo
682 682
             }
683 683
 
684 684
             // Comparison between <= and > or <
685
-            if (!empty($operandsByOperator[ BelowOrEqualRule::operator ])) {
686
-                $belowOrEqualRule = $operandsByOperator[ BelowOrEqualRule::operator ][0];
685
+            if (!empty($operandsByOperator[BelowOrEqualRule::operator])) {
686
+                $belowOrEqualRule = $operandsByOperator[BelowOrEqualRule::operator][0];
687 687
 
688
-                if (!empty($operandsByOperator[ BelowRule::operator ])) {
689
-                    $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit();
688
+                if (!empty($operandsByOperator[BelowRule::operator])) {
689
+                    $upper_limit = reset($operandsByOperator[BelowRule::operator])->getUpperLimit();
690 690
 
691 691
                     if ($belowOrEqualRule->getMaximum() >= $upper_limit) {
692 692
                         // [field < 3] && [field <= 3]
693 693
                         // [field < 3] && [field <= 4]
694
-                        unset($operandsByOperator[ BelowOrEqualRule::operator ][0]);
694
+                        unset($operandsByOperator[BelowOrEqualRule::operator][0]);
695 695
                     }
696 696
                     else {
697 697
                         // [field < 3] && [field <= 2]
698
-                        unset($operandsByOperator[ BelowRule::operator ][0]);
698
+                        unset($operandsByOperator[BelowRule::operator][0]);
699 699
                     }
700 700
                 }
701 701
 
702
-                if (!empty($operandsByOperator[ AboveRule::operator ])) {
703
-                    $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getLowerLimit();
702
+                if (!empty($operandsByOperator[AboveRule::operator])) {
703
+                    $lower_limit = reset($operandsByOperator[AboveRule::operator])->getLowerLimit();
704 704
 
705 705
                     if ($belowOrEqualRule->getMaximum() <= $lower_limit) {
706 706
                         // [field > 3] && [field <= 2] <=> false
@@ -722,10 +722,10 @@  discard block
 block discarded – undo
722 722
     public function setOperandsOrReplaceByOperation($new_operands)
723 723
     {
724 724
         try {
725
-            return $this->setOperands( $new_operands );
725
+            return $this->setOperands($new_operands);
726 726
         }
727 727
         catch (\LogicException $e) {
728
-            return new AndRule( $new_operands );
728
+            return new AndRule($new_operands);
729 729
         }
730 730
     }
731 731
 
Please login to merge, or discard this patch.
Braces   +104 added lines, -94 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,
@@ -495,14 +504,16 @@  discard block
 block discarded – undo
495 504
                     foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $not_equal_rule) {
496 505
 
497 506
                         if ($equalRule->getValue() !== null) {
498
-                            if ($not_equal_rule->getValue() === null) // means if exists <=> equals something
499
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
500
-                            elseif ($not_equal_rule->getValue() != $equalRule->getValue())
501
-                                unset($operandsByOperator[ NotEqualRule::operator ][$i]);
502
-                        }
503
-                        elseif ($equalRule->getValue() === null ) {
504
-                            if ($not_equal_rule->getValue() !== null)
507
+                            if ($not_equal_rule->getValue() === null) {
508
+                                // means if exists <=> equals something
505 509
                                 unset($operandsByOperator[ NotEqualRule::operator ][$i]);
510
+                            } elseif ($not_equal_rule->getValue() != $equalRule->getValue()) {
511
+                                                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
512
+                            }
513
+                        } elseif ($equalRule->getValue() === null ) {
514
+                            if ($not_equal_rule->getValue() !== null) {
515
+                                                            unset($operandsByOperator[ NotEqualRule::operator ][$i]);
516
+                            }
506 517
                             // else we let the "equal null" and the "not equal null" for the romeInvalidBranches step
507 518
                         }
508 519
                     }
@@ -511,15 +522,17 @@  discard block
 block discarded – undo
511 522
                 if (!empty($operandsByOperator[ AboveRule::operator ])) {
512 523
 
513 524
                     $aboveRule = reset($operandsByOperator[ AboveRule::operator ]);
514
-                    if ($equalRule->getValue() !== null && $aboveRule->getMinimum() < $equalRule->getValue())
515
-                        unset($operandsByOperator[ AboveRule::operator ]);
525
+                    if ($equalRule->getValue() !== null && $aboveRule->getMinimum() < $equalRule->getValue()) {
526
+                                            unset($operandsByOperator[ AboveRule::operator ]);
527
+                    }
516 528
                 }
517 529
 
518 530
                 if (!empty($operandsByOperator[ BelowRule::operator ])) {
519 531
 
520 532
                     $belowRule = reset($operandsByOperator[ BelowRule::operator ]);
521
-                    if ($equalRule->getValue() !== null && $belowRule->getMaximum() > $equalRule->getValue())
522
-                        unset($operandsByOperator[ BelowRule::operator ]);
533
+                    if ($equalRule->getValue() !== null && $belowRule->getMaximum() > $equalRule->getValue()) {
534
+                                            unset($operandsByOperator[ BelowRule::operator ]);
535
+                    }
523 536
                 }
524 537
 
525 538
                 if (!empty($operandsByOperator[ InRule::operator ])) {
@@ -528,8 +541,7 @@  discard block
 block discarded – undo
528 541
 
529 542
                     if (in_array($equalRule->getValue(), $possibilities)) {
530 543
                         unset($operandsByOperator[ InRule::operator ]);
531
-                    }
532
-                    else {
544
+                    } else {
533 545
                         // We flush possibilities of the InRule
534 546
                         // TODO Replace it by a FalseRule
535 547
                         $operandsByOperator[ InRule::operator ][0]->setPossibilities([]);
@@ -544,8 +556,7 @@  discard block
 block discarded – undo
544 556
                     if (in_array($equalRule->getValue(), $notInRule->getPossibilities())) {
545 557
                         // ['field', '=', 4] && ['field', '!in', [4]...] <=> false
546 558
                         return [];
547
-                    }
548
-                    else {
559
+                    } else {
549 560
                         unset($operandsByOperator[ NotInRule::operator ]);
550 561
                     }
551 562
                     // $notInRule->dump(true);
@@ -556,8 +567,7 @@  discard block
 block discarded – undo
556 567
                     $belowOrEqualRule = reset($operandsByOperator[ BelowOrEqualRule::operator ]);
557 568
                     if ($equalRule->getValue() <= $belowOrEqualRule->getMaximum()) {
558 569
                         unset($operandsByOperator[ BelowOrEqualRule::operator ]);
559
-                    }
560
-                    else {
570
+                    } else {
561 571
                         // ['field', '=', 4] && ['field', '<=', [3]...] <=> false
562 572
                         return [];
563 573
                     }
@@ -579,19 +589,21 @@  discard block
 block discarded – undo
579 589
                             }
580 590
 
581 591
                             if (!empty($operandsByOperator[ EqualRule::operator ])) {
582
-                                if (reset($operandsByOperator[ EqualRule::operator ])->getValue() !== null)
583
-                                    unset($operandsByOperator[ NotEqualRule::operator ][$i]);
592
+                                if (reset($operandsByOperator[ EqualRule::operator ])->getValue() !== null) {
593
+                                                                    unset($operandsByOperator[ NotEqualRule::operator ][$i]);
594
+                                }
584 595
                             }
585
-                        }
586
-                        else {
596
+                        } else {
587 597
                             if (!empty($operandsByOperator[ AboveRule::operator ])) {
588
-                                if ($operandsByOperator[ AboveRule::operator ][0]->getMinimum() >= $notEqualRule->getValue())
589
-                                    unset($operandsByOperator[ NotEqualRule::operator ][$i]);
598
+                                if ($operandsByOperator[ AboveRule::operator ][0]->getMinimum() >= $notEqualRule->getValue()) {
599
+                                                                    unset($operandsByOperator[ NotEqualRule::operator ][$i]);
600
+                                }
590 601
                             }
591 602
 
592 603
                             if (!empty($operandsByOperator[ BelowRule::operator ])) {
593
-                                if ($operandsByOperator[ BelowRule::operator ][0]->getMaximum() <= $notEqualRule->getValue())
594
-                                    unset($operandsByOperator[ NotEqualRule::operator ][$i]);
604
+                                if ($operandsByOperator[ BelowRule::operator ][0]->getMaximum() <= $notEqualRule->getValue()) {
605
+                                                                    unset($operandsByOperator[ NotEqualRule::operator ][$i]);
606
+                                }
595 607
                             }
596 608
                         }
597 609
 
@@ -692,8 +704,7 @@  discard block
 block discarded – undo
692 704
                         // [field < 3] && [field <= 3]
693 705
                         // [field < 3] && [field <= 4]
694 706
                         unset($operandsByOperator[ BelowOrEqualRule::operator ][0]);
695
-                    }
696
-                    else {
707
+                    } else {
697 708
                         // [field < 3] && [field <= 2]
698 709
                         unset($operandsByOperator[ BelowRule::operator ][0]);
699 710
                     }
@@ -723,8 +734,7 @@  discard block
 block discarded – undo
723 734
     {
724 735
         try {
725 736
             return $this->setOperands( $new_operands );
726
-        }
727
-        catch (\LogicException $e) {
737
+        } catch (\LogicException $e) {
728 738
             return new AndRule( $new_operands );
729 739
         }
730 740
     }
Please login to merge, or discard this patch.
src/Rule/BelowOrEqualRule.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, $maximum, array $options=[])
21
+    public function __construct($field, $maximum, 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('below_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($belowRuleValue)
110 110
             || $belowRuleValue != $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->maximum == $maximum)
54
-            return $this;
53
+        if ($this->maximum == $maximum) {
54
+                    return $this;
55
+        }
55 56
 
56 57
         $this->maximum = $maximum;
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 BelowRule) {
101
+            } elseif ($operand instanceof BelowRule) {
102 102
                 $belowRuleField = $operand->getField();
103 103
                 $belowRuleValue = $operand->getUpperLimit();
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.