@@ -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 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function negateOperand(array $current_simplification_options) |
48 | 48 | { |
49 | - if ( ! $this->isNormalizationAllowed($current_simplification_options)) { |
|
49 | + if (!$this->isNormalizationAllowed($current_simplification_options)) { |
|
50 | 50 | return $this; |
51 | 51 | } |
52 | 52 | |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | ]); |
81 | 81 | } |
82 | 82 | else { |
83 | - $new_rule = new NotEqualRule( $field, $operand->getValue() ); |
|
83 | + $new_rule = new NotEqualRule($field, $operand->getValue()); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | elseif ($operand instanceof NotEqualRule) { |
87 | - $new_rule = new EqualRule( $field, $operand->getValue() ); |
|
87 | + $new_rule = new EqualRule($field, $operand->getValue()); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | |
120 | 120 | $tmp = []; |
121 | 121 | foreach ($current_operand_possibilities->getOperands() as $current_operand_possibility) { |
122 | - $tmp[] = $current_operand_possibility->addOperand( $next_operand->copy() ); |
|
122 | + $tmp[] = $current_operand_possibility->addOperand($next_operand->copy()); |
|
123 | 123 | } |
124 | 124 | $current_operand_possibilities->setOperands($tmp); |
125 | 125 | |
126 | 126 | foreach ($next_operand_possibilities->getOperands() as $next_operand_possibility) { |
127 | 127 | $current_operand_possibilities->addOperand( |
128 | - $next_operand_possibility->addOperand( new NotRule($next_operand->copy()) ) |
|
128 | + $next_operand_possibility->addOperand(new NotRule($next_operand->copy())) |
|
129 | 129 | ); |
130 | 130 | } |
131 | 131 | } |
@@ -133,15 +133,15 @@ discard block |
||
133 | 133 | // We remove the only possibility where no rule is negated |
134 | 134 | $combinations = $current_operand_possibilities->getOperands(); |
135 | 135 | array_shift($combinations); // The first rule contains no negation |
136 | - $new_rule->setOperands( $combinations ) |
|
136 | + $new_rule->setOperands($combinations) |
|
137 | 137 | // ->dump(true) |
138 | 138 | ; |
139 | 139 | } |
140 | 140 | elseif ($operand instanceof OrRule) { |
141 | 141 | |
142 | 142 | // $operand->dump(true); |
143 | - if ( $operand instanceof InRule |
|
144 | - && ! $operand->isNormalizationAllowed($current_simplification_options) |
|
143 | + if ($operand instanceof InRule |
|
144 | + && !$operand->isNormalizationAllowed($current_simplification_options) |
|
145 | 145 | ) { |
146 | 146 | // ['not', ['field', 'in', [2, 3]]] <=> ['field', '!in', [2, 3]] |
147 | 147 | $new_rule = new NotInRule( |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | [$sub_operand->copy()], |
160 | 160 | $current_simplification_options |
161 | 161 | ); |
162 | - $new_rule->addOperand( $negation ); |
|
162 | + $new_rule->addOperand($negation); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | // $new_rule->dump(!true); |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | $new_rule = $operand->getOperandAt(0); |
170 | 170 | } |
171 | 171 | |
172 | - if ( ! isset($new_rule)) { |
|
172 | + if (!isset($new_rule)) { |
|
173 | 173 | throw new \LogicException( |
174 | - 'Removing NotRule(' . var_export($operand, true) . ') ' |
|
174 | + 'Removing NotRule('.var_export($operand, true).') ' |
|
175 | 175 | . ' not implemented' |
176 | 176 | ); |
177 | 177 | } |
@@ -188,11 +188,11 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function rootifyDisjunctions($simplification_options) |
190 | 190 | { |
191 | - if ( ! $this->isNormalizationAllowed($simplification_options)) { |
|
191 | + if (!$this->isNormalizationAllowed($simplification_options)) { |
|
192 | 192 | return $this; |
193 | 193 | } |
194 | 194 | |
195 | - $this->moveSimplificationStepForward( self::rootify_disjunctions, $simplification_options ); |
|
195 | + $this->moveSimplificationStepForward(self::rootify_disjunctions, $simplification_options); |
|
196 | 196 | |
197 | 197 | // not implemented |
198 | 198 | |
@@ -206,12 +206,12 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function unifyAtomicOperands($simplification_strategy_step = false, array $contextual_options) |
208 | 208 | { |
209 | - if ( ! $this->isNormalizationAllowed($contextual_options)) { |
|
209 | + if (!$this->isNormalizationAllowed($contextual_options)) { |
|
210 | 210 | return $this; |
211 | 211 | } |
212 | 212 | |
213 | 213 | if ($simplification_strategy_step) { |
214 | - $this->moveSimplificationStepForward( self::unify_atomic_operands, $contextual_options ); |
|
214 | + $this->moveSimplificationStepForward(self::unify_atomic_operands, $contextual_options); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | return $this; |
@@ -222,19 +222,19 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @return array |
224 | 224 | */ |
225 | - public function toArray(array $options=[]) |
|
225 | + public function toArray(array $options = []) |
|
226 | 226 | { |
227 | 227 | $default_options = [ |
228 | 228 | 'show_instance' => false, |
229 | 229 | 'semantic' => false, |
230 | 230 | ]; |
231 | 231 | foreach ($default_options as $default_option => &$default_value) { |
232 | - if ( ! isset($options[ $default_option ])) { |
|
233 | - $options[ $default_option ] = $default_value; |
|
232 | + if (!isset($options[$default_option])) { |
|
233 | + $options[$default_option] = $default_value; |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
237 | - if ( ! $options['show_instance'] && isset($this->cache['array'])) { |
|
237 | + if (!$options['show_instance'] && isset($this->cache['array'])) { |
|
238 | 238 | return $this->cache['array']; |
239 | 239 | } |
240 | 240 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | ]; |
245 | 245 | |
246 | 246 | // TODO make a dedicated cache entry for semantic array? |
247 | - if ( ! $options['show_instance'] && ! $options['semantic']) { |
|
247 | + if (!$options['show_instance'] && !$options['semantic']) { |
|
248 | 248 | return $this->cache['array'] = $array; |
249 | 249 | } |
250 | 250 | else { |
@@ -254,10 +254,10 @@ discard block |
||
254 | 254 | |
255 | 255 | /** |
256 | 256 | */ |
257 | - public function toString(array $options=[]) |
|
257 | + public function toString(array $options = []) |
|
258 | 258 | { |
259 | 259 | $operator = self::operator; |
260 | - if ( ! $this->operands) { |
|
260 | + if (!$this->operands) { |
|
261 | 261 | return "['{$operator}']"; |
262 | 262 | } |
263 | 263 | |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | |
267 | 267 | $out = "['{$operator}'," |
268 | 268 | . $line_break |
269 | - . ($indent_unit ? : ' ') |
|
269 | + . ($indent_unit ?: ' ') |
|
270 | 270 | . str_replace($line_break, $line_break.$indent_unit, $this->getOperandAt(0)->toString($options)) |
271 | 271 | . ',' |
272 | 272 | . $line_break |
@@ -304,13 +304,13 @@ discard block |
||
304 | 304 | |
305 | 305 | if ($new_operand instanceof NotRule) { |
306 | 306 | $operands = $new_operand->getOperands(); |
307 | - return reset( $operands ); |
|
307 | + return reset($operands); |
|
308 | 308 | } |
309 | - elseif ($new_operand instanceof EqualRule && ! $this->getOption('not_equal.normalization', $contextual_options)) { |
|
310 | - return new NotEqualRule( $new_operand->getField(), $new_operand->getValue(), $this->options ); |
|
309 | + elseif ($new_operand instanceof EqualRule && !$this->getOption('not_equal.normalization', $contextual_options)) { |
|
310 | + return new NotEqualRule($new_operand->getField(), $new_operand->getValue(), $this->options); |
|
311 | 311 | } |
312 | - elseif ($new_operand instanceof InRule && ! $this->getOption('not_in.normalization', $contextual_options)) { |
|
313 | - return new NotInRule( $new_operand->getField(), $new_operand->getPossibilities(), $this->options ); |
|
312 | + elseif ($new_operand instanceof InRule && !$this->getOption('not_in.normalization', $contextual_options)) { |
|
313 | + return new NotInRule($new_operand->getField(), $new_operand->getPossibilities(), $this->options); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | // Don't use addOperand here to allow inheritance for optimizations (e.g. NotInRule) |
@@ -324,11 +324,11 @@ discard block |
||
324 | 324 | /** |
325 | 325 | * |
326 | 326 | */ |
327 | - public function hasSolution(array $contextual_options=[]) |
|
327 | + public function hasSolution(array $contextual_options = []) |
|
328 | 328 | { |
329 | 329 | $operand = $this->getOperandAt(0); |
330 | 330 | |
331 | - return $operand instanceof AbstractAtomicRule ? ! $operand->hasSolution($contextual_options) : true; |
|
331 | + return $operand instanceof AbstractAtomicRule ? !$operand->hasSolution($contextual_options) : true; |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /**/ |
@@ -60,30 +60,25 @@ discard block |
||
60 | 60 | new BelowRule($field, $operand->getLowerLimit()), |
61 | 61 | new EqualRule($field, $operand->getLowerLimit()), |
62 | 62 | ]); |
63 | - } |
|
64 | - elseif ($operand instanceof BelowRule) { |
|
63 | + } elseif ($operand instanceof BelowRule) { |
|
65 | 64 | // ! (v > a) : v <= a : (v < a || a = v) |
66 | 65 | $new_rule = new OrRule([ |
67 | 66 | new AboveRule($field, $operand->getUpperLimit()), |
68 | 67 | new EqualRule($field, $operand->getUpperLimit()), |
69 | 68 | ]); |
70 | - } |
|
71 | - elseif ($operand instanceof EqualRule && null === $operand->getValue()) { |
|
69 | + } elseif ($operand instanceof EqualRule && null === $operand->getValue()) { |
|
72 | 70 | $new_rule = new NotEqualRule($field, null); |
73 | - } |
|
74 | - elseif ($operand instanceof EqualRule) { |
|
71 | + } elseif ($operand instanceof EqualRule) { |
|
75 | 72 | // ! (v = a) : (v < a) || (v > a) |
76 | 73 | if ($this->getOption('not_equal.normalization', $current_simplification_options)) { |
77 | 74 | $new_rule = new OrRule([ |
78 | 75 | new AboveRule($field, $operand->getValue()), |
79 | 76 | new BelowRule($field, $operand->getValue()), |
80 | 77 | ]); |
81 | - } |
|
82 | - else { |
|
78 | + } else { |
|
83 | 79 | $new_rule = new NotEqualRule( $field, $operand->getValue() ); |
84 | 80 | } |
85 | - } |
|
86 | - elseif ($operand instanceof NotEqualRule) { |
|
81 | + } elseif ($operand instanceof NotEqualRule) { |
|
87 | 82 | $new_rule = new EqualRule( $field, $operand->getValue() ); |
88 | 83 | } |
89 | 84 | } |
@@ -136,8 +131,7 @@ discard block |
||
136 | 131 | $new_rule->setOperands( $combinations ) |
137 | 132 | // ->dump(true) |
138 | 133 | ; |
139 | - } |
|
140 | - elseif ($operand instanceof OrRule) { |
|
134 | + } elseif ($operand instanceof OrRule) { |
|
141 | 135 | |
142 | 136 | // $operand->dump(true); |
143 | 137 | if ( $operand instanceof InRule |
@@ -148,8 +142,7 @@ discard block |
||
148 | 142 | $operand->getField(), |
149 | 143 | $operand->getPossibilities() |
150 | 144 | ); |
151 | - } |
|
152 | - else { |
|
145 | + } else { |
|
153 | 146 | // ! (A || B) : !A && !B |
154 | 147 | // ! (A || B || C || D) : !A && !B && !C && !D |
155 | 148 | $new_rule = new AndRule; |
@@ -163,8 +156,7 @@ discard block |
||
163 | 156 | } |
164 | 157 | } |
165 | 158 | // $new_rule->dump(!true); |
166 | - } |
|
167 | - elseif ($operand instanceof NotRule) { |
|
159 | + } elseif ($operand instanceof NotRule) { |
|
168 | 160 | // ! ( ! a) : a |
169 | 161 | $new_rule = $operand->getOperandAt(0); |
170 | 162 | } |
@@ -246,8 +238,7 @@ discard block |
||
246 | 238 | // TODO make a dedicated cache entry for semantic array? |
247 | 239 | if ( ! $options['show_instance'] && ! $options['semantic']) { |
248 | 240 | return $this->cache['array'] = $array; |
249 | - } |
|
250 | - else { |
|
241 | + } else { |
|
251 | 242 | return $array; |
252 | 243 | } |
253 | 244 | } |
@@ -305,11 +296,9 @@ discard block |
||
305 | 296 | if ($new_operand instanceof NotRule) { |
306 | 297 | $operands = $new_operand->getOperands(); |
307 | 298 | return reset( $operands ); |
308 | - } |
|
309 | - elseif ($new_operand instanceof EqualRule && ! $this->getOption('not_equal.normalization', $contextual_options)) { |
|
299 | + } elseif ($new_operand instanceof EqualRule && ! $this->getOption('not_equal.normalization', $contextual_options)) { |
|
310 | 300 | return new NotEqualRule( $new_operand->getField(), $new_operand->getValue(), $this->options ); |
311 | - } |
|
312 | - elseif ($new_operand instanceof InRule && ! $this->getOption('not_in.normalization', $contextual_options)) { |
|
301 | + } elseif ($new_operand instanceof InRule && ! $this->getOption('not_in.normalization', $contextual_options)) { |
|
313 | 302 | return new NotInRule( $new_operand->getField(), $new_operand->getPossibilities(), $this->options ); |
314 | 303 | } |
315 | 304 |