@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | const remove_negations = 'remove_negations'; |
22 | 22 | const rootify_disjunctions = 'rootify_disjunctions'; |
23 | 23 | const unify_atomic_operands = 'unify_atomic_operands'; |
24 | - const remove_invalid_branches = 'remove_invalid_branches'; // simplified after this step |
|
24 | + const remove_invalid_branches = 'remove_invalid_branches'; // simplified after this step |
|
25 | 25 | |
26 | 26 | const simplified = self::remove_invalid_branches; |
27 | 27 | |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | |
45 | 45 | /** |
46 | 46 | */ |
47 | - public function __construct( array $operands=[] ) |
|
47 | + public function __construct(array $operands = []) |
|
48 | 48 | { |
49 | - $this->setOperands( $operands ); |
|
49 | + $this->setOperands($operands); |
|
50 | 50 | $this->flushCache(); |
51 | 51 | } |
52 | 52 | |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return $this |
67 | 67 | */ |
68 | - public function addOperand( AbstractRule $new_operand ) |
|
68 | + public function addOperand(AbstractRule $new_operand) |
|
69 | 69 | { |
70 | - if ( ! isset($this->operands[ $id = $new_operand->getSemanticId() ])) { |
|
71 | - $this->operands[ $id ] = $new_operand; |
|
70 | + if ( ! isset($this->operands[$id = $new_operand->getSemanticId()])) { |
|
71 | + $this->operands[$id] = $new_operand; |
|
72 | 72 | |
73 | 73 | if ($this->current_simplification_step) { |
74 | 74 | $this->current_simplification_step = null; |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function getOperands() |
87 | 87 | { |
88 | - return array_values( $this->operands ); |
|
88 | + return array_values($this->operands); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @param array $simplification_options |
130 | 130 | * @param bool $force |
131 | 131 | */ |
132 | - public function moveSimplificationStepForward($step_to_go_to, array $simplification_options, $force=false) |
|
132 | + public function moveSimplificationStepForward($step_to_go_to, array $simplification_options, $force = false) |
|
133 | 133 | { |
134 | 134 | if ( ! in_array($step_to_go_to, self::simplification_steps)) { |
135 | 135 | throw new \InvalidArgumentException( |
@@ -141,18 +141,18 @@ discard block |
||
141 | 141 | if ( ! $force && null !== $this->current_simplification_step) { |
142 | 142 | $steps_indices = array_flip(self::simplification_steps); |
143 | 143 | |
144 | - $current_index = $steps_indices[ $this->current_simplification_step ]; |
|
145 | - $target_index = $steps_indices[ $step_to_go_to ]; |
|
144 | + $current_index = $steps_indices[$this->current_simplification_step]; |
|
145 | + $target_index = $steps_indices[$step_to_go_to]; |
|
146 | 146 | |
147 | - if ( $current_index >= $target_index ) { |
|
147 | + if ($current_index >= $target_index) { |
|
148 | 148 | // allow recall of previous step without going back |
149 | 149 | return; |
150 | 150 | } |
151 | - elseif ( $current_index < $target_index - 1 ) { |
|
151 | + elseif ($current_index < $target_index - 1) { |
|
152 | 152 | throw new \LogicException( |
153 | - "$step_to_go_to MUST be fullfilled after " . self::simplification_steps[$target_index - 1] |
|
154 | - . " instead of the current step: " . $this->current_simplification_step |
|
155 | - ."\nfor: " . $this |
|
153 | + "$step_to_go_to MUST be fullfilled after ".self::simplification_steps[$target_index - 1] |
|
154 | + . " instead of the current step: ".$this->current_simplification_step |
|
155 | + ."\nfor: ".$this |
|
156 | 156 | ); |
157 | 157 | } |
158 | 158 | } |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | |
190 | 190 | $steps_indices = array_flip(self::simplification_steps); |
191 | 191 | |
192 | - $current_index = $steps_indices[ $this->current_simplification_step ]; |
|
193 | - $step_index = $steps_indices[ $step ]; |
|
192 | + $current_index = $steps_indices[$this->current_simplification_step]; |
|
193 | + $step_index = $steps_indices[$step]; |
|
194 | 194 | |
195 | 195 | return $current_index >= $step_index; |
196 | 196 | } |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | if ($operands[$i] instanceof AbstractOperationRule) { |
219 | - $operands[$i]->removeNegations( $contextual_options ); |
|
219 | + $operands[$i]->removeNegations($contextual_options); |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
@@ -239,11 +239,11 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @return AbstractOperationRule |
241 | 241 | */ |
242 | - public function cleanOperations(array $simplification_options, $recurse=true) |
|
242 | + public function cleanOperations(array $simplification_options, $recurse = true) |
|
243 | 243 | { |
244 | 244 | if ($recurse) { |
245 | 245 | foreach ($this->operands as $i => $operand) { |
246 | - if ( $operand instanceof AbstractOperationRule |
|
246 | + if ($operand instanceof AbstractOperationRule |
|
247 | 247 | && ! $operand instanceof InRule |
248 | 248 | && ! $operand instanceof NotEqualRule |
249 | 249 | && ! $operand instanceof NotInRule |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | public function unifyAtomicOperands($simplification_strategy_step = false, array $contextual_options) |
317 | 317 | { |
318 | 318 | if ($simplification_strategy_step) { |
319 | - $this->moveSimplificationStepForward( self::unify_atomic_operands, $contextual_options ); |
|
319 | + $this->moveSimplificationStepForward(self::unify_atomic_operands, $contextual_options); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | // $this->dump(true); |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | catch (\Exception $e) { |
353 | 353 | VisibilityViolator::setHiddenProperty( |
354 | 354 | $e, 'message', |
355 | - $e->getMessage() . "\n" . var_export($operandsByOperator, true) |
|
355 | + $e->getMessage()."\n".var_export($operandsByOperator, true) |
|
356 | 356 | ); |
357 | 357 | |
358 | 358 | throw $e; |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | } |
361 | 361 | } |
362 | 362 | |
363 | - return $this->setOperandsOrReplaceByOperation( $unifiedOperands, $contextual_options ); |
|
363 | + return $this->setOperandsOrReplaceByOperation($unifiedOperands, $contextual_options); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | private static $simplification_cache = []; |
@@ -376,10 +376,10 @@ discard block |
||
376 | 376 | * |
377 | 377 | * @return AbstractRule the simplified rule |
378 | 378 | */ |
379 | - final public function simplify($options=[]) |
|
379 | + final public function simplify($options = []) |
|
380 | 380 | { |
381 | - $step_to_stop_before = ! empty($options['stop_before']) ? $options['stop_before'] : null; |
|
382 | - $step_to_stop_after = ! empty($options['stop_after']) ? $options['stop_after'] : null; |
|
381 | + $step_to_stop_before = ! empty($options['stop_before']) ? $options['stop_before'] : null; |
|
382 | + $step_to_stop_after = ! empty($options['stop_after']) ? $options['stop_after'] : null; |
|
383 | 383 | $force_logical_core = ! empty($options['force_logical_core']) ? $options['force_logical_core'] : false; |
384 | 384 | |
385 | 385 | if ($step_to_stop_before && ! in_array($step_to_stop_before, self::simplification_steps)) { |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | // $instance->dump(true); |
418 | 418 | |
419 | 419 | if (self::remove_negations == $step_to_stop_after || |
420 | - self::rootify_disjunctions == $step_to_stop_before ) { |
|
420 | + self::rootify_disjunctions == $step_to_stop_before) { |
|
421 | 421 | return $instance; |
422 | 422 | } |
423 | 423 | |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | // $instance->dump(true); |
430 | 430 | |
431 | 431 | if (self::rootify_disjunctions == $step_to_stop_after || |
432 | - self::unify_atomic_operands == $step_to_stop_before ) { |
|
432 | + self::unify_atomic_operands == $step_to_stop_before) { |
|
433 | 433 | return $instance; |
434 | 434 | } |
435 | 435 | |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | // $instance->dump(true); |
441 | 441 | |
442 | 442 | if (self::unify_atomic_operands == $step_to_stop_after || |
443 | - self::remove_invalid_branches == $step_to_stop_before ) { |
|
443 | + self::remove_invalid_branches == $step_to_stop_before) { |
|
444 | 444 | return $instance; |
445 | 445 | } |
446 | 446 | |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | // last non recursive clean |
458 | 458 | // TODO kind of monad|become|cese |
459 | 459 | // @see https://github.com/jclaveau/php-logical-filter/issues/20 |
460 | - if ($instance instanceof AndRule || $instance instanceof OrRule ) { |
|
460 | + if ($instance instanceof AndRule || $instance instanceof OrRule) { |
|
461 | 461 | if ( ! $instance->getOperands()) { |
462 | 462 | return $instance; |
463 | 463 | } |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | |
479 | 479 | $cache_keys[] = $instance->getSemanticId().'-'.$options_id; |
480 | 480 | foreach ($cache_keys as $cache_key) { |
481 | - self::$simplification_cache[ $cache_key ] = $instance; |
|
481 | + self::$simplification_cache[$cache_key] = $instance; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | return $instance->copy(); |
@@ -501,15 +501,15 @@ discard block |
||
501 | 501 | // For FilteredValue and FilteredKey |
502 | 502 | $field = (string) $field; |
503 | 503 | |
504 | - if ( ! isset($operandsByFields[ $field ])) { |
|
505 | - $operandsByFields[ $field ] = []; |
|
504 | + if ( ! isset($operandsByFields[$field])) { |
|
505 | + $operandsByFields[$field] = []; |
|
506 | 506 | } |
507 | 507 | |
508 | - if ( ! isset($operandsByFields[ $field ][ $operand::operator ])) { |
|
509 | - $operandsByFields[ $field ][ $operand::operator ] = []; |
|
508 | + if ( ! isset($operandsByFields[$field][$operand::operator])) { |
|
509 | + $operandsByFields[$field][$operand::operator] = []; |
|
510 | 510 | } |
511 | 511 | |
512 | - $operandsByFields[ $field ][ $operand::operator ][] = $operand; |
|
512 | + $operandsByFields[$field][$operand::operator][] = $operand; |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | return $operandsByFields; |
@@ -532,15 +532,15 @@ discard block |
||
532 | 532 | // For FilteredValue and FilteredKey |
533 | 533 | $field = (string) $field; |
534 | 534 | |
535 | - if ( ! isset($operandsByFields[ $field ])) { |
|
536 | - $operandsByFields[ $field ] = []; |
|
535 | + if ( ! isset($operandsByFields[$field])) { |
|
536 | + $operandsByFields[$field] = []; |
|
537 | 537 | } |
538 | 538 | |
539 | - if ( ! isset($operandsByFields[ $field ][ $operand::operator ])) { |
|
540 | - $operandsByFields[ $field ][ $operand::operator ] = []; |
|
539 | + if ( ! isset($operandsByFields[$field][$operand::operator])) { |
|
540 | + $operandsByFields[$field][$operand::operator] = []; |
|
541 | 541 | } |
542 | 542 | |
543 | - $operandsByFields[ $field ][ $operand::operator ][] = $operand; |
|
543 | + $operandsByFields[$field][$operand::operator][] = $operand; |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | return $operandsByFields; |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | * |
579 | 579 | * @return AbstractRule|null The operand if it exists or null |
580 | 580 | */ |
581 | - protected function getOperandAt($index=0) |
|
581 | + protected function getOperandAt($index = 0) |
|
582 | 582 | { |
583 | 583 | $operands = array_values($this->operands); |
584 | 584 | if (isset($operands[$index])) { |