@@ -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 | } |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | // If tyhere is no more operands for a given field it means there |
| 487 | 487 | // is no possible solutions for it so all the current and_case |
| 488 | 488 | // is invalidated. |
| 489 | - if (! $operandsByOperator) |
|
| 489 | + if (!$operandsByOperator) |
|
| 490 | 490 | return []; |
| 491 | 491 | } |
| 492 | 492 | |
@@ -500,75 +500,75 @@ discard block |
||
| 500 | 500 | protected static function simplifyDifferentOperandsForField($field, array $operandsByOperator) |
| 501 | 501 | { |
| 502 | 502 | // EqualRule comparisons |
| 503 | - if (!empty($operandsByOperator[ EqualRule::operator ])) { |
|
| 503 | + if (!empty($operandsByOperator[EqualRule::operator])) { |
|
| 504 | 504 | |
| 505 | - $equalRule = reset( $operandsByOperator[ EqualRule::operator ] ); |
|
| 505 | + $equalRule = reset($operandsByOperator[EqualRule::operator]); |
|
| 506 | 506 | |
| 507 | - if (!empty($operandsByOperator[ NotEqualRule::operator ])) { |
|
| 508 | - foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $not_equal_rule) { |
|
| 507 | + if (!empty($operandsByOperator[NotEqualRule::operator])) { |
|
| 508 | + foreach ($operandsByOperator[NotEqualRule::operator] as $i => $not_equal_rule) { |
|
| 509 | 509 | |
| 510 | 510 | if ($equalRule->getValue() !== null) { |
| 511 | 511 | if ($not_equal_rule->getValue() === null) // means if exists <=> equals something |
| 512 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 512 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 513 | 513 | elseif ($not_equal_rule->getValue() != $equalRule->getValue()) |
| 514 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 514 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 515 | 515 | } |
| 516 | - elseif ($equalRule->getValue() === null ) { |
|
| 516 | + elseif ($equalRule->getValue() === null) { |
|
| 517 | 517 | if ($not_equal_rule->getValue() !== null) |
| 518 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 518 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 519 | 519 | // else we let the "equal null" and the "not equal null" for the romeInvalidBranches step |
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | - if (!empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 524 | + if (!empty($operandsByOperator[AboveRule::operator])) { |
|
| 525 | 525 | |
| 526 | - $aboveRule = reset($operandsByOperator[ AboveRule::operator ]); |
|
| 526 | + $aboveRule = reset($operandsByOperator[AboveRule::operator]); |
|
| 527 | 527 | if ($equalRule->getValue() !== null && $aboveRule->getMinimum() < $equalRule->getValue()) |
| 528 | - unset($operandsByOperator[ AboveRule::operator ]); |
|
| 528 | + unset($operandsByOperator[AboveRule::operator]); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - if (!empty($operandsByOperator[ BelowRule::operator ])) { |
|
| 531 | + if (!empty($operandsByOperator[BelowRule::operator])) { |
|
| 532 | 532 | |
| 533 | - $belowRule = reset($operandsByOperator[ BelowRule::operator ]); |
|
| 533 | + $belowRule = reset($operandsByOperator[BelowRule::operator]); |
|
| 534 | 534 | if ($equalRule->getValue() !== null && $belowRule->getMaximum() > $equalRule->getValue()) |
| 535 | - unset($operandsByOperator[ BelowRule::operator ]); |
|
| 535 | + unset($operandsByOperator[BelowRule::operator]); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | - if (!empty($operandsByOperator[ InRule::operator ])) { |
|
| 538 | + if (!empty($operandsByOperator[InRule::operator])) { |
|
| 539 | 539 | |
| 540 | - $possibilities = reset($operandsByOperator[ InRule::operator ])->getPossibilities(); |
|
| 540 | + $possibilities = reset($operandsByOperator[InRule::operator])->getPossibilities(); |
|
| 541 | 541 | |
| 542 | 542 | if (in_array($equalRule->getValue(), $possibilities)) { |
| 543 | - unset($operandsByOperator[ InRule::operator ]); |
|
| 543 | + unset($operandsByOperator[InRule::operator]); |
|
| 544 | 544 | } |
| 545 | 545 | else { |
| 546 | 546 | // We flush possibilities of the InRule |
| 547 | 547 | // TODO Replace it by a FalseRule |
| 548 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities([]); |
|
| 548 | + $operandsByOperator[InRule::operator][0]->setPossibilities([]); |
|
| 549 | 549 | // and also remove the equal rule to shorten the reste of the simplification process |
| 550 | - unset($operandsByOperator[ EqualRule::operator ]); |
|
| 550 | + unset($operandsByOperator[EqualRule::operator]); |
|
| 551 | 551 | } |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - if (!empty($operandsByOperator[ NotInRule::operator ])) { |
|
| 554 | + if (!empty($operandsByOperator[NotInRule::operator])) { |
|
| 555 | 555 | |
| 556 | - $notInRule = reset($operandsByOperator[ NotInRule::operator ]); |
|
| 556 | + $notInRule = reset($operandsByOperator[NotInRule::operator]); |
|
| 557 | 557 | if (in_array($equalRule->getValue(), $notInRule->getPossibilities())) { |
| 558 | 558 | // ['field', '=', 4] && ['field', '!in', [4]...] <=> false |
| 559 | 559 | return []; |
| 560 | 560 | } |
| 561 | 561 | else { |
| 562 | - unset($operandsByOperator[ NotInRule::operator ]); |
|
| 562 | + unset($operandsByOperator[NotInRule::operator]); |
|
| 563 | 563 | } |
| 564 | 564 | // $notInRule->dump(true); |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - if (!empty($operandsByOperator[ BelowOrEqualRule::operator ])) { |
|
| 567 | + if (!empty($operandsByOperator[BelowOrEqualRule::operator])) { |
|
| 568 | 568 | |
| 569 | - $belowOrEqualRule = reset($operandsByOperator[ BelowOrEqualRule::operator ]); |
|
| 569 | + $belowOrEqualRule = reset($operandsByOperator[BelowOrEqualRule::operator]); |
|
| 570 | 570 | if ($equalRule->getValue() <= $belowOrEqualRule->getMaximum()) { |
| 571 | - unset($operandsByOperator[ BelowOrEqualRule::operator ]); |
|
| 571 | + unset($operandsByOperator[BelowOrEqualRule::operator]); |
|
| 572 | 572 | } |
| 573 | 573 | else { |
| 574 | 574 | // ['field', '=', 4] && ['field', '<=', [3]...] <=> false |
@@ -576,11 +576,11 @@ discard block |
||
| 576 | 576 | } |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - if (!empty($operandsByOperator[ AboveOrEqualRule::operator ])) { |
|
| 579 | + if (!empty($operandsByOperator[AboveOrEqualRule::operator])) { |
|
| 580 | 580 | |
| 581 | - $aboveOrEqualRule = reset($operandsByOperator[ AboveOrEqualRule::operator ]); |
|
| 581 | + $aboveOrEqualRule = reset($operandsByOperator[AboveOrEqualRule::operator]); |
|
| 582 | 582 | if ($equalRule->getValue() >= $aboveOrEqualRule->getMinimum()) { |
| 583 | - unset($operandsByOperator[ AboveOrEqualRule::operator ]); |
|
| 583 | + unset($operandsByOperator[AboveOrEqualRule::operator]); |
|
| 584 | 584 | } |
| 585 | 585 | else { |
| 586 | 586 | // ['field', '=', 4] && ['field', '<=', [3]...] <=> false |
@@ -590,52 +590,52 @@ discard block |
||
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | // NotEqualRule null comparisons |
| 593 | - if (!empty($operandsByOperator[ NotEqualRule::operator ])) { |
|
| 594 | - if (!empty($operandsByOperator[ NotEqualRule::operator ])) { |
|
| 595 | - foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $notEqualRule) { |
|
| 593 | + if (!empty($operandsByOperator[NotEqualRule::operator])) { |
|
| 594 | + if (!empty($operandsByOperator[NotEqualRule::operator])) { |
|
| 595 | + foreach ($operandsByOperator[NotEqualRule::operator] as $i => $notEqualRule) { |
|
| 596 | 596 | |
| 597 | 597 | if ($notEqualRule->getValue() === null) { |
| 598 | - if (!empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 599 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 598 | + if (!empty($operandsByOperator[AboveRule::operator])) { |
|
| 599 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | - if (!empty($operandsByOperator[ BelowRule::operator ])) { |
|
| 603 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 602 | + if (!empty($operandsByOperator[BelowRule::operator])) { |
|
| 603 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | - if (!empty($operandsByOperator[ EqualRule::operator ])) { |
|
| 607 | - if (reset($operandsByOperator[ EqualRule::operator ])->getValue() !== null) |
|
| 608 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 606 | + if (!empty($operandsByOperator[EqualRule::operator])) { |
|
| 607 | + if (reset($operandsByOperator[EqualRule::operator])->getValue() !== null) |
|
| 608 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 609 | 609 | } |
| 610 | 610 | } |
| 611 | 611 | else { |
| 612 | - if (!empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 613 | - if ($operandsByOperator[ AboveRule::operator ][0]->getMinimum() >= $notEqualRule->getValue()) |
|
| 614 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 612 | + if (!empty($operandsByOperator[AboveRule::operator])) { |
|
| 613 | + if ($operandsByOperator[AboveRule::operator][0]->getMinimum() >= $notEqualRule->getValue()) |
|
| 614 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - if (!empty($operandsByOperator[ BelowRule::operator ])) { |
|
| 618 | - if ($operandsByOperator[ BelowRule::operator ][0]->getMaximum() <= $notEqualRule->getValue()) |
|
| 619 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 617 | + if (!empty($operandsByOperator[BelowRule::operator])) { |
|
| 618 | + if ($operandsByOperator[BelowRule::operator][0]->getMaximum() <= $notEqualRule->getValue()) |
|
| 619 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 620 | 620 | } |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - if (!empty($operandsByOperator[ NotInRule::operator ])) { |
|
| 624 | - $notInRule = reset($operandsByOperator[ NotInRule::operator ]); |
|
| 623 | + if (!empty($operandsByOperator[NotInRule::operator])) { |
|
| 624 | + $notInRule = reset($operandsByOperator[NotInRule::operator]); |
|
| 625 | 625 | if (!in_array($notEqualRule->getValue(), $notInRule->getPossibilities())) { |
| 626 | 626 | // TODO Replace it by a FalseRule |
| 627 | - $operandsByOperator[ NotInRule::operator ][0]->setPossibilities( |
|
| 627 | + $operandsByOperator[NotInRule::operator][0]->setPossibilities( |
|
| 628 | 628 | array_merge($notInRule->getPossibilities(), [$notEqualRule->getValue()]) |
| 629 | 629 | ); |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 632 | + unset($operandsByOperator[NotEqualRule::operator][$i]); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | - if (!empty($operandsByOperator[ InRule::operator ])) { |
|
| 636 | - $inRule = reset($operandsByOperator[ InRule::operator ]); |
|
| 635 | + if (!empty($operandsByOperator[InRule::operator])) { |
|
| 636 | + $inRule = reset($operandsByOperator[InRule::operator]); |
|
| 637 | 637 | |
| 638 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
| 638 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
| 639 | 639 | array_diff($inRule->getPossibilities(), [$notEqualRule->getValue()]) |
| 640 | 640 | ); |
| 641 | 641 | } |
@@ -645,61 +645,61 @@ discard block |
||
| 645 | 645 | |
| 646 | 646 | // Comparison between InRules and NotInRules |
| 647 | 647 | // This is an optimization to avoid NotIn explosion |
| 648 | - if (!empty($operandsByOperator[ InRule::operator ])) { |
|
| 649 | - $inRule = $operandsByOperator[ InRule::operator ][0]; |
|
| 648 | + if (!empty($operandsByOperator[InRule::operator])) { |
|
| 649 | + $inRule = $operandsByOperator[InRule::operator][0]; |
|
| 650 | 650 | |
| 651 | - if (!empty($operandsByOperator[ NotInRule::operator ])) { |
|
| 652 | - $notInRule = reset($operandsByOperator[ NotInRule::operator ]); |
|
| 653 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
| 654 | - array_diff( $inRule->getPossibilities(), $notInRule->getPossibilities()) |
|
| 651 | + if (!empty($operandsByOperator[NotInRule::operator])) { |
|
| 652 | + $notInRule = reset($operandsByOperator[NotInRule::operator]); |
|
| 653 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
| 654 | + array_diff($inRule->getPossibilities(), $notInRule->getPossibilities()) |
|
| 655 | 655 | ); |
| 656 | - unset($operandsByOperator[ NotInRule::operator ]); |
|
| 656 | + unset($operandsByOperator[NotInRule::operator]); |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | - if (!empty($operandsByOperator[ BelowRule::operator ])) { |
|
| 660 | - $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getMaximum(); |
|
| 659 | + if (!empty($operandsByOperator[BelowRule::operator])) { |
|
| 660 | + $upper_limit = reset($operandsByOperator[BelowRule::operator])->getMaximum(); |
|
| 661 | 661 | |
| 662 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
| 663 | - array_filter( $inRule->getPossibilities(), function ($possibility) use ($upper_limit) { |
|
| 662 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
| 663 | + array_filter($inRule->getPossibilities(), function($possibility) use ($upper_limit) { |
|
| 664 | 664 | return $possibility < $upper_limit; |
| 665 | 665 | } ) |
| 666 | 666 | ); |
| 667 | 667 | |
| 668 | - unset($operandsByOperator[ BelowRule::operator ]); |
|
| 668 | + unset($operandsByOperator[BelowRule::operator]); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | - if (!empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 672 | - $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getMinimum(); |
|
| 671 | + if (!empty($operandsByOperator[AboveRule::operator])) { |
|
| 672 | + $lower_limit = reset($operandsByOperator[AboveRule::operator])->getMinimum(); |
|
| 673 | 673 | |
| 674 | - $operandsByOperator[ InRule::operator ][0]->setPossibilities( |
|
| 675 | - array_filter( $inRule->getPossibilities(), function ($possibility) use ($lower_limit) { |
|
| 674 | + $operandsByOperator[InRule::operator][0]->setPossibilities( |
|
| 675 | + array_filter($inRule->getPossibilities(), function($possibility) use ($lower_limit) { |
|
| 676 | 676 | return $possibility > $lower_limit; |
| 677 | 677 | } ) |
| 678 | 678 | ); |
| 679 | 679 | |
| 680 | - unset($operandsByOperator[ AboveRule::operator ]); |
|
| 680 | + unset($operandsByOperator[AboveRule::operator]); |
|
| 681 | 681 | } |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | // Comparison between NotInRules and > or < |
| 685 | - if (!empty($operandsByOperator[ NotInRule::operator ])) { |
|
| 686 | - $notInRule = $operandsByOperator[ NotInRule::operator ][0]; |
|
| 685 | + if (!empty($operandsByOperator[NotInRule::operator])) { |
|
| 686 | + $notInRule = $operandsByOperator[NotInRule::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 | - $operandsByOperator[ NotInRule::operator ][0]->setPossibilities( |
|
| 692 | - array_filter( $notInRule->getPossibilities(), function ($possibility) use ($upper_limit) { |
|
| 691 | + $operandsByOperator[NotInRule::operator][0]->setPossibilities( |
|
| 692 | + array_filter($notInRule->getPossibilities(), function($possibility) use ($upper_limit) { |
|
| 693 | 693 | return $possibility < $upper_limit; |
| 694 | 694 | } ) |
| 695 | 695 | ); |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | - if (!empty($operandsByOperator[ AboveRule::operator ])) { |
|
| 699 | - $lower_limit = reset($operandsByOperator[ AboveRule::operator ])->getMinimum(); |
|
| 698 | + if (!empty($operandsByOperator[AboveRule::operator])) { |
|
| 699 | + $lower_limit = reset($operandsByOperator[AboveRule::operator])->getMinimum(); |
|
| 700 | 700 | |
| 701 | - $operandsByOperator[ NotInRule::operator ][0]->setPossibilities( |
|
| 702 | - array_filter( $notInRule->getPossibilities(), function ($possibility) use ($lower_limit) { |
|
| 701 | + $operandsByOperator[NotInRule::operator][0]->setPossibilities( |
|
| 702 | + array_filter($notInRule->getPossibilities(), function($possibility) use ($lower_limit) { |
|
| 703 | 703 | return $possibility > $lower_limit; |
| 704 | 704 | } ) |
| 705 | 705 | ); |
@@ -707,25 +707,25 @@ discard block |
||
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | // Comparison between <= and > or < |
| 710 | - if (!empty($operandsByOperator[ BelowOrEqualRule::operator ])) { |
|
| 711 | - $belowOrEqualRule = $operandsByOperator[ BelowOrEqualRule::operator ][0]; |
|
| 710 | + if (!empty($operandsByOperator[BelowOrEqualRule::operator])) { |
|
| 711 | + $belowOrEqualRule = $operandsByOperator[BelowOrEqualRule::operator][0]; |
|
| 712 | 712 | |
| 713 | - if (!empty($operandsByOperator[ BelowRule::operator ])) { |
|
| 714 | - $upper_limit = reset($operandsByOperator[ BelowRule::operator ])->getUpperLimit(); |
|
| 713 | + if (!empty($operandsByOperator[BelowRule::operator])) { |
|
| 714 | + $upper_limit = reset($operandsByOperator[BelowRule::operator])->getUpperLimit(); |
|
| 715 | 715 | |
| 716 | 716 | if ($belowOrEqualRule->getMaximum() >= $upper_limit) { |
| 717 | 717 | // [field < 3] && [field <= 3] |
| 718 | 718 | // [field < 3] && [field <= 4] |
| 719 | - unset($operandsByOperator[ BelowOrEqualRule::operator ][0]); |
|
| 719 | + unset($operandsByOperator[BelowOrEqualRule::operator][0]); |
|
| 720 | 720 | } |
| 721 | 721 | else { |
| 722 | 722 | // [field < 3] && [field <= 2] |
| 723 | - unset($operandsByOperator[ BelowRule::operator ][0]); |
|
| 723 | + unset($operandsByOperator[BelowRule::operator][0]); |
|
| 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 | 730 | if ($belowOrEqualRule->getMaximum() <= $lower_limit) { |
| 731 | 731 | // [field > 3] && [field <= 2] <=> false |
@@ -733,8 +733,8 @@ discard block |
||
| 733 | 733 | } |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | - if (!empty($operandsByOperator[ AboveOrEqualRule::operator ])) { |
|
| 737 | - $minimum = reset($operandsByOperator[ AboveOrEqualRule::operator ])->getMinimum(); |
|
| 736 | + if (!empty($operandsByOperator[AboveOrEqualRule::operator])) { |
|
| 737 | + $minimum = reset($operandsByOperator[AboveOrEqualRule::operator])->getMinimum(); |
|
| 738 | 738 | |
| 739 | 739 | if ($belowOrEqualRule->getMaximum() < $minimum) { |
| 740 | 740 | // [field <= 3] && [field >= 4] <=> false |
@@ -742,11 +742,11 @@ discard block |
||
| 742 | 742 | } |
| 743 | 743 | elseif ($belowOrEqualRule->getMaximum() == $minimum) { |
| 744 | 744 | // [field <= 3] && [field >= 3] <=> [field = 3] |
| 745 | - unset($operandsByOperator[ BelowOrEqualRule::operator ]); |
|
| 746 | - unset($operandsByOperator[ AboveOrEqualRule::operator ]); |
|
| 747 | - $operandsByOperator[ EqualRule::operator ][] = new EqualRule($field, $minimum); |
|
| 745 | + unset($operandsByOperator[BelowOrEqualRule::operator]); |
|
| 746 | + unset($operandsByOperator[AboveOrEqualRule::operator]); |
|
| 747 | + $operandsByOperator[EqualRule::operator][] = new EqualRule($field, $minimum); |
|
| 748 | 748 | |
| 749 | - if (count($operandsByOperator[ EqualRule::operator ]) > 1) { |
|
| 749 | + if (count($operandsByOperator[EqualRule::operator]) > 1) { |
|
| 750 | 750 | $operandsByOperator = self::simplifyDifferentOperandsForField($field, $operandsByOperator); |
| 751 | 751 | } |
| 752 | 752 | } |
@@ -765,10 +765,10 @@ discard block |
||
| 765 | 765 | public function setOperandsOrReplaceByOperation($new_operands) |
| 766 | 766 | { |
| 767 | 767 | try { |
| 768 | - return $this->setOperands( $new_operands ); |
|
| 768 | + return $this->setOperands($new_operands); |
|
| 769 | 769 | } |
| 770 | 770 | catch (\LogicException $e) { |
| 771 | - return new AndRule( $new_operands ); |
|
| 771 | + return new AndRule($new_operands); |
|
| 772 | 772 | } |
| 773 | 773 | } |
| 774 | 774 | |
@@ -21,16 +21,18 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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, |
@@ -486,8 +495,9 @@ discard block |
||
| 486 | 495 | // If tyhere is no more operands for a given field it means there |
| 487 | 496 | // is no possible solutions for it so all the current and_case |
| 488 | 497 | // is invalidated. |
| 489 | - if (! $operandsByOperator) |
|
| 490 | - return []; |
|
| 498 | + if (! $operandsByOperator) { |
|
| 499 | + return []; |
|
| 500 | + } |
|
| 491 | 501 | } |
| 492 | 502 | |
| 493 | 503 | return $operandsByFields; |
@@ -508,14 +518,16 @@ discard block |
||
| 508 | 518 | foreach ($operandsByOperator[ NotEqualRule::operator ] as $i => $not_equal_rule) { |
| 509 | 519 | |
| 510 | 520 | if ($equalRule->getValue() !== null) { |
| 511 | - if ($not_equal_rule->getValue() === null) // means if exists <=> equals something |
|
| 512 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 513 | - elseif ($not_equal_rule->getValue() != $equalRule->getValue()) |
|
| 514 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 515 | - } |
|
| 516 | - elseif ($equalRule->getValue() === null ) { |
|
| 517 | - if ($not_equal_rule->getValue() !== null) |
|
| 521 | + if ($not_equal_rule->getValue() === null) { |
|
| 522 | + // means if exists <=> equals something |
|
| 518 | 523 | unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
| 524 | + } elseif ($not_equal_rule->getValue() != $equalRule->getValue()) { |
|
| 525 | + unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 526 | + } |
|
| 527 | + } elseif ($equalRule->getValue() === null ) { |
|
| 528 | + if ($not_equal_rule->getValue() !== null) { |
|
| 529 | + unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 530 | + } |
|
| 519 | 531 | // else we let the "equal null" and the "not equal null" for the romeInvalidBranches step |
| 520 | 532 | } |
| 521 | 533 | } |
@@ -524,15 +536,17 @@ discard block |
||
| 524 | 536 | if (!empty($operandsByOperator[ AboveRule::operator ])) { |
| 525 | 537 | |
| 526 | 538 | $aboveRule = reset($operandsByOperator[ AboveRule::operator ]); |
| 527 | - if ($equalRule->getValue() !== null && $aboveRule->getMinimum() < $equalRule->getValue()) |
|
| 528 | - unset($operandsByOperator[ AboveRule::operator ]); |
|
| 539 | + if ($equalRule->getValue() !== null && $aboveRule->getMinimum() < $equalRule->getValue()) { |
|
| 540 | + unset($operandsByOperator[ AboveRule::operator ]); |
|
| 541 | + } |
|
| 529 | 542 | } |
| 530 | 543 | |
| 531 | 544 | if (!empty($operandsByOperator[ BelowRule::operator ])) { |
| 532 | 545 | |
| 533 | 546 | $belowRule = reset($operandsByOperator[ BelowRule::operator ]); |
| 534 | - if ($equalRule->getValue() !== null && $belowRule->getMaximum() > $equalRule->getValue()) |
|
| 535 | - unset($operandsByOperator[ BelowRule::operator ]); |
|
| 547 | + if ($equalRule->getValue() !== null && $belowRule->getMaximum() > $equalRule->getValue()) { |
|
| 548 | + unset($operandsByOperator[ BelowRule::operator ]); |
|
| 549 | + } |
|
| 536 | 550 | } |
| 537 | 551 | |
| 538 | 552 | if (!empty($operandsByOperator[ InRule::operator ])) { |
@@ -541,8 +555,7 @@ discard block |
||
| 541 | 555 | |
| 542 | 556 | if (in_array($equalRule->getValue(), $possibilities)) { |
| 543 | 557 | unset($operandsByOperator[ InRule::operator ]); |
| 544 | - } |
|
| 545 | - else { |
|
| 558 | + } else { |
|
| 546 | 559 | // We flush possibilities of the InRule |
| 547 | 560 | // TODO Replace it by a FalseRule |
| 548 | 561 | $operandsByOperator[ InRule::operator ][0]->setPossibilities([]); |
@@ -557,8 +570,7 @@ discard block |
||
| 557 | 570 | if (in_array($equalRule->getValue(), $notInRule->getPossibilities())) { |
| 558 | 571 | // ['field', '=', 4] && ['field', '!in', [4]...] <=> false |
| 559 | 572 | return []; |
| 560 | - } |
|
| 561 | - else { |
|
| 573 | + } else { |
|
| 562 | 574 | unset($operandsByOperator[ NotInRule::operator ]); |
| 563 | 575 | } |
| 564 | 576 | // $notInRule->dump(true); |
@@ -569,8 +581,7 @@ discard block |
||
| 569 | 581 | $belowOrEqualRule = reset($operandsByOperator[ BelowOrEqualRule::operator ]); |
| 570 | 582 | if ($equalRule->getValue() <= $belowOrEqualRule->getMaximum()) { |
| 571 | 583 | unset($operandsByOperator[ BelowOrEqualRule::operator ]); |
| 572 | - } |
|
| 573 | - else { |
|
| 584 | + } else { |
|
| 574 | 585 | // ['field', '=', 4] && ['field', '<=', [3]...] <=> false |
| 575 | 586 | return []; |
| 576 | 587 | } |
@@ -581,8 +592,7 @@ discard block |
||
| 581 | 592 | $aboveOrEqualRule = reset($operandsByOperator[ AboveOrEqualRule::operator ]); |
| 582 | 593 | if ($equalRule->getValue() >= $aboveOrEqualRule->getMinimum()) { |
| 583 | 594 | unset($operandsByOperator[ AboveOrEqualRule::operator ]); |
| 584 | - } |
|
| 585 | - else { |
|
| 595 | + } else { |
|
| 586 | 596 | // ['field', '=', 4] && ['field', '<=', [3]...] <=> false |
| 587 | 597 | return []; |
| 588 | 598 | } |
@@ -604,19 +614,21 @@ discard block |
||
| 604 | 614 | } |
| 605 | 615 | |
| 606 | 616 | if (!empty($operandsByOperator[ EqualRule::operator ])) { |
| 607 | - if (reset($operandsByOperator[ EqualRule::operator ])->getValue() !== null) |
|
| 608 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 617 | + if (reset($operandsByOperator[ EqualRule::operator ])->getValue() !== null) { |
|
| 618 | + unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 619 | + } |
|
| 609 | 620 | } |
| 610 | - } |
|
| 611 | - else { |
|
| 621 | + } else { |
|
| 612 | 622 | if (!empty($operandsByOperator[ AboveRule::operator ])) { |
| 613 | - if ($operandsByOperator[ AboveRule::operator ][0]->getMinimum() >= $notEqualRule->getValue()) |
|
| 614 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 623 | + if ($operandsByOperator[ AboveRule::operator ][0]->getMinimum() >= $notEqualRule->getValue()) { |
|
| 624 | + unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 625 | + } |
|
| 615 | 626 | } |
| 616 | 627 | |
| 617 | 628 | if (!empty($operandsByOperator[ BelowRule::operator ])) { |
| 618 | - if ($operandsByOperator[ BelowRule::operator ][0]->getMaximum() <= $notEqualRule->getValue()) |
|
| 619 | - unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 629 | + if ($operandsByOperator[ BelowRule::operator ][0]->getMaximum() <= $notEqualRule->getValue()) { |
|
| 630 | + unset($operandsByOperator[ NotEqualRule::operator ][$i]); |
|
| 631 | + } |
|
| 620 | 632 | } |
| 621 | 633 | } |
| 622 | 634 | |
@@ -717,8 +729,7 @@ discard block |
||
| 717 | 729 | // [field < 3] && [field <= 3] |
| 718 | 730 | // [field < 3] && [field <= 4] |
| 719 | 731 | unset($operandsByOperator[ BelowOrEqualRule::operator ][0]); |
| 720 | - } |
|
| 721 | - else { |
|
| 732 | + } else { |
|
| 722 | 733 | // [field < 3] && [field <= 2] |
| 723 | 734 | unset($operandsByOperator[ BelowRule::operator ][0]); |
| 724 | 735 | } |
@@ -739,8 +750,7 @@ discard block |
||
| 739 | 750 | if ($belowOrEqualRule->getMaximum() < $minimum) { |
| 740 | 751 | // [field <= 3] && [field >= 4] <=> false |
| 741 | 752 | return []; |
| 742 | - } |
|
| 743 | - elseif ($belowOrEqualRule->getMaximum() == $minimum) { |
|
| 753 | + } elseif ($belowOrEqualRule->getMaximum() == $minimum) { |
|
| 744 | 754 | // [field <= 3] && [field >= 3] <=> [field = 3] |
| 745 | 755 | unset($operandsByOperator[ BelowOrEqualRule::operator ]); |
| 746 | 756 | unset($operandsByOperator[ AboveOrEqualRule::operator ]); |
@@ -766,8 +776,7 @@ discard block |
||
| 766 | 776 | { |
| 767 | 777 | try { |
| 768 | 778 | return $this->setOperands( $new_operands ); |
| 769 | - } |
|
| 770 | - catch (\LogicException $e) { |
|
| 779 | + } catch (\LogicException $e) { |
|
| 771 | 780 | return new AndRule( $new_operands ); |
| 772 | 781 | } |
| 773 | 782 | } |