@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | continue; |
25 | 25 | } |
26 | 26 | |
27 | - if ( ! $operand->isNormalizationAllowed($simplification_options) ) { |
|
27 | + if ( ! $operand->isNormalizationAllowed($simplification_options)) { |
|
28 | 28 | continue; |
29 | 29 | } |
30 | 30 | |
31 | 31 | // Id AND is an operand on AND they can be merge (and the same with OR) |
32 | 32 | foreach ($operand->getOperands() as $sub_operand) { |
33 | - $this->addOperand( $sub_operand->copy() ); |
|
33 | + $this->addOperand($sub_operand->copy()); |
|
34 | 34 | } |
35 | 35 | unset($this->operands[$i]); |
36 | 36 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | return $this->copy(); |
55 | 55 | } |
56 | 56 | |
57 | - $this->moveSimplificationStepForward( self::rootify_disjunctions, $simplification_options ); |
|
57 | + $this->moveSimplificationStepForward(self::rootify_disjunctions, $simplification_options); |
|
58 | 58 | |
59 | 59 | $upLiftedOperands = []; |
60 | 60 | foreach ($this->getOperands() as $operand) { |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return array |
83 | 83 | */ |
84 | - public function toArray(array $options=[]) |
|
84 | + public function toArray(array $options = []) |
|
85 | 85 | { |
86 | 86 | $default_options = [ |
87 | 87 | 'show_instance' => false, |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | 'semantic' => false, |
90 | 90 | ]; |
91 | 91 | foreach ($default_options as $default_option => &$default_value) { |
92 | - if ( ! isset($options[ $default_option ])) { |
|
93 | - $options[ $default_option ] = $default_value; |
|
92 | + if ( ! isset($options[$default_option])) { |
|
93 | + $options[$default_option] = $default_value; |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | |
130 | 130 | /** |
131 | 131 | */ |
132 | - public function toString(array $options=[]) |
|
132 | + public function toString(array $options = []) |
|
133 | 133 | { |
134 | 134 | $operator = self::operator; |
135 | 135 | if ( ! $this->operands) { |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | foreach ($this->operands as $operand) { |
145 | 145 | $out .= implode("\n", array_map(function($line) use (&$indent_unit) { |
146 | 146 | return $indent_unit.$line; |
147 | - }, explode("\n", $operand->toString($options)) )) . ",$line_break"; |
|
147 | + }, explode("\n", $operand->toString($options)))).",$line_break"; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | $out .= ']'; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | |
166 | 166 | try { |
167 | 167 | if (AboveRule::operator == $operator) { |
168 | - usort($operands, function( AboveRule $a, AboveRule $b ) { |
|
168 | + usort($operands, function(AboveRule $a, AboveRule $b) { |
|
169 | 169 | if (null === $a->getMinimum()) { |
170 | 170 | return 1; |
171 | 171 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $operands = [reset($operands)]; |
184 | 184 | } |
185 | 185 | elseif (BelowRule::operator == $operator) { |
186 | - usort($operands, function( BelowRule $a, BelowRule $b ) { |
|
186 | + usort($operands, function(BelowRule $a, BelowRule $b) { |
|
187 | 187 | if (null === $a->getMaximum()) { |
188 | 188 | return 1; |
189 | 189 | } |
@@ -208,17 +208,17 @@ discard block |
||
208 | 208 | continue; |
209 | 209 | } |
210 | 210 | |
211 | - $first_in->setPossibilities( array_merge( |
|
211 | + $first_in->setPossibilities(array_merge( |
|
212 | 212 | $first_in->getPossibilities(), |
213 | 213 | $next_in->getPossibilities() |
214 | - ) ); |
|
214 | + )); |
|
215 | 215 | |
216 | 216 | unset($operands[$i]); |
217 | 217 | } |
218 | 218 | } |
219 | 219 | } |
220 | 220 | catch (\Exception $e) { |
221 | - VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage() . "\n" . var_export([ |
|
221 | + VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage()."\n".var_export([ |
|
222 | 222 | 'operands' => $operands, |
223 | 223 | ], true) |
224 | 224 | ); |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | throw $e; |
228 | 228 | } |
229 | 229 | |
230 | - $operandsByFields[ $field ][ $operator ] = $operands; |
|
230 | + $operandsByFields[$field][$operator] = $operands; |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
@@ -272,14 +272,14 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return bool If the rule can have a solution or not |
274 | 274 | */ |
275 | - public function hasSolution(array $simplification_options=[]) |
|
275 | + public function hasSolution(array $simplification_options = []) |
|
276 | 276 | { |
277 | 277 | if ( ! $this->isNormalizationAllowed($simplification_options)) { |
278 | 278 | return true; |
279 | 279 | } |
280 | 280 | |
281 | 281 | $operands = $this->getOperands(); |
282 | - if ( (count($operands) == 1 && ! reset($operands)->hasSolution()) // skip simplification case after call of addMinimalCase() (which seems to have unwanted side effect) |
|
282 | + if ((count($operands) == 1 && ! reset($operands)->hasSolution()) // skip simplification case after call of addMinimalCase() (which seems to have unwanted side effect) |
|
283 | 283 | && ! $this->simplicationStepReached(self::simplified)) { |
284 | 284 | throw new \LogicException( |
285 | 285 | "hasSolution has no sens if the rule is not simplified instead of being at: " |
@@ -301,10 +301,10 @@ discard block |
||
301 | 301 | public function setOperandsOrReplaceByOperation($new_operands) |
302 | 302 | { |
303 | 303 | try { |
304 | - return $this->setOperands( $new_operands ); |
|
304 | + return $this->setOperands($new_operands); |
|
305 | 305 | } |
306 | 306 | catch (\LogicException $e) { |
307 | - return new OrRule( $new_operands ); |
|
307 | + return new OrRule($new_operands); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | |
59 | 59 | foreach ($upLiftedOperands as $i => $operand) { |
60 | 60 | if ($operand instanceof NotRule) { |
61 | - if ( ($operand instanceof NotEqualRule || $operand instanceof NotInRule) |
|
61 | + if (($operand instanceof NotEqualRule || $operand instanceof NotInRule) |
|
62 | 62 | && ! $operand->isNormalizationAllowed($simplification_options) |
63 | 63 | ) { |
64 | 64 | foreach ($upLiftedOr->getOperands() as $upLifdtedOperand) { |
65 | - $upLifdtedOperand->addOperand( $operand->copy() ); |
|
65 | + $upLifdtedOperand->addOperand($operand->copy()); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | else { |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | foreach ($operand->getOperands() as $subOperand) { |
85 | 85 | foreach ($upLiftedOr->getOperands() as $upLiftedOrSubOperand) { |
86 | 86 | $newUpLiftedOrSubOperand = $upLiftedOrSubOperand->copy(); |
87 | - $newUpLiftedOrSubOperand->addOperand( $subOperand->copy() ); |
|
87 | + $newUpLiftedOrSubOperand->addOperand($subOperand->copy()); |
|
88 | 88 | if ($newUpLiftedOrSubOperand->simplify($simplification_options)->hasSolution($simplification_options)) { |
89 | - $newUpLiftedOr->addOperand( $newUpLiftedOrSubOperand ); |
|
89 | + $newUpLiftedOr->addOperand($newUpLiftedOrSubOperand); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | ); |
104 | 104 | } |
105 | 105 | |
106 | - $upLifdtedOperand->addOperand( $operand->copy() ); |
|
106 | + $upLifdtedOperand->addOperand($operand->copy()); |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @todo same as OrRule |
120 | 120 | */ |
121 | - public function toArray(array $options=[]) |
|
121 | + public function toArray(array $options = []) |
|
122 | 122 | { |
123 | 123 | $default_options = [ |
124 | 124 | 'show_instance' => false, |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | 'semantic' => false, |
127 | 127 | ]; |
128 | 128 | foreach ($default_options as $default_option => &$default_value) { |
129 | - if ( ! isset($options[ $default_option ])) { |
|
130 | - $options[ $default_option ] = $default_value; |
|
129 | + if ( ! isset($options[$default_option])) { |
|
130 | + $options[$default_option] = $default_value; |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @param array $options indent_unit |
171 | 171 | * @return string The rule description |
172 | 172 | */ |
173 | - public function toString(array $options=[]) |
|
173 | + public function toString(array $options = []) |
|
174 | 174 | { |
175 | 175 | $operator = self::operator; |
176 | 176 | if ( ! $this->operands) { |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | foreach ($this->operands as $operand) { |
186 | 186 | $out .= implode("\n", array_map(function($line) use (&$indent_unit) { |
187 | 187 | return $indent_unit.$line; |
188 | - }, explode("\n", $operand->toString($options)) )) . ",$line_break"; |
|
188 | + }, explode("\n", $operand->toString($options)))).",$line_break"; |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | $out .= ']'; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | |
210 | 210 | // Id AND is an operand on AND they can be merge (and the same with OR) |
211 | 211 | foreach ($operands as $sub_operand) { |
212 | - $this->addOperand( $sub_operand->copy() ); |
|
212 | + $this->addOperand($sub_operand->copy()); |
|
213 | 213 | } |
214 | 214 | unset($this->operands[$i]); |
215 | 215 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | foreach ($this->operands as $i => $operand) { |
239 | 239 | // if ($operand instanceof AndRule || $operand instanceof OrRule ) { |
240 | - if ( in_array( get_class($operand), [AndRule::class, OrRule::class]) ) { |
|
240 | + if (in_array(get_class($operand), [AndRule::class, OrRule::class])) { |
|
241 | 241 | $this->operands[$i] = $operand->removeInvalidBranches($simplification_options); |
242 | 242 | if ( ! $this->operands[$i]->hasSolution()) { |
243 | 243 | $this->operands = []; |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | // $this->dump(true); |
252 | 252 | |
253 | 253 | foreach ($operandsByFields as $field => $operandsByOperator) { |
254 | - if ( ! empty($operandsByOperator[ EqualRule::operator ])) { |
|
255 | - foreach ($operandsByOperator[ EqualRule::operator ] as $equalRule) { |
|
254 | + if ( ! empty($operandsByOperator[EqualRule::operator])) { |
|
255 | + foreach ($operandsByOperator[EqualRule::operator] as $equalRule) { |
|
256 | 256 | // Multiple equal rules without the same value is invalid |
257 | 257 | if (isset($previousEqualRule) && $previousEqualRule->getValue() != $equalRule->getValue()) { |
258 | 258 | $this->operands = []; |
@@ -262,55 +262,55 @@ discard block |
||
262 | 262 | } |
263 | 263 | unset($previousEqualRule); |
264 | 264 | |
265 | - $equalRule = reset($operandsByOperator[ EqualRule::operator ]); |
|
265 | + $equalRule = reset($operandsByOperator[EqualRule::operator]); |
|
266 | 266 | |
267 | - if ( ! empty($operandsByOperator[ BelowRule::operator ]) |
|
267 | + if ( ! empty($operandsByOperator[BelowRule::operator]) |
|
268 | 268 | && null === $equalRule->getValue() |
269 | 269 | ) { |
270 | 270 | $this->operands = []; |
271 | 271 | return $this; |
272 | 272 | } |
273 | 273 | |
274 | - if ( ! empty($operandsByOperator[ BelowRule::operator ]) |
|
275 | - && $equalRule->getValue() >= reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit() |
|
274 | + if ( ! empty($operandsByOperator[BelowRule::operator]) |
|
275 | + && $equalRule->getValue() >= reset($operandsByOperator[BelowRule::operator])->getUpperLimit() |
|
276 | 276 | ) { |
277 | 277 | $this->operands = []; |
278 | 278 | return $this; |
279 | 279 | } |
280 | 280 | |
281 | - if ( ! empty($operandsByOperator[ AboveRule::operator ]) |
|
281 | + if ( ! empty($operandsByOperator[AboveRule::operator]) |
|
282 | 282 | && null === $equalRule->getValue() |
283 | 283 | ) { |
284 | 284 | $this->operands = []; |
285 | 285 | return $this; |
286 | 286 | } |
287 | 287 | |
288 | - if ( ! empty($operandsByOperator[ AboveRule::operator ]) |
|
289 | - && $equalRule->getValue() <= reset($operandsByOperator[ AboveRule::operator ])->getLowerLimit() |
|
288 | + if ( ! empty($operandsByOperator[AboveRule::operator]) |
|
289 | + && $equalRule->getValue() <= reset($operandsByOperator[AboveRule::operator])->getLowerLimit() |
|
290 | 290 | ) { |
291 | 291 | $this->operands = []; |
292 | 292 | return $this; |
293 | 293 | } |
294 | 294 | |
295 | - if ( ! empty($operandsByOperator[ NotEqualRule::operator ]) |
|
296 | - && $equalRule->getValue() == reset($operandsByOperator[ NotEqualRule::operator ])->getValue() |
|
295 | + if ( ! empty($operandsByOperator[NotEqualRule::operator]) |
|
296 | + && $equalRule->getValue() == reset($operandsByOperator[NotEqualRule::operator])->getValue() |
|
297 | 297 | ) { |
298 | 298 | $this->operands = []; |
299 | 299 | return $this; |
300 | 300 | } |
301 | 301 | |
302 | - if ( ! empty($operandsByOperator[ NotEqualRule::operator ]) |
|
302 | + if ( ! empty($operandsByOperator[NotEqualRule::operator]) |
|
303 | 303 | && null === $equalRule->getValue() |
304 | - && null === reset($operandsByOperator[ NotEqualRule::operator ])->getValue() |
|
304 | + && null === reset($operandsByOperator[NotEqualRule::operator])->getValue() |
|
305 | 305 | ) { |
306 | 306 | $this->operands = []; |
307 | 307 | return $this; |
308 | 308 | } |
309 | 309 | } |
310 | - elseif ( ! empty($operandsByOperator[ BelowRule::operator ]) |
|
311 | - && ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
312 | - $aboveRule = reset($operandsByOperator[ AboveRule::operator ]); |
|
313 | - $belowRule = reset($operandsByOperator[ BelowRule::operator ]); |
|
310 | + elseif ( ! empty($operandsByOperator[BelowRule::operator]) |
|
311 | + && ! empty($operandsByOperator[AboveRule::operator])) { |
|
312 | + $aboveRule = reset($operandsByOperator[AboveRule::operator]); |
|
313 | + $belowRule = reset($operandsByOperator[BelowRule::operator]); |
|
314 | 314 | |
315 | 315 | if ($belowRule->getUpperLimit() <= $aboveRule->getLowerLimit()) { |
316 | 316 | $this->operands = []; |
@@ -332,10 +332,10 @@ discard block |
||
332 | 332 | * simplification |
333 | 333 | * @return bool If the AndRule can have a solution or not |
334 | 334 | */ |
335 | - public function hasSolution(array $contextual_options=[]) |
|
335 | + public function hasSolution(array $contextual_options = []) |
|
336 | 336 | { |
337 | 337 | $operands = $this->getOperands(); |
338 | - if ( (count($operands) == 1 && ! reset($operands)->hasSolution()) // skip simplification case after call of addMinimalCase() (which seems to have unwanted side effect) |
|
338 | + if ((count($operands) == 1 && ! reset($operands)->hasSolution()) // skip simplification case after call of addMinimalCase() (which seems to have unwanted side effect) |
|
339 | 339 | && ! $this->simplicationStepReached(self::simplified)) { |
340 | 340 | throw new \LogicException( |
341 | 341 | "hasSolution has no sens if the rule is not simplified instead of being at: " |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | |
370 | 370 | try { |
371 | 371 | if (AboveRule::operator == $operator) { |
372 | - usort($operands, function( AboveRule $a, AboveRule $b ) { |
|
372 | + usort($operands, function(AboveRule $a, AboveRule $b) { |
|
373 | 373 | if (null === $a->getLowerLimit()) { |
374 | 374 | return 1; |
375 | 375 | } |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $operands = [reset($operands)]; |
388 | 388 | } |
389 | 389 | elseif (BelowRule::operator == $operator) { |
390 | - usort($operands, function( BelowRule $a, BelowRule $b ) { |
|
390 | + usort($operands, function(BelowRule $a, BelowRule $b) { |
|
391 | 391 | if (null === $a->getUpperLimit()) { |
392 | 392 | return 1; |
393 | 393 | } |
@@ -433,10 +433,10 @@ discard block |
||
433 | 433 | continue; |
434 | 434 | } |
435 | 435 | |
436 | - $first_in->setPossibilities( array_intersect( |
|
436 | + $first_in->setPossibilities(array_intersect( |
|
437 | 437 | $first_in->getPossibilities(), |
438 | 438 | $next_in->getPossibilities() |
439 | - ) ); |
|
439 | + )); |
|
440 | 440 | |
441 | 441 | unset($operands[$i]); |
442 | 442 | } |
@@ -454,17 +454,17 @@ discard block |
||
454 | 454 | continue; |
455 | 455 | } |
456 | 456 | |
457 | - $first_not_in->setPossibilities( array_merge( |
|
457 | + $first_not_in->setPossibilities(array_merge( |
|
458 | 458 | $first_not_in->getPossibilities(), |
459 | 459 | $next_not_in->getPossibilities() |
460 | - ) ); |
|
460 | + )); |
|
461 | 461 | |
462 | 462 | unset($operands[$i]); |
463 | 463 | } |
464 | 464 | } |
465 | 465 | } |
466 | 466 | catch (\Exception $e) { |
467 | - VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage() . "\n" . var_export([ |
|
467 | + VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage()."\n".var_export([ |
|
468 | 468 | 'operands' => $operands, |
469 | 469 | // 'this' => $this, |
470 | 470 | ], true) |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | throw $e; |
475 | 475 | } |
476 | 476 | |
477 | - $operandsByFields[ $field ][ $operator ] = $operands; |
|
477 | + $operandsByFields[$field][$operator] = $operands; |
|
478 | 478 | } |
479 | 479 | } |
480 | 480 | |
@@ -497,14 +497,14 @@ discard block |
||
497 | 497 | ] |
498 | 498 | as $unifyable_operator |
499 | 499 | ) { |
500 | - if ( ! empty($operandsByOperator[ $unifyable_operator ])) { |
|
501 | - if (1 != count($operandsByOperator[ $unifyable_operator ])) { |
|
500 | + if ( ! empty($operandsByOperator[$unifyable_operator])) { |
|
501 | + if (1 != count($operandsByOperator[$unifyable_operator])) { |
|
502 | 502 | throw new \LogicException( |
503 | - __METHOD__ . " MUST be called after unifyAtomicOperands() " |
|
503 | + __METHOD__." MUST be called after unifyAtomicOperands() " |
|
504 | 504 | ."to have only one '$unifyable_operator' predicate istead of:\n" |
505 | - ."[\n".implode( ",\n", array_map(function ($rule) { |
|
505 | + ."[\n".implode(",\n", array_map(function($rule) { |
|
506 | 506 | return $rule->toString(); |
507 | - }, $operandsByOperator[ $unifyable_operator ]) |
|
507 | + }, $operandsByOperator[$unifyable_operator]) |
|
508 | 508 | )."\n]" |
509 | 509 | ); |
510 | 510 | } |
@@ -530,73 +530,73 @@ discard block |
||
530 | 530 | protected static function simplifyDifferentOperandsForField($field, array $operandsByOperator) |
531 | 531 | { |
532 | 532 | // EqualRule comparisons |
533 | - if ( ! empty($operandsByOperator[ EqualRule::operator ])) { |
|
534 | - $equalRule = reset( $operandsByOperator[ EqualRule::operator ] ); |
|
533 | + if ( ! empty($operandsByOperator[EqualRule::operator])) { |
|
534 | + $equalRule = reset($operandsByOperator[EqualRule::operator]); |
|
535 | 535 | |
536 | - if ( ! empty($operandsByOperator[ NotEqualRule::operator ])) { |
|
537 | - foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $not_equal_rule) { |
|
536 | + if ( ! empty($operandsByOperator[NotEqualRule::operator])) { |
|
537 | + foreach ($operandsByOperator[NotEqualRule::operator] as $i => $not_equal_rule) { |
|
538 | 538 | if (null !== $equalRule->getValue()) { |
539 | 539 | if (null === $not_equal_rule->getValue()) { // means if exists <=> equals something |
540 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
540 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
541 | 541 | } |
542 | 542 | elseif ($not_equal_rule->getValue() != $equalRule->getValue()) { |
543 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
543 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
544 | 544 | } |
545 | 545 | } |
546 | - elseif (null === $equalRule->getValue() ) { |
|
546 | + elseif (null === $equalRule->getValue()) { |
|
547 | 547 | if (null !== $not_equal_rule->getValue()) { |
548 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
548 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
549 | 549 | } |
550 | 550 | // else we let the "equal null" and the "not equal null" for the romeInvalidBranches step |
551 | 551 | } |
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
555 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
556 | - $aboveRule = reset($operandsByOperator[ AboveRule::operator ]); |
|
555 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
556 | + $aboveRule = reset($operandsByOperator[AboveRule::operator]); |
|
557 | 557 | if (null !== $equalRule->getValue() && $aboveRule->getLowerLimit() < $equalRule->getValue()) { |
558 | - unset($operandsByOperator[ AboveRule::operator ]); |
|
558 | + unset($operandsByOperator[AboveRule::operator]); |
|
559 | 559 | } |
560 | 560 | } |
561 | 561 | |
562 | - if ( ! empty($operandsByOperator[ BelowRule::operator ])) { |
|
563 | - $belowRule = reset($operandsByOperator[ BelowRule::operator ]); |
|
562 | + if ( ! empty($operandsByOperator[BelowRule::operator])) { |
|
563 | + $belowRule = reset($operandsByOperator[BelowRule::operator]); |
|
564 | 564 | if (null !== $equalRule->getValue() && $belowRule->getUpperLimit() > $equalRule->getValue()) { |
565 | - unset($operandsByOperator[ BelowRule::operator ]); |
|
565 | + unset($operandsByOperator[BelowRule::operator]); |
|
566 | 566 | } |
567 | 567 | } |
568 | 568 | |
569 | - if ( ! empty($operandsByOperator[ InRule::operator ])) { |
|
570 | - $possibilities = reset($operandsByOperator[ InRule::operator ])->getPossibilities(); |
|
569 | + if ( ! empty($operandsByOperator[InRule::operator])) { |
|
570 | + $possibilities = reset($operandsByOperator[InRule::operator])->getPossibilities(); |
|
571 | 571 | |
572 | 572 | if (in_array($equalRule->getValue(), $possibilities)) { |
573 | - unset($operandsByOperator[ InRule::operator ]); |
|
573 | + unset($operandsByOperator[InRule::operator]); |
|
574 | 574 | } |
575 | 575 | else { |
576 | 576 | // We flush possibilities of the InRule |
577 | 577 | // TODO Replace it by a FalseRule |
578 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities([]); |
|
578 | + $operandsByOperator[InRule::operator][0]->setPossibilities([]); |
|
579 | 579 | // and also remove the equal rule to shorten the reste of the simplification process |
580 | - unset($operandsByOperator[ EqualRule::operator ]); |
|
580 | + unset($operandsByOperator[EqualRule::operator]); |
|
581 | 581 | } |
582 | 582 | } |
583 | 583 | |
584 | - if ( ! empty($operandsByOperator[ NotInRule::operator ])) { |
|
585 | - $notInRule = reset($operandsByOperator[ NotInRule::operator ]); |
|
584 | + if ( ! empty($operandsByOperator[NotInRule::operator])) { |
|
585 | + $notInRule = reset($operandsByOperator[NotInRule::operator]); |
|
586 | 586 | if (in_array($equalRule->getValue(), $notInRule->getPossibilities())) { |
587 | 587 | // ['field', '=', 4] && ['field', '!in', [4]...] <=> false |
588 | 588 | return []; |
589 | 589 | } |
590 | 590 | else { |
591 | - unset($operandsByOperator[ NotInRule::operator ]); |
|
591 | + unset($operandsByOperator[NotInRule::operator]); |
|
592 | 592 | } |
593 | 593 | // $notInRule->dump(true); |
594 | 594 | } |
595 | 595 | |
596 | - if ( ! empty($operandsByOperator[ BelowOrEqualRule::operator ])) { |
|
597 | - $belowOrEqualRule = reset($operandsByOperator[ BelowOrEqualRule::operator ]); |
|
596 | + if ( ! empty($operandsByOperator[BelowOrEqualRule::operator])) { |
|
597 | + $belowOrEqualRule = reset($operandsByOperator[BelowOrEqualRule::operator]); |
|
598 | 598 | if ($equalRule->getValue() <= $belowOrEqualRule->getMaximum()) { |
599 | - unset($operandsByOperator[ BelowOrEqualRule::operator ]); |
|
599 | + unset($operandsByOperator[BelowOrEqualRule::operator]); |
|
600 | 600 | } |
601 | 601 | else { |
602 | 602 | // ['field', '=', 4] && ['field', '<=', [3]...] <=> false |
@@ -604,10 +604,10 @@ discard block |
||
604 | 604 | } |
605 | 605 | } |
606 | 606 | |
607 | - if ( ! empty($operandsByOperator[ AboveOrEqualRule::operator ])) { |
|
608 | - $aboveOrEqualRule = reset($operandsByOperator[ AboveOrEqualRule::operator ]); |
|
607 | + if ( ! empty($operandsByOperator[AboveOrEqualRule::operator])) { |
|
608 | + $aboveOrEqualRule = reset($operandsByOperator[AboveOrEqualRule::operator]); |
|
609 | 609 | if ($equalRule->getValue() >= $aboveOrEqualRule->getMinimum()) { |
610 | - unset($operandsByOperator[ AboveOrEqualRule::operator ]); |
|
610 | + unset($operandsByOperator[AboveOrEqualRule::operator]); |
|
611 | 611 | } |
612 | 612 | else { |
613 | 613 | // ['field', '=', 4] && ['field', '<=', [3]...] <=> false |
@@ -617,54 +617,54 @@ discard block |
||
617 | 617 | } |
618 | 618 | |
619 | 619 | // NotEqualRule null comparisons |
620 | - if ( ! empty($operandsByOperator[ NotEqualRule::operator ])) { |
|
621 | - if ( ! empty($operandsByOperator[ NotEqualRule::operator ])) { |
|
622 | - foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $notEqualRule) { |
|
620 | + if ( ! empty($operandsByOperator[NotEqualRule::operator])) { |
|
621 | + if ( ! empty($operandsByOperator[NotEqualRule::operator])) { |
|
622 | + foreach ($operandsByOperator[NotEqualRule::operator] as $i => $notEqualRule) { |
|
623 | 623 | if (null === $notEqualRule->getValue()) { |
624 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
625 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
624 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
625 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
626 | 626 | } |
627 | 627 | |
628 | - if ( ! empty($operandsByOperator[ BelowRule::operator ])) { |
|
629 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
628 | + if ( ! empty($operandsByOperator[BelowRule::operator])) { |
|
629 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
630 | 630 | } |
631 | 631 | |
632 | - if ( ! empty($operandsByOperator[ EqualRule::operator ])) { |
|
633 | - if (null !== reset($operandsByOperator[ EqualRule::operator ])->getValue()) { |
|
634 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
632 | + if ( ! empty($operandsByOperator[EqualRule::operator])) { |
|
633 | + if (null !== reset($operandsByOperator[EqualRule::operator])->getValue()) { |
|
634 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
635 | 635 | } |
636 | 636 | } |
637 | 637 | } |
638 | 638 | else { |
639 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
640 | - if ($operandsByOperator[ AboveRule::operator ][0]->getLowerLimit() >= $notEqualRule->getValue()) { |
|
641 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
639 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
640 | + if ($operandsByOperator[AboveRule::operator][0]->getLowerLimit() >= $notEqualRule->getValue()) { |
|
641 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
642 | 642 | } |
643 | 643 | } |
644 | 644 | |
645 | - if ( ! empty($operandsByOperator[ BelowRule::operator ])) { |
|
646 | - if ($operandsByOperator[ BelowRule::operator ][0]->getUpperLimit() <= $notEqualRule->getValue()) { |
|
647 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
645 | + if ( ! empty($operandsByOperator[BelowRule::operator])) { |
|
646 | + if ($operandsByOperator[BelowRule::operator][0]->getUpperLimit() <= $notEqualRule->getValue()) { |
|
647 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
648 | 648 | } |
649 | 649 | } |
650 | 650 | } |
651 | 651 | |
652 | - if ( ! empty($operandsByOperator[ NotInRule::operator ])) { |
|
653 | - $notInRule = reset($operandsByOperator[ NotInRule::operator ]); |
|
652 | + if ( ! empty($operandsByOperator[NotInRule::operator])) { |
|
653 | + $notInRule = reset($operandsByOperator[NotInRule::operator]); |
|
654 | 654 | if ( ! in_array($notEqualRule->getValue(), $notInRule->getPossibilities())) { |
655 | 655 | // TODO Replace it by a FalseRule |
656 | - $operandsByOperator[ NotInRule::operator ][0]->setPossibilities( |
|
656 | + $operandsByOperator[NotInRule::operator][0]->setPossibilities( |
|
657 | 657 | array_merge($notInRule->getPossibilities(), [$notEqualRule->getValue()]) |
658 | 658 | ); |
659 | 659 | } |
660 | 660 | |
661 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
661 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
662 | 662 | } |
663 | 663 | |
664 | - if ( ! empty($operandsByOperator[ InRule::operator ])) { |
|
665 | - $inRule = reset($operandsByOperator[ InRule::operator ]); |
|
664 | + if ( ! empty($operandsByOperator[InRule::operator])) { |
|
665 | + $inRule = reset($operandsByOperator[InRule::operator]); |
|
666 | 666 | |
667 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
667 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
668 | 668 | array_diff($inRule->getPossibilities(), [$notEqualRule->getValue()]) |
669 | 669 | ); |
670 | 670 | } |
@@ -674,61 +674,61 @@ discard block |
||
674 | 674 | |
675 | 675 | // Comparison between InRules and NotInRules |
676 | 676 | // This is an optimization to avoid NotIn explosion |
677 | - if ( ! empty($operandsByOperator[ InRule::operator ])) { |
|
678 | - $inRule = $operandsByOperator[ InRule::operator ][0]; |
|
677 | + if ( ! empty($operandsByOperator[InRule::operator])) { |
|
678 | + $inRule = $operandsByOperator[InRule::operator][0]; |
|
679 | 679 | |
680 | - if ( ! empty($operandsByOperator[ NotInRule::operator ])) { |
|
681 | - $notInRule = reset($operandsByOperator[ NotInRule::operator ]); |
|
682 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
683 | - array_diff( $inRule->getPossibilities(), $notInRule->getPossibilities()) |
|
680 | + if ( ! empty($operandsByOperator[NotInRule::operator])) { |
|
681 | + $notInRule = reset($operandsByOperator[NotInRule::operator]); |
|
682 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
683 | + array_diff($inRule->getPossibilities(), $notInRule->getPossibilities()) |
|
684 | 684 | ); |
685 | - unset($operandsByOperator[ NotInRule::operator ]); |
|
685 | + unset($operandsByOperator[NotInRule::operator]); |
|
686 | 686 | } |
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 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
692 | - array_filter( $inRule->getPossibilities(), function ($possibility) use ($upper_limit) { |
|
691 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
692 | + array_filter($inRule->getPossibilities(), function($possibility) use ($upper_limit) { |
|
693 | 693 | return $possibility < $upper_limit; |
694 | 694 | } ) |
695 | 695 | ); |
696 | 696 | |
697 | - unset($operandsByOperator[ BelowRule::operator ]); |
|
697 | + unset($operandsByOperator[BelowRule::operator]); |
|
698 | 698 | } |
699 | 699 | |
700 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
701 | - $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getLowerLimit(); |
|
700 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
701 | + $lower_limit = reset($operandsByOperator[AboveRule::operator])->getLowerLimit(); |
|
702 | 702 | |
703 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
704 | - array_filter( $inRule->getPossibilities(), function ($possibility) use ($lower_limit) { |
|
703 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
704 | + array_filter($inRule->getPossibilities(), function($possibility) use ($lower_limit) { |
|
705 | 705 | return $possibility > $lower_limit; |
706 | 706 | } ) |
707 | 707 | ); |
708 | 708 | |
709 | - unset($operandsByOperator[ AboveRule::operator ]); |
|
709 | + unset($operandsByOperator[AboveRule::operator]); |
|
710 | 710 | } |
711 | 711 | } |
712 | 712 | |
713 | 713 | // Comparison between NotInRules and > or < |
714 | - if ( ! empty($operandsByOperator[ NotInRule::operator ])) { |
|
715 | - $notInRule = $operandsByOperator[ NotInRule::operator ][0]; |
|
714 | + if ( ! empty($operandsByOperator[NotInRule::operator])) { |
|
715 | + $notInRule = $operandsByOperator[NotInRule::operator][0]; |
|
716 | 716 | |
717 | - if ( ! empty($operandsByOperator[ BelowRule::operator ])) { |
|
718 | - $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit(); |
|
717 | + if ( ! empty($operandsByOperator[BelowRule::operator])) { |
|
718 | + $upper_limit = reset($operandsByOperator[BelowRule::operator])->getUpperLimit(); |
|
719 | 719 | |
720 | - $operandsByOperator[ NotInRule::operator ][0]->setPossibilities( |
|
721 | - array_filter( $notInRule->getPossibilities(), function ($possibility) use ($upper_limit) { |
|
720 | + $operandsByOperator[NotInRule::operator][0]->setPossibilities( |
|
721 | + array_filter($notInRule->getPossibilities(), function($possibility) use ($upper_limit) { |
|
722 | 722 | return $possibility < $upper_limit; |
723 | 723 | } ) |
724 | 724 | ); |
725 | 725 | } |
726 | 726 | |
727 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
728 | - $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getLowerLimit(); |
|
727 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
728 | + $lower_limit = reset($operandsByOperator[AboveRule::operator])->getLowerLimit(); |
|
729 | 729 | |
730 | - $operandsByOperator[ NotInRule::operator ][0]->setPossibilities( |
|
731 | - array_filter( $notInRule->getPossibilities(), function ($possibility) use ($lower_limit) { |
|
730 | + $operandsByOperator[NotInRule::operator][0]->setPossibilities( |
|
731 | + array_filter($notInRule->getPossibilities(), function($possibility) use ($lower_limit) { |
|
732 | 732 | return $possibility > $lower_limit; |
733 | 733 | } ) |
734 | 734 | ); |
@@ -736,25 +736,25 @@ discard block |
||
736 | 736 | } |
737 | 737 | |
738 | 738 | // Comparison between <= and > or < |
739 | - if ( ! empty($operandsByOperator[ BelowOrEqualRule::operator ])) { |
|
740 | - $belowOrEqualRule = $operandsByOperator[ BelowOrEqualRule::operator ][0]; |
|
739 | + if ( ! empty($operandsByOperator[BelowOrEqualRule::operator])) { |
|
740 | + $belowOrEqualRule = $operandsByOperator[BelowOrEqualRule::operator][0]; |
|
741 | 741 | |
742 | - if ( ! empty($operandsByOperator[ BelowRule::operator ])) { |
|
743 | - $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit(); |
|
742 | + if ( ! empty($operandsByOperator[BelowRule::operator])) { |
|
743 | + $upper_limit = reset($operandsByOperator[BelowRule::operator])->getUpperLimit(); |
|
744 | 744 | |
745 | 745 | if ($belowOrEqualRule->getMaximum() >= $upper_limit) { |
746 | 746 | // [field < 3] && [field <= 3] |
747 | 747 | // [field < 3] && [field <= 4] |
748 | - unset($operandsByOperator[ BelowOrEqualRule::operator ][0]); |
|
748 | + unset($operandsByOperator[BelowOrEqualRule::operator][0]); |
|
749 | 749 | } |
750 | 750 | else { |
751 | 751 | // [field < 3] && [field <= 2] |
752 | - unset($operandsByOperator[ BelowRule::operator ][0]); |
|
752 | + unset($operandsByOperator[BelowRule::operator][0]); |
|
753 | 753 | } |
754 | 754 | } |
755 | 755 | |
756 | - if ( ! empty($operandsByOperator[ AboveRule::operator ])) { |
|
757 | - $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getLowerLimit(); |
|
756 | + if ( ! empty($operandsByOperator[AboveRule::operator])) { |
|
757 | + $lower_limit = reset($operandsByOperator[AboveRule::operator])->getLowerLimit(); |
|
758 | 758 | |
759 | 759 | if ($belowOrEqualRule->getMaximum() <= $lower_limit) { |
760 | 760 | // [field > 3] && [field <= 2] <=> false |
@@ -762,8 +762,8 @@ discard block |
||
762 | 762 | } |
763 | 763 | } |
764 | 764 | |
765 | - if ( ! empty($operandsByOperator[ AboveOrEqualRule::operator ])) { |
|
766 | - $minimum = reset($operandsByOperator[ AboveOrEqualRule::operator ])->getMinimum(); |
|
765 | + if ( ! empty($operandsByOperator[AboveOrEqualRule::operator])) { |
|
766 | + $minimum = reset($operandsByOperator[AboveOrEqualRule::operator])->getMinimum(); |
|
767 | 767 | |
768 | 768 | if ($belowOrEqualRule->getMaximum() < $minimum) { |
769 | 769 | // [field <= 3] && [field >= 4] <=> false |
@@ -771,11 +771,11 @@ discard block |
||
771 | 771 | } |
772 | 772 | elseif ($belowOrEqualRule->getMaximum() == $minimum) { |
773 | 773 | // [field <= 3] && [field >= 3] <=> [field = 3] |
774 | - unset($operandsByOperator[ BelowOrEqualRule::operator ]); |
|
775 | - unset($operandsByOperator[ AboveOrEqualRule::operator ]); |
|
776 | - $operandsByOperator[ EqualRule::operator ][] = new EqualRule($field, $minimum); |
|
774 | + unset($operandsByOperator[BelowOrEqualRule::operator]); |
|
775 | + unset($operandsByOperator[AboveOrEqualRule::operator]); |
|
776 | + $operandsByOperator[EqualRule::operator][] = new EqualRule($field, $minimum); |
|
777 | 777 | |
778 | - if (count($operandsByOperator[ EqualRule::operator ]) > 1) { |
|
778 | + if (count($operandsByOperator[EqualRule::operator]) > 1) { |
|
779 | 779 | $operandsByOperator = self::simplifyDifferentOperandsForField($field, $operandsByOperator); |
780 | 780 | } |
781 | 781 | } |
@@ -795,10 +795,10 @@ discard block |
||
795 | 795 | public function setOperandsOrReplaceByOperation(array $new_operands) |
796 | 796 | { |
797 | 797 | try { |
798 | - return $this->setOperands( $new_operands ); |
|
798 | + return $this->setOperands($new_operands); |
|
799 | 799 | } |
800 | 800 | catch (\LogicException $e) { |
801 | - return new AndRule( $new_operands ); |
|
801 | + return new AndRule($new_operands); |
|
802 | 802 | } |
803 | 803 | } |
804 | 804 |