@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | const remove_negations = 'remove_negations'; |
21 | 21 | const rootify_disjunctions = 'rootify_disjunctions'; |
22 | 22 | const unify_atomic_operands = 'unify_atomic_operands'; |
23 | - const remove_invalid_branches = 'remove_invalid_branches'; // simplified after this step |
|
23 | + const remove_invalid_branches = 'remove_invalid_branches'; // simplified after this step |
|
24 | 24 | |
25 | 25 | const simplified = self::remove_invalid_branches; |
26 | 26 | |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | |
44 | 44 | /** |
45 | 45 | */ |
46 | - public function __construct( array $operands=[] ) |
|
46 | + public function __construct(array $operands = []) |
|
47 | 47 | { |
48 | - $this->setOperands( $operands ); |
|
48 | + $this->setOperands($operands); |
|
49 | 49 | $this->flushCache(); |
50 | 50 | } |
51 | 51 | |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return $this |
66 | 66 | */ |
67 | - public function addOperand( AbstractRule $new_operand ) |
|
67 | + public function addOperand(AbstractRule $new_operand) |
|
68 | 68 | { |
69 | - if ( ! isset($this->operands[ $id = $new_operand->getSemanticId() ])) { |
|
70 | - $this->operands[ $id ] = $new_operand; |
|
69 | + if (!isset($this->operands[$id = $new_operand->getSemanticId()])) { |
|
70 | + $this->operands[$id] = $new_operand; |
|
71 | 71 | |
72 | 72 | if ($this->current_simplification_step) { |
73 | 73 | $this->current_simplification_step = null; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function getOperands() |
86 | 86 | { |
87 | - return array_values( $this->operands ); |
|
87 | + return array_values($this->operands); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -128,30 +128,30 @@ discard block |
||
128 | 128 | * @param array $simplification_options |
129 | 129 | * @param bool $force |
130 | 130 | */ |
131 | - public function moveSimplificationStepForward($step_to_go_to, array $simplification_options, $force=false) |
|
131 | + public function moveSimplificationStepForward($step_to_go_to, array $simplification_options, $force = false) |
|
132 | 132 | { |
133 | - if ( ! in_array($step_to_go_to, self::simplification_steps)) { |
|
133 | + if (!in_array($step_to_go_to, self::simplification_steps)) { |
|
134 | 134 | throw new \InvalidArgumentException( |
135 | 135 | "Invalid simplification step to go to: ".$step_to_go_to |
136 | 136 | ); |
137 | 137 | } |
138 | 138 | |
139 | 139 | // if ($this->isNormalizationAllowed($simplification_options) && !$force && $this->current_simplification_step != null) { |
140 | - if ( ! $force && null !== $this->current_simplification_step) { |
|
140 | + if (!$force && null !== $this->current_simplification_step) { |
|
141 | 141 | $steps_indices = array_flip(self::simplification_steps); |
142 | 142 | |
143 | - $current_index = $steps_indices[ $this->current_simplification_step ]; |
|
144 | - $target_index = $steps_indices[ $step_to_go_to ]; |
|
143 | + $current_index = $steps_indices[$this->current_simplification_step]; |
|
144 | + $target_index = $steps_indices[$step_to_go_to]; |
|
145 | 145 | |
146 | - if ( $current_index >= $target_index ) { |
|
146 | + if ($current_index >= $target_index) { |
|
147 | 147 | // allow recall of previous step without going back |
148 | 148 | return; |
149 | 149 | } |
150 | - elseif ( $current_index < $target_index - 1 ) { |
|
150 | + elseif ($current_index < $target_index - 1) { |
|
151 | 151 | throw new \LogicException( |
152 | - "$step_to_go_to MUST be fullfilled after " . self::simplification_steps[$target_index - 1] |
|
153 | - . " instead of the current step: " . $this->current_simplification_step |
|
154 | - ."\nfor: " . $this |
|
152 | + "$step_to_go_to MUST be fullfilled after ".self::simplification_steps[$target_index - 1] |
|
153 | + . " instead of the current step: ".$this->current_simplification_step |
|
154 | + ."\nfor: ".$this |
|
155 | 155 | ); |
156 | 156 | } |
157 | 157 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function simplicationStepReached($step) |
170 | 170 | { |
171 | - if ( ! in_array($step, self::simplification_steps)) { |
|
171 | + if (!in_array($step, self::simplification_steps)) { |
|
172 | 172 | throw new \InvalidArgumentException( |
173 | 173 | "Invalid simplification step: ".$step |
174 | 174 | ); |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | |
181 | 181 | $steps_indices = array_flip(self::simplification_steps); |
182 | 182 | |
183 | - $current_index = $steps_indices[ $this->current_simplification_step ]; |
|
184 | - $step_index = $steps_indices[ $step ]; |
|
183 | + $current_index = $steps_indices[$this->current_simplification_step]; |
|
184 | + $step_index = $steps_indices[$step]; |
|
185 | 185 | |
186 | 186 | return $current_index >= $step_index; |
187 | 187 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function removeNegations(array $contextual_options) |
195 | 195 | { |
196 | - if ( ! $this->isNormalizationAllowed($contextual_options)) { |
|
196 | + if (!$this->isNormalizationAllowed($contextual_options)) { |
|
197 | 197 | return $this; |
198 | 198 | } |
199 | 199 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | } |
208 | 208 | |
209 | 209 | if ($operands[$i] instanceof AbstractOperationRule) { |
210 | - $operands[$i]->removeNegations( $contextual_options ); |
|
210 | + $operands[$i]->removeNegations($contextual_options); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
@@ -230,14 +230,14 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @return AbstractOperationRule |
232 | 232 | */ |
233 | - public function cleanOperations(array $simplification_options, $recurse=true) |
|
233 | + public function cleanOperations(array $simplification_options, $recurse = true) |
|
234 | 234 | { |
235 | 235 | if ($recurse) { |
236 | 236 | foreach ($this->operands as $i => $operand) { |
237 | - if ( $operand instanceof AbstractOperationRule |
|
238 | - && ! $operand instanceof InRule |
|
239 | - && ! $operand instanceof NotEqualRule |
|
240 | - && ! $operand instanceof NotInRule |
|
237 | + if ($operand instanceof AbstractOperationRule |
|
238 | + && !$operand instanceof InRule |
|
239 | + && !$operand instanceof NotEqualRule |
|
240 | + && !$operand instanceof NotInRule |
|
241 | 241 | ) { |
242 | 242 | $this->operands[$i] = $operand->cleanOperations($simplification_options); |
243 | 243 | } |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | public function removeMonooperandOperationsOperands(array $simplification_options) |
277 | 277 | { |
278 | 278 | foreach ($this->operands as $i => $operand) { |
279 | - if ( ! $operand instanceof AbstractOperationRule || $operand instanceof NotRule) { |
|
279 | + if (!$operand instanceof AbstractOperationRule || $operand instanceof NotRule) { |
|
280 | 280 | continue; |
281 | 281 | } |
282 | 282 | |
283 | - if ($operand instanceof InRule && ! $operand->isNormalizationAllowed($simplification_options)) { |
|
283 | + if ($operand instanceof InRule && !$operand->isNormalizationAllowed($simplification_options)) { |
|
284 | 284 | $count = count($operand->getPossibilities()); |
285 | 285 | } |
286 | 286 | else { |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | } |
298 | 298 | } |
299 | 299 | |
300 | - return ! empty($has_been_changed); |
|
300 | + return !empty($has_been_changed); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | public function unifyAtomicOperands($simplification_strategy_step = false, array $contextual_options) |
309 | 309 | { |
310 | 310 | if ($simplification_strategy_step) { |
311 | - $this->moveSimplificationStepForward( self::unify_atomic_operands, $contextual_options ); |
|
311 | + $this->moveSimplificationStepForward(self::unify_atomic_operands, $contextual_options); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | // $this->dump(true); |
315 | 315 | |
316 | - if ( ! $this->isNormalizationAllowed($contextual_options)) { |
|
316 | + if (!$this->isNormalizationAllowed($contextual_options)) { |
|
317 | 317 | return $this; |
318 | 318 | } |
319 | 319 | |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | catch (\Exception $e) { |
345 | 345 | VisibilityViolator::setHiddenProperty( |
346 | 346 | $e, 'message', |
347 | - $e->getMessage() . "\n" . var_export($operandsByOperator, true) |
|
347 | + $e->getMessage()."\n".var_export($operandsByOperator, true) |
|
348 | 348 | ); |
349 | 349 | |
350 | 350 | throw $e; |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | - return $this->setOperandsOrReplaceByOperation( $unifiedOperands, $contextual_options ); |
|
355 | + return $this->setOperandsOrReplaceByOperation($unifiedOperands, $contextual_options); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | private static $simplification_cache = []; |
@@ -368,13 +368,13 @@ discard block |
||
368 | 368 | * |
369 | 369 | * @return AbstractRule the simplified rule |
370 | 370 | */ |
371 | - final public function simplify($options=[]) |
|
371 | + final public function simplify($options = []) |
|
372 | 372 | { |
373 | - $step_to_stop_before = ! empty($options['stop_before']) ? $options['stop_before'] : null; |
|
374 | - $step_to_stop_after = ! empty($options['stop_after']) ? $options['stop_after'] : null; |
|
375 | - $force_logical_core = ! empty($options['force_logical_core']) ? $options['force_logical_core'] : false; |
|
373 | + $step_to_stop_before = !empty($options['stop_before']) ? $options['stop_before'] : null; |
|
374 | + $step_to_stop_after = !empty($options['stop_after']) ? $options['stop_after'] : null; |
|
375 | + $force_logical_core = !empty($options['force_logical_core']) ? $options['force_logical_core'] : false; |
|
376 | 376 | |
377 | - if ($step_to_stop_before && ! in_array($step_to_stop_before, self::simplification_steps)) { |
|
377 | + if ($step_to_stop_before && !in_array($step_to_stop_before, self::simplification_steps)) { |
|
378 | 378 | throw new \InvalidArgumentException( |
379 | 379 | "Invalid simplification step to stop at: ".$step_to_stop_before |
380 | 380 | ); |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | // $instance->dump(true); |
410 | 410 | |
411 | 411 | if (self::remove_negations == $step_to_stop_after || |
412 | - self::rootify_disjunctions == $step_to_stop_before ) { |
|
412 | + self::rootify_disjunctions == $step_to_stop_before) { |
|
413 | 413 | return $instance; |
414 | 414 | } |
415 | 415 | |
@@ -421,18 +421,18 @@ discard block |
||
421 | 421 | // $instance->dump(true); |
422 | 422 | |
423 | 423 | if (self::rootify_disjunctions == $step_to_stop_after || |
424 | - self::unify_atomic_operands == $step_to_stop_before ) { |
|
424 | + self::unify_atomic_operands == $step_to_stop_before) { |
|
425 | 425 | return $instance; |
426 | 426 | } |
427 | 427 | |
428 | - if ( ! $instance instanceof AbstractAtomicRule) { |
|
428 | + if (!$instance instanceof AbstractAtomicRule) { |
|
429 | 429 | $instance->cleanOperations($options); |
430 | 430 | $instance->unifyAtomicOperands(true, $options); |
431 | 431 | |
432 | 432 | // $instance->dump(true); |
433 | 433 | |
434 | 434 | if (self::unify_atomic_operands == $step_to_stop_after || |
435 | - self::remove_invalid_branches == $step_to_stop_before ) { |
|
435 | + self::remove_invalid_branches == $step_to_stop_before) { |
|
436 | 436 | return $instance; |
437 | 437 | } |
438 | 438 | |
@@ -449,8 +449,8 @@ discard block |
||
449 | 449 | // last non recursive clean |
450 | 450 | // TODO kind of monad|become|cese |
451 | 451 | //@see https://github.com/jclaveau/php-logical-filter/issues/20 |
452 | - if ($instance instanceof AndRule || $instance instanceof OrRule ) { |
|
453 | - if ( ! $instance->getOperands()) { |
|
452 | + if ($instance instanceof AndRule || $instance instanceof OrRule) { |
|
453 | + if (!$instance->getOperands()) { |
|
454 | 454 | return $instance; |
455 | 455 | } |
456 | 456 | |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | $instance = $instance->forceLogicalCore(); |
470 | 470 | // for the simplification status at |
471 | 471 | foreach ($operands = $instance->getOperands() as $andOperand) { |
472 | - if ( ! $andOperand instanceof AndRule) { |
|
472 | + if (!$andOperand instanceof AndRule) { |
|
473 | 473 | throw new \LogicException( |
474 | 474 | "A rule is intended to be an and case: \n" |
475 | 475 | .$andOperand |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | |
490 | 490 | $cache_keys[] = $instance->getSemanticId().'-'.$options_id; |
491 | 491 | foreach ($cache_keys as $cache_key) { |
492 | - self::$simplification_cache[ $cache_key ] = $instance; |
|
492 | + self::$simplification_cache[$cache_key] = $instance; |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | return $instance->copy(); |
@@ -512,15 +512,15 @@ discard block |
||
512 | 512 | // For FilteredValue and FilteredKey |
513 | 513 | $field = (string) $field; |
514 | 514 | |
515 | - if ( ! isset($operandsByFields[ $field ])) { |
|
516 | - $operandsByFields[ $field ] = []; |
|
515 | + if (!isset($operandsByFields[$field])) { |
|
516 | + $operandsByFields[$field] = []; |
|
517 | 517 | } |
518 | 518 | |
519 | - if ( ! isset($operandsByFields[ $field ][ $operand::operator ])) { |
|
520 | - $operandsByFields[ $field ][ $operand::operator ] = []; |
|
519 | + if (!isset($operandsByFields[$field][$operand::operator])) { |
|
520 | + $operandsByFields[$field][$operand::operator] = []; |
|
521 | 521 | } |
522 | 522 | |
523 | - $operandsByFields[ $field ][ $operand::operator ][] = $operand; |
|
523 | + $operandsByFields[$field][$operand::operator][] = $operand; |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | return $operandsByFields; |
@@ -543,15 +543,15 @@ discard block |
||
543 | 543 | // For FilteredValue and FilteredKey |
544 | 544 | $field = (string) $field; |
545 | 545 | |
546 | - if ( ! isset($operandsByFields[ $field ])) { |
|
547 | - $operandsByFields[ $field ] = []; |
|
546 | + if (!isset($operandsByFields[$field])) { |
|
547 | + $operandsByFields[$field] = []; |
|
548 | 548 | } |
549 | 549 | |
550 | - if ( ! isset($operandsByFields[ $field ][ $operand::operator ])) { |
|
551 | - $operandsByFields[ $field ][ $operand::operator ] = []; |
|
550 | + if (!isset($operandsByFields[$field][$operand::operator])) { |
|
551 | + $operandsByFields[$field][$operand::operator] = []; |
|
552 | 552 | } |
553 | 553 | |
554 | - $operandsByFields[ $field ][ $operand::operator ][] = $operand; |
|
554 | + $operandsByFields[$field][$operand::operator][] = $operand; |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | return $operandsByFields; |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | * |
590 | 590 | * @return AbstractRule|null The operand if it exists or null |
591 | 591 | */ |
592 | - protected function getOperandAt($index=0) |
|
592 | + protected function getOperandAt($index = 0) |
|
593 | 593 | { |
594 | 594 | $operands = array_values($this->operands); |
595 | 595 | if (isset($operands[$index])) { |