@@ -13,17 +13,17 @@ discard block |
||
13 | 13 | * @param string $field The field to apply the rule on. |
14 | 14 | * @param array $value The value the field can equal to. |
15 | 15 | */ |
16 | - public function __construct( $field, $possibilities ) |
|
16 | + public function __construct($field, $possibilities) |
|
17 | 17 | { |
18 | 18 | $this->addOperand(new InRule($field, $possibilities)); |
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
22 | 22 | */ |
23 | - public function isNormalizationAllowed(array $contextual_options=[]) |
|
23 | + public function isNormalizationAllowed(array $contextual_options = []) |
|
24 | 24 | { |
25 | 25 | $operand = $this->getOperandAt(0); |
26 | - if ( ! $operand->getPossibilities()) |
|
26 | + if (!$operand->getPossibilities()) |
|
27 | 27 | return false; |
28 | 28 | |
29 | 29 | return $operand->isNormalizationAllowed($contextual_options); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function setPossibilities($possibilities) |
79 | 79 | { |
80 | - if ( is_object($possibilities) |
|
80 | + if (is_object($possibilities) |
|
81 | 81 | && $possibilities instanceof \IteratorAggregate |
82 | 82 | && method_exists($possibilities, 'toArray') |
83 | 83 | ) { |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | /** |
115 | 115 | */ |
116 | - public function hasSolution(array $contextual_options=[]) |
|
116 | + public function hasSolution(array $contextual_options = []) |
|
117 | 117 | { |
118 | 118 | return true; |
119 | 119 | } |
@@ -123,14 +123,14 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return array |
125 | 125 | */ |
126 | - public function toArray(array $options=[]) |
|
126 | + public function toArray(array $options = []) |
|
127 | 127 | { |
128 | 128 | $default_options = [ |
129 | 129 | 'show_instance' => false, |
130 | 130 | ]; |
131 | 131 | foreach ($default_options as $default_option => &$default_value) { |
132 | - if (!isset($options[ $default_option ])) |
|
133 | - $options[ $default_option ] = $default_value; |
|
132 | + if (!isset($options[$default_option])) |
|
133 | + $options[$default_option] = $default_value; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | try { |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | |
148 | 148 | /** |
149 | 149 | */ |
150 | - public function toString(array $options=[]) |
|
150 | + public function toString(array $options = []) |
|
151 | 151 | { |
152 | 152 | try { |
153 | 153 | // if (!$this->changed) |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | |
158 | 158 | $operator = self::operator; |
159 | 159 | |
160 | - $stringified_possibilities = '[' . implode(', ', array_map(function($possibility) { |
|
160 | + $stringified_possibilities = '['.implode(', ', array_map(function($possibility) { |
|
161 | 161 | return var_export($possibility, true); |
162 | - }, $this->getPossibilities()) ) .']'; |
|
162 | + }, $this->getPossibilities())).']'; |
|
163 | 163 | |
164 | 164 | // return $this->cache = "['{$this->getField()}', '$operator', stringified_possibilities]"; |
165 | 165 | return "['{$this->getField()}', '$operator', $stringified_possibilities]"; |
@@ -24,7 +24,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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,122 +483,122 @@ discard block |
||
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 | 554 | |
555 | 555 | // NotEqualRule null comparisons |
556 | - if (!empty($operandsByOperator[ NotEqualRule::operator ])) { |
|
557 | - if (!empty($operandsByOperator[ NotEqualRule::operator ])) { |
|
558 | - foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $notEqualRule) { |
|
556 | + if (!empty($operandsByOperator[NotEqualRule::operator])) { |
|
557 | + if (!empty($operandsByOperator[NotEqualRule::operator])) { |
|
558 | + foreach ($operandsByOperator[NotEqualRule::operator] as $i => $notEqualRule) { |
|
559 | 559 | |
560 | 560 | if ($notEqualRule->getValue() === null) { |
561 | - if (!empty($operandsByOperator[ AboveRule::operator ])) { |
|
562 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
561 | + if (!empty($operandsByOperator[AboveRule::operator])) { |
|
562 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
563 | 563 | } |
564 | 564 | |
565 | - if (!empty($operandsByOperator[ BelowRule::operator ])) { |
|
566 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
565 | + if (!empty($operandsByOperator[BelowRule::operator])) { |
|
566 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
567 | 567 | } |
568 | 568 | |
569 | - if (!empty($operandsByOperator[ EqualRule::operator ])) { |
|
570 | - if (reset($operandsByOperator[ EqualRule::operator ])->getValue() !== null) |
|
571 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
569 | + if (!empty($operandsByOperator[EqualRule::operator])) { |
|
570 | + if (reset($operandsByOperator[EqualRule::operator])->getValue() !== null) |
|
571 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
572 | 572 | } |
573 | 573 | } |
574 | 574 | else { |
575 | - if (!empty($operandsByOperator[ AboveRule::operator ])) { |
|
576 | - if ($operandsByOperator[ AboveRule::operator ][0]->getMinimum() >= $notEqualRule->getValue()) |
|
577 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
575 | + if (!empty($operandsByOperator[AboveRule::operator])) { |
|
576 | + if ($operandsByOperator[AboveRule::operator][0]->getMinimum() >= $notEqualRule->getValue()) |
|
577 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
578 | 578 | } |
579 | 579 | |
580 | - if (!empty($operandsByOperator[ BelowRule::operator ])) { |
|
581 | - if ($operandsByOperator[ BelowRule::operator ][0]->getMaximum() <= $notEqualRule->getValue()) |
|
582 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
580 | + if (!empty($operandsByOperator[BelowRule::operator])) { |
|
581 | + if ($operandsByOperator[BelowRule::operator][0]->getMaximum() <= $notEqualRule->getValue()) |
|
582 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
583 | 583 | } |
584 | 584 | } |
585 | 585 | |
586 | - if (!empty($operandsByOperator[ NotInRule::operator ])) { |
|
587 | - $notInRule = reset($operandsByOperator[ NotInRule::operator ]); |
|
586 | + if (!empty($operandsByOperator[NotInRule::operator])) { |
|
587 | + $notInRule = reset($operandsByOperator[NotInRule::operator]); |
|
588 | 588 | if (!in_array($notEqualRule->getValue(), $notInRule->getPossibilities())) { |
589 | 589 | // TODO Replace it by a FalseRule |
590 | - $operandsByFields[ $field ][ NotInRule::operator ][0]->setPossibilities( |
|
590 | + $operandsByFields[$field][NotInRule::operator][0]->setPossibilities( |
|
591 | 591 | array_merge($notInRule->getPossibilities(), [$notEqualRule->getValue()]) |
592 | 592 | ); |
593 | 593 | } |
594 | 594 | |
595 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
595 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
596 | 596 | } |
597 | 597 | |
598 | - if (!empty($operandsByOperator[ InRule::operator ])) { |
|
599 | - $inRule = reset($operandsByOperator[ InRule::operator ]); |
|
598 | + if (!empty($operandsByOperator[InRule::operator])) { |
|
599 | + $inRule = reset($operandsByOperator[InRule::operator]); |
|
600 | 600 | |
601 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
601 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
602 | 602 | array_diff($inRule->getPossibilities(), [$notEqualRule->getValue()]) |
603 | 603 | ); |
604 | 604 | } |
@@ -608,61 +608,61 @@ discard block |
||
608 | 608 | |
609 | 609 | // Comparison between InRules and NotInRules |
610 | 610 | // This is an optimization to avoid NotIn explosion |
611 | - if (!empty($operandsByOperator[ InRule::operator ])) { |
|
612 | - $inRule = $operandsByOperator[ InRule::operator ][0]; |
|
611 | + if (!empty($operandsByOperator[InRule::operator])) { |
|
612 | + $inRule = $operandsByOperator[InRule::operator][0]; |
|
613 | 613 | |
614 | - if (!empty($operandsByOperator[ NotInRule::operator ])) { |
|
615 | - $notInRule = reset($operandsByOperator[ NotInRule::operator ]); |
|
616 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
617 | - array_diff( $inRule->getPossibilities(), $notInRule->getPossibilities()) |
|
614 | + if (!empty($operandsByOperator[NotInRule::operator])) { |
|
615 | + $notInRule = reset($operandsByOperator[NotInRule::operator]); |
|
616 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
617 | + array_diff($inRule->getPossibilities(), $notInRule->getPossibilities()) |
|
618 | 618 | ); |
619 | - unset($operandsByOperator[ NotInRule::operator ]); |
|
619 | + unset($operandsByOperator[NotInRule::operator]); |
|
620 | 620 | } |
621 | 621 | |
622 | - if (!empty($operandsByOperator[ BelowRule::operator ])) { |
|
623 | - $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getMaximum(); |
|
622 | + if (!empty($operandsByOperator[BelowRule::operator])) { |
|
623 | + $upper_limit = reset($operandsByOperator[BelowRule::operator])->getMaximum(); |
|
624 | 624 | |
625 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
626 | - array_filter( $inRule->getPossibilities(), function ($possibility) use ($upper_limit) { |
|
625 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
626 | + array_filter($inRule->getPossibilities(), function($possibility) use ($upper_limit) { |
|
627 | 627 | return $possibility < $upper_limit; |
628 | 628 | } ) |
629 | 629 | ); |
630 | 630 | |
631 | - unset($operandsByOperator[ BelowRule::operator ]); |
|
631 | + unset($operandsByOperator[BelowRule::operator]); |
|
632 | 632 | } |
633 | 633 | |
634 | - if (!empty($operandsByOperator[ AboveRule::operator ])) { |
|
635 | - $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getMinimum(); |
|
634 | + if (!empty($operandsByOperator[AboveRule::operator])) { |
|
635 | + $lower_limit = reset($operandsByOperator[AboveRule::operator])->getMinimum(); |
|
636 | 636 | |
637 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
638 | - array_filter( $inRule->getPossibilities(), function ($possibility) use ($lower_limit) { |
|
637 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
638 | + array_filter($inRule->getPossibilities(), function($possibility) use ($lower_limit) { |
|
639 | 639 | return $possibility > $lower_limit; |
640 | 640 | } ) |
641 | 641 | ); |
642 | 642 | |
643 | - unset($operandsByOperator[ AboveRule::operator ]); |
|
643 | + unset($operandsByOperator[AboveRule::operator]); |
|
644 | 644 | } |
645 | 645 | } |
646 | 646 | |
647 | 647 | // Comparison between NotInRules and > or < |
648 | - if (!empty($operandsByOperator[ NotInRule::operator ])) { |
|
649 | - $notInRule = $operandsByOperator[ NotInRule::operator ][0]; |
|
648 | + if (!empty($operandsByOperator[NotInRule::operator])) { |
|
649 | + $notInRule = $operandsByOperator[NotInRule::operator][0]; |
|
650 | 650 | |
651 | - if (!empty($operandsByOperator[ BelowRule::operator ])) { |
|
652 | - $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getMaximum(); |
|
651 | + if (!empty($operandsByOperator[BelowRule::operator])) { |
|
652 | + $upper_limit = reset($operandsByOperator[BelowRule::operator])->getMaximum(); |
|
653 | 653 | |
654 | - $operandsByOperator[ NotInRule::operator ][0]->setPossibilities( |
|
655 | - array_filter( $notInRule->getPossibilities(), function ($possibility) use ($upper_limit) { |
|
654 | + $operandsByOperator[NotInRule::operator][0]->setPossibilities( |
|
655 | + array_filter($notInRule->getPossibilities(), function($possibility) use ($upper_limit) { |
|
656 | 656 | return $possibility < $upper_limit; |
657 | 657 | } ) |
658 | 658 | ); |
659 | 659 | } |
660 | 660 | |
661 | - if (!empty($operandsByOperator[ AboveRule::operator ])) { |
|
662 | - $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getMinimum(); |
|
661 | + if (!empty($operandsByOperator[AboveRule::operator])) { |
|
662 | + $lower_limit = reset($operandsByOperator[AboveRule::operator])->getMinimum(); |
|
663 | 663 | |
664 | - $operandsByOperator[ NotInRule::operator ][0]->setPossibilities( |
|
665 | - array_filter( $notInRule->getPossibilities(), function ($possibility) use ($lower_limit) { |
|
664 | + $operandsByOperator[NotInRule::operator][0]->setPossibilities( |
|
665 | + array_filter($notInRule->getPossibilities(), function($possibility) use ($lower_limit) { |
|
666 | 666 | return $possibility > $lower_limit; |
667 | 667 | } ) |
668 | 668 | ); |
@@ -682,10 +682,10 @@ discard block |
||
682 | 682 | public function setOperandsOrReplaceByOperation($new_operands) |
683 | 683 | { |
684 | 684 | try { |
685 | - return $this->setOperands( $new_operands ); |
|
685 | + return $this->setOperands($new_operands); |
|
686 | 686 | } |
687 | 687 | catch (\LogicException $e) { |
688 | - return new AndRule( $new_operands ); |
|
688 | + return new AndRule($new_operands); |
|
689 | 689 | } |
690 | 690 | } |
691 | 691 |