@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @todo use get_class instead of instanceof to avoid order issue |
| 42 | 42 | * in the conditions. |
| 43 | 43 | * |
| 44 | - * @return array |
|
| 44 | + * @return AbstractRule |
|
| 45 | 45 | */ |
| 46 | 46 | public function negateOperand(array $current_simplification_options) |
| 47 | 47 | { |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * @todo rename as RootifyDisjunjctions? |
| 187 | 187 | * @todo return $this (implements a Rule monad?) |
| 188 | 188 | * |
| 189 | - * @return OrRule copied operands with one OR at its root |
|
| 189 | + * @return NotRule copied operands with one OR at its root |
|
| 190 | 190 | */ |
| 191 | 191 | public function rootifyDisjunctions($simplification_options) |
| 192 | 192 | { |
@@ -286,6 +286,7 @@ discard block |
||
| 286 | 286 | * This method is meant to be used during simplification that would |
| 287 | 287 | * need to change the class of the current instance by a normal one. |
| 288 | 288 | * |
| 289 | + * @param AbstractRule[] $new_operands |
|
| 289 | 290 | * @return OrRule The current instance (of or or subclass) or a new OrRule |
| 290 | 291 | */ |
| 291 | 292 | public function setOperandsOrReplaceByOperation($new_operands, array $contextual_options) |
@@ -12,9 +12,9 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | */ |
| 15 | - public function __construct( AbstractRule $operand=null, array $options=[] ) |
|
| 15 | + public function __construct(AbstractRule $operand = null, array $options = []) |
|
| 16 | 16 | { |
| 17 | - if ( ! empty($options)) { |
|
| 17 | + if (!empty($options)) { |
|
| 18 | 18 | $this->setOptions($options); |
| 19 | 19 | } |
| 20 | 20 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | */ |
| 30 | - public function isNormalizationAllowed(array $current_simplification_options=[]) |
|
| 30 | + public function isNormalizationAllowed(array $current_simplification_options = []) |
|
| 31 | 31 | { |
| 32 | 32 | $operand = $this->getOperandAt(0); |
| 33 | 33 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function negateOperand(array $current_simplification_options) |
| 47 | 47 | { |
| 48 | - if ( ! $this->isNormalizationAllowed($current_simplification_options)) { |
|
| 48 | + if (!$this->isNormalizationAllowed($current_simplification_options)) { |
|
| 49 | 49 | return $this; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -79,11 +79,11 @@ discard block |
||
| 79 | 79 | ]); |
| 80 | 80 | } |
| 81 | 81 | else { |
| 82 | - $new_rule = new NotEqualRule( $field, $operand->getValue() ); |
|
| 82 | + $new_rule = new NotEqualRule($field, $operand->getValue()); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | elseif ($operand instanceof NotEqualRule) { |
| 86 | - $new_rule = new EqualRule( $field, $operand->getValue() ); |
|
| 86 | + $new_rule = new EqualRule($field, $operand->getValue()); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
@@ -118,13 +118,13 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | $tmp = []; |
| 120 | 120 | foreach ($current_operand_possibilities->getOperands() as $current_operand_possibility) { |
| 121 | - $tmp[] = $current_operand_possibility->addOperand( $next_operand->copy() ); |
|
| 121 | + $tmp[] = $current_operand_possibility->addOperand($next_operand->copy()); |
|
| 122 | 122 | } |
| 123 | 123 | $current_operand_possibilities->setOperands($tmp); |
| 124 | 124 | |
| 125 | 125 | foreach ($next_operand_possibilities->getOperands() as $next_operand_possibility) { |
| 126 | 126 | $current_operand_possibilities->addOperand( |
| 127 | - $next_operand_possibility->addOperand( new NotRule($next_operand->copy()) ) |
|
| 127 | + $next_operand_possibility->addOperand(new NotRule($next_operand->copy())) |
|
| 128 | 128 | ); |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -132,15 +132,15 @@ discard block |
||
| 132 | 132 | // We remove the only possibility where no rule is negated |
| 133 | 133 | $combinations = $current_operand_possibilities->getOperands(); |
| 134 | 134 | array_shift($combinations); // The first rule contains no negation |
| 135 | - $new_rule->setOperands( $combinations ) |
|
| 135 | + $new_rule->setOperands($combinations) |
|
| 136 | 136 | // ->dump(true) |
| 137 | 137 | ; |
| 138 | 138 | } |
| 139 | 139 | elseif ($operand instanceof OrRule) { |
| 140 | 140 | |
| 141 | 141 | // $operand->dump(true); |
| 142 | - if ( $operand instanceof InRule |
|
| 143 | - && ! $operand->isNormalizationAllowed($current_simplification_options) |
|
| 142 | + if ($operand instanceof InRule |
|
| 143 | + && !$operand->isNormalizationAllowed($current_simplification_options) |
|
| 144 | 144 | ) { |
| 145 | 145 | // ['not', ['field', 'in', [2, 3]]] <=> ['field', '!in', [2, 3]] |
| 146 | 146 | $new_rule = new NotInRule( |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | [$sub_operand->copy()], |
| 159 | 159 | $current_simplification_options |
| 160 | 160 | ); |
| 161 | - $new_rule->addOperand( $negation ); |
|
| 161 | + $new_rule->addOperand($negation); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | // $new_rule->dump(!true); |
@@ -168,9 +168,9 @@ discard block |
||
| 168 | 168 | $new_rule = $operand->getOperandAt(0); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if ( ! isset($new_rule)) { |
|
| 171 | + if (!isset($new_rule)) { |
|
| 172 | 172 | throw new \LogicException( |
| 173 | - 'Removing NotRule(' . var_export($operand, true) . ') ' |
|
| 173 | + 'Removing NotRule('.var_export($operand, true).') ' |
|
| 174 | 174 | . ' not implemented' |
| 175 | 175 | ); |
| 176 | 176 | } |
@@ -190,11 +190,11 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | public function rootifyDisjunctions($simplification_options) |
| 192 | 192 | { |
| 193 | - if ( ! $this->isNormalizationAllowed($simplification_options)) { |
|
| 193 | + if (!$this->isNormalizationAllowed($simplification_options)) { |
|
| 194 | 194 | return $this; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - $this->moveSimplificationStepForward( self::rootify_disjunctions, $simplification_options ); |
|
| 197 | + $this->moveSimplificationStepForward(self::rootify_disjunctions, $simplification_options); |
|
| 198 | 198 | |
| 199 | 199 | foreach ($this->operands as $id => $operand) { |
| 200 | 200 | if ($operand instanceof AbstractOperationRule) { |
@@ -212,12 +212,12 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | public function unifyAtomicOperands($simplification_strategy_step = false, array $contextual_options) |
| 214 | 214 | { |
| 215 | - if ( ! $this->isNormalizationAllowed($contextual_options)) { |
|
| 215 | + if (!$this->isNormalizationAllowed($contextual_options)) { |
|
| 216 | 216 | return $this; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | if ($simplification_strategy_step) { |
| 220 | - $this->moveSimplificationStepForward( self::unify_atomic_operands, $contextual_options ); |
|
| 220 | + $this->moveSimplificationStepForward(self::unify_atomic_operands, $contextual_options); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | return $this; |
@@ -228,19 +228,19 @@ discard block |
||
| 228 | 228 | * |
| 229 | 229 | * @return array |
| 230 | 230 | */ |
| 231 | - public function toArray(array $options=[]) |
|
| 231 | + public function toArray(array $options = []) |
|
| 232 | 232 | { |
| 233 | 233 | $default_options = [ |
| 234 | 234 | 'show_instance' => false, |
| 235 | 235 | 'semantic' => false, |
| 236 | 236 | ]; |
| 237 | 237 | foreach ($default_options as $default_option => &$default_value) { |
| 238 | - if ( ! isset($options[ $default_option ])) { |
|
| 239 | - $options[ $default_option ] = $default_value; |
|
| 238 | + if (!isset($options[$default_option])) { |
|
| 239 | + $options[$default_option] = $default_value; |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if ( ! $options['show_instance'] && isset($this->cache['array'])) { |
|
| 243 | + if (!$options['show_instance'] && isset($this->cache['array'])) { |
|
| 244 | 244 | return $this->cache['array']; |
| 245 | 245 | } |
| 246 | 246 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | ]; |
| 251 | 251 | |
| 252 | 252 | // TODO make a dedicated cache entry for semantic array? |
| 253 | - if ( ! $options['show_instance'] && ! $options['semantic']) { |
|
| 253 | + if (!$options['show_instance'] && !$options['semantic']) { |
|
| 254 | 254 | return $this->cache['array'] = $array; |
| 255 | 255 | } |
| 256 | 256 | else { |
@@ -260,10 +260,10 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | /** |
| 262 | 262 | */ |
| 263 | - public function toString(array $options=[]) |
|
| 263 | + public function toString(array $options = []) |
|
| 264 | 264 | { |
| 265 | 265 | $operator = self::operator; |
| 266 | - if ( ! $this->operands) { |
|
| 266 | + if (!$this->operands) { |
|
| 267 | 267 | return "['{$operator}']"; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | $out = "['{$operator}'," |
| 274 | 274 | . $line_break |
| 275 | - . ($indent_unit ? : ' ') |
|
| 275 | + . ($indent_unit ?: ' ') |
|
| 276 | 276 | . str_replace($line_break, $line_break.$indent_unit, $this->getOperandAt(0)->toString($options)) |
| 277 | 277 | . ',' |
| 278 | 278 | . $line_break |
@@ -308,21 +308,21 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | if ($new_operand instanceof NotRule) { |
| 310 | 310 | $operands = $new_operand->getOperands(); |
| 311 | - return reset( $operands ); |
|
| 311 | + return reset($operands); |
|
| 312 | 312 | } |
| 313 | - elseif ($new_operand instanceof EqualRule && ! $this->getOption('not_equal.normalization', $contextual_options)) { |
|
| 314 | - return new NotEqualRule( $new_operand->getField(), $new_operand->getValue(), $this->options ); |
|
| 313 | + elseif ($new_operand instanceof EqualRule && !$this->getOption('not_equal.normalization', $contextual_options)) { |
|
| 314 | + return new NotEqualRule($new_operand->getField(), $new_operand->getValue(), $this->options); |
|
| 315 | 315 | } |
| 316 | - elseif ($new_operand instanceof InRule && ! $this->getOption('not_in.normalization', $contextual_options)) { |
|
| 317 | - return new NotInRule( $new_operand->getField(), $new_operand->getPossibilities(), $this->options ); |
|
| 316 | + elseif ($new_operand instanceof InRule && !$this->getOption('not_in.normalization', $contextual_options)) { |
|
| 317 | + return new NotInRule($new_operand->getField(), $new_operand->getPossibilities(), $this->options); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | try { |
| 321 | 321 | // Don't use addOperand here to allow inheritance for optimizations (e.g. NotInRule) |
| 322 | - $out = $this->setOperands( $new_operands ); |
|
| 322 | + $out = $this->setOperands($new_operands); |
|
| 323 | 323 | } |
| 324 | 324 | catch (\LogicException $e) { |
| 325 | - $out = new NotRule( $new_operand ); |
|
| 325 | + $out = new NotRule($new_operand); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | // $out->dump(); |
@@ -333,11 +333,11 @@ discard block |
||
| 333 | 333 | /** |
| 334 | 334 | * |
| 335 | 335 | */ |
| 336 | - public function hasSolution(array $contextual_options=[]) |
|
| 336 | + public function hasSolution(array $contextual_options = []) |
|
| 337 | 337 | { |
| 338 | 338 | $operand = $this->getOperandAt(0); |
| 339 | 339 | |
| 340 | - return $operand instanceof AbstractAtomicRule ? ! $operand->hasSolution($contextual_options) : true; |
|
| 340 | + return $operand instanceof AbstractAtomicRule ? !$operand->hasSolution($contextual_options) : true; |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /**/ |
@@ -59,30 +59,25 @@ discard block |
||
| 59 | 59 | new BelowRule($field, $operand->getMinimum()), |
| 60 | 60 | new EqualRule($field, $operand->getMinimum()), |
| 61 | 61 | ]); |
| 62 | - } |
|
| 63 | - elseif ($operand instanceof BelowRule) { |
|
| 62 | + } elseif ($operand instanceof BelowRule) { |
|
| 64 | 63 | // ! (v > a) : v <= a : (v < a || a = v) |
| 65 | 64 | $new_rule = new OrRule([ |
| 66 | 65 | new AboveRule($field, $operand->getMaximum()), |
| 67 | 66 | new EqualRule($field, $operand->getMaximum()), |
| 68 | 67 | ]); |
| 69 | - } |
|
| 70 | - elseif ($operand instanceof EqualRule && null === $operand->getValue()) { |
|
| 68 | + } elseif ($operand instanceof EqualRule && null === $operand->getValue()) { |
|
| 71 | 69 | $new_rule = new NotEqualRule($field, null); |
| 72 | - } |
|
| 73 | - elseif ($operand instanceof EqualRule) { |
|
| 70 | + } elseif ($operand instanceof EqualRule) { |
|
| 74 | 71 | // ! (v = a) : (v < a) || (v > a) |
| 75 | 72 | if ($this->getOption('not_equal.normalization', $current_simplification_options)) { |
| 76 | 73 | $new_rule = new OrRule([ |
| 77 | 74 | new AboveRule($field, $operand->getValue()), |
| 78 | 75 | new BelowRule($field, $operand->getValue()), |
| 79 | 76 | ]); |
| 80 | - } |
|
| 81 | - else { |
|
| 77 | + } else { |
|
| 82 | 78 | $new_rule = new NotEqualRule( $field, $operand->getValue() ); |
| 83 | 79 | } |
| 84 | - } |
|
| 85 | - elseif ($operand instanceof NotEqualRule) { |
|
| 80 | + } elseif ($operand instanceof NotEqualRule) { |
|
| 86 | 81 | $new_rule = new EqualRule( $field, $operand->getValue() ); |
| 87 | 82 | } |
| 88 | 83 | } |
@@ -135,8 +130,7 @@ discard block |
||
| 135 | 130 | $new_rule->setOperands( $combinations ) |
| 136 | 131 | // ->dump(true) |
| 137 | 132 | ; |
| 138 | - } |
|
| 139 | - elseif ($operand instanceof OrRule) { |
|
| 133 | + } elseif ($operand instanceof OrRule) { |
|
| 140 | 134 | |
| 141 | 135 | // $operand->dump(true); |
| 142 | 136 | if ( $operand instanceof InRule |
@@ -147,8 +141,7 @@ discard block |
||
| 147 | 141 | $operand->getField(), |
| 148 | 142 | $operand->getPossibilities() |
| 149 | 143 | ); |
| 150 | - } |
|
| 151 | - else { |
|
| 144 | + } else { |
|
| 152 | 145 | // ! (A || B) : !A && !B |
| 153 | 146 | // ! (A || B || C || D) : !A && !B && !C && !D |
| 154 | 147 | $new_rule = new AndRule; |
@@ -162,8 +155,7 @@ discard block |
||
| 162 | 155 | } |
| 163 | 156 | } |
| 164 | 157 | // $new_rule->dump(!true); |
| 165 | - } |
|
| 166 | - elseif ($operand instanceof NotRule) { |
|
| 158 | + } elseif ($operand instanceof NotRule) { |
|
| 167 | 159 | // ! ( ! a) : a |
| 168 | 160 | $new_rule = $operand->getOperandAt(0); |
| 169 | 161 | } |
@@ -252,8 +244,7 @@ discard block |
||
| 252 | 244 | // TODO make a dedicated cache entry for semantic array? |
| 253 | 245 | if ( ! $options['show_instance'] && ! $options['semantic']) { |
| 254 | 246 | return $this->cache['array'] = $array; |
| 255 | - } |
|
| 256 | - else { |
|
| 247 | + } else { |
|
| 257 | 248 | return $array; |
| 258 | 249 | } |
| 259 | 250 | } |
@@ -309,19 +300,16 @@ discard block |
||
| 309 | 300 | if ($new_operand instanceof NotRule) { |
| 310 | 301 | $operands = $new_operand->getOperands(); |
| 311 | 302 | return reset( $operands ); |
| 312 | - } |
|
| 313 | - elseif ($new_operand instanceof EqualRule && ! $this->getOption('not_equal.normalization', $contextual_options)) { |
|
| 303 | + } elseif ($new_operand instanceof EqualRule && ! $this->getOption('not_equal.normalization', $contextual_options)) { |
|
| 314 | 304 | return new NotEqualRule( $new_operand->getField(), $new_operand->getValue(), $this->options ); |
| 315 | - } |
|
| 316 | - elseif ($new_operand instanceof InRule && ! $this->getOption('not_in.normalization', $contextual_options)) { |
|
| 305 | + } elseif ($new_operand instanceof InRule && ! $this->getOption('not_in.normalization', $contextual_options)) { |
|
| 317 | 306 | return new NotInRule( $new_operand->getField(), $new_operand->getPossibilities(), $this->options ); |
| 318 | 307 | } |
| 319 | 308 | |
| 320 | 309 | try { |
| 321 | 310 | // Don't use addOperand here to allow inheritance for optimizations (e.g. NotInRule) |
| 322 | 311 | $out = $this->setOperands( $new_operands ); |
| 323 | - } |
|
| 324 | - catch (\LogicException $e) { |
|
| 312 | + } catch (\LogicException $e) { |
|
| 325 | 313 | $out = new NotRule( $new_operand ); |
| 326 | 314 | } |
| 327 | 315 | |