@@ -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|null |
|
45 | 45 | */ |
46 | 46 | public function negateOperand(array $current_simplification_options) |
47 | 47 | { |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @todo rename as RootifyDisjunjctions? |
185 | 185 | * @todo return $this (implements a Rule monad?) |
186 | 186 | * |
187 | - * @return OrRule copied operands with one OR at its root |
|
187 | + * @return NotRule copied operands with one OR at its root |
|
188 | 188 | */ |
189 | 189 | public function rootifyDisjunctions($simplification_options) |
190 | 190 | { |
@@ -284,6 +284,7 @@ discard block |
||
284 | 284 | * This method is meant to be used during simplification that would |
285 | 285 | * need to change the class of the current instance by a normal one. |
286 | 286 | * |
287 | + * @param AbstractRule[] $new_operands |
|
287 | 288 | * @return OrRule The current instance (of or or subclass) or a new OrRule |
288 | 289 | */ |
289 | 290 | 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 | |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | ]); |
85 | 85 | } |
86 | 86 | else { |
87 | - $new_rule = new NotEqualRule( $field, $operand->getValue() ); |
|
87 | + $new_rule = new NotEqualRule($field, $operand->getValue()); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | elseif ($operand instanceof NotEqualRule) { |
91 | - $new_rule = new EqualRule( $field, $operand->getValue() ); |
|
91 | + $new_rule = new EqualRule($field, $operand->getValue()); |
|
92 | 92 | } |
93 | 93 | elseif ($operand instanceof AndRule) { |
94 | 94 | // @see https://github.com/jclaveau/php-logical-filter/issues/40 |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | |
122 | 122 | $tmp = []; |
123 | 123 | foreach ($current_operand_possibilities->getOperands() as $current_operand_possibility) { |
124 | - $tmp[] = $current_operand_possibility->addOperand( $next_operand->copy() ); |
|
124 | + $tmp[] = $current_operand_possibility->addOperand($next_operand->copy()); |
|
125 | 125 | } |
126 | 126 | $current_operand_possibilities->setOperands($tmp); |
127 | 127 | |
128 | 128 | foreach ($next_operand_possibilities->getOperands() as $next_operand_possibility) { |
129 | 129 | $current_operand_possibilities->addOperand( |
130 | - $next_operand_possibility->addOperand( new NotRule($next_operand->copy()) ) |
|
130 | + $next_operand_possibility->addOperand(new NotRule($next_operand->copy())) |
|
131 | 131 | ); |
132 | 132 | } |
133 | 133 | } |
@@ -135,15 +135,15 @@ discard block |
||
135 | 135 | // We remove the only possibility where no rule is negated |
136 | 136 | $combinations = $current_operand_possibilities->getOperands(); |
137 | 137 | array_shift($combinations); // The first rule contains no negation |
138 | - $new_rule->setOperands( $combinations ) |
|
138 | + $new_rule->setOperands($combinations) |
|
139 | 139 | // ->dump(true) |
140 | 140 | ; |
141 | 141 | } |
142 | 142 | elseif ($operand instanceof OrRule) { |
143 | 143 | |
144 | 144 | // $operand->dump(true); |
145 | - if ( $operand instanceof InRule |
|
146 | - && ! $operand->isNormalizationAllowed($current_simplification_options) |
|
145 | + if ($operand instanceof InRule |
|
146 | + && !$operand->isNormalizationAllowed($current_simplification_options) |
|
147 | 147 | ) { |
148 | 148 | // ['not', ['field', 'in', [2, 3]]] <=> ['field', '!in', [2, 3]] |
149 | 149 | $new_rule = new NotInRule( |
@@ -161,14 +161,14 @@ discard block |
||
161 | 161 | [$sub_operand->copy()], |
162 | 162 | $current_simplification_options |
163 | 163 | ); |
164 | - $new_rule->addOperand( $negation ); |
|
164 | + $new_rule->addOperand($negation); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | // $new_rule->dump(!true); |
168 | 168 | } |
169 | 169 | else { |
170 | 170 | throw new \LogicException( |
171 | - 'Removing NotRule(' . var_export($operand, true) . ') ' |
|
171 | + 'Removing NotRule('.var_export($operand, true).') ' |
|
172 | 172 | . ' not implemented' |
173 | 173 | ); |
174 | 174 | } |
@@ -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 | foreach ($this->operands as $id => $operand) { |
198 | 198 | if ($operand instanceof AbstractOperationRule) { |
@@ -210,12 +210,12 @@ discard block |
||
210 | 210 | */ |
211 | 211 | public function unifyAtomicOperands($simplification_strategy_step = false, array $contextual_options) |
212 | 212 | { |
213 | - if ( ! $this->isNormalizationAllowed($contextual_options)) { |
|
213 | + if (!$this->isNormalizationAllowed($contextual_options)) { |
|
214 | 214 | return $this; |
215 | 215 | } |
216 | 216 | |
217 | 217 | if ($simplification_strategy_step) { |
218 | - $this->moveSimplificationStepForward( self::unify_atomic_operands, $contextual_options ); |
|
218 | + $this->moveSimplificationStepForward(self::unify_atomic_operands, $contextual_options); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | return $this; |
@@ -226,19 +226,19 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @return array |
228 | 228 | */ |
229 | - public function toArray(array $options=[]) |
|
229 | + public function toArray(array $options = []) |
|
230 | 230 | { |
231 | 231 | $default_options = [ |
232 | 232 | 'show_instance' => false, |
233 | 233 | 'semantic' => false, |
234 | 234 | ]; |
235 | 235 | foreach ($default_options as $default_option => &$default_value) { |
236 | - if ( ! isset($options[ $default_option ])) { |
|
237 | - $options[ $default_option ] = $default_value; |
|
236 | + if (!isset($options[$default_option])) { |
|
237 | + $options[$default_option] = $default_value; |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | - if ( ! $options['show_instance'] && isset($this->cache['array'])) { |
|
241 | + if (!$options['show_instance'] && isset($this->cache['array'])) { |
|
242 | 242 | return $this->cache['array']; |
243 | 243 | } |
244 | 244 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | ]; |
249 | 249 | |
250 | 250 | // TODO make a dedicated cache entry for semantic array? |
251 | - if ( ! $options['show_instance'] && ! $options['semantic']) { |
|
251 | + if (!$options['show_instance'] && !$options['semantic']) { |
|
252 | 252 | return $this->cache['array'] = $array; |
253 | 253 | } |
254 | 254 | else { |
@@ -258,10 +258,10 @@ discard block |
||
258 | 258 | |
259 | 259 | /** |
260 | 260 | */ |
261 | - public function toString(array $options=[]) |
|
261 | + public function toString(array $options = []) |
|
262 | 262 | { |
263 | 263 | $operator = self::operator; |
264 | - if ( ! $this->operands) { |
|
264 | + if (!$this->operands) { |
|
265 | 265 | return "['{$operator}']"; |
266 | 266 | } |
267 | 267 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | |
271 | 271 | $out = "['{$operator}'," |
272 | 272 | . $line_break |
273 | - . ($indent_unit ? : ' ') |
|
273 | + . ($indent_unit ?: ' ') |
|
274 | 274 | . str_replace($line_break, $line_break.$indent_unit, $this->getOperandAt(0)->toString($options)) |
275 | 275 | . ',' |
276 | 276 | . $line_break |
@@ -306,21 +306,21 @@ discard block |
||
306 | 306 | |
307 | 307 | if ($new_operand instanceof NotRule) { |
308 | 308 | $operands = $new_operand->getOperands(); |
309 | - return reset( $operands ); |
|
309 | + return reset($operands); |
|
310 | 310 | } |
311 | - elseif ($new_operand instanceof EqualRule && ! $this->getOption('not_equal.normalization', $contextual_options)) { |
|
312 | - return new NotEqualRule( $new_operand->getField(), $new_operand->getValue(), $this->options ); |
|
311 | + elseif ($new_operand instanceof EqualRule && !$this->getOption('not_equal.normalization', $contextual_options)) { |
|
312 | + return new NotEqualRule($new_operand->getField(), $new_operand->getValue(), $this->options); |
|
313 | 313 | } |
314 | - elseif ($new_operand instanceof InRule && ! $this->getOption('not_in.normalization', $contextual_options)) { |
|
315 | - return new NotInRule( $new_operand->getField(), $new_operand->getPossibilities(), $this->options ); |
|
314 | + elseif ($new_operand instanceof InRule && !$this->getOption('not_in.normalization', $contextual_options)) { |
|
315 | + return new NotInRule($new_operand->getField(), $new_operand->getPossibilities(), $this->options); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | try { |
319 | 319 | // Don't use addOperand here to allow inheritance for optimizations (e.g. NotInRule) |
320 | - $out = $this->setOperands( $new_operands ); |
|
320 | + $out = $this->setOperands($new_operands); |
|
321 | 321 | } |
322 | 322 | catch (\LogicException $e) { |
323 | - $out = new NotRule( $new_operand ); |
|
323 | + $out = new NotRule($new_operand); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | // $out->dump(); |
@@ -331,11 +331,11 @@ discard block |
||
331 | 331 | /** |
332 | 332 | * |
333 | 333 | */ |
334 | - public function hasSolution(array $contextual_options=[]) |
|
334 | + public function hasSolution(array $contextual_options = []) |
|
335 | 335 | { |
336 | 336 | $operand = $this->getOperandAt(0); |
337 | 337 | |
338 | - return $operand instanceof AbstractAtomicRule ? ! $operand->hasSolution($contextual_options) : true; |
|
338 | + return $operand instanceof AbstractAtomicRule ? !$operand->hasSolution($contextual_options) : true; |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /**/ |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | } |
181 | 181 | else { |
182 | 182 | throw new \InvalidArgumentException( |
183 | - "'mode' option must belong to ['string', 'export', 'dump'] " |
|
183 | + "'mode' option must belong to ['string', 'export', 'dump'] " |
|
184 | 184 | ."instead of " . var_export($mode, true) |
185 | 185 | ); |
186 | 186 | } |
@@ -273,9 +273,9 @@ discard block |
||
273 | 273 | } |
274 | 274 | |
275 | 275 | return hash('md4', serialize( $this->toArray(['semantic' => true]) )) // faster but longer |
276 | - .'-' |
|
277 | - .hash('md4', serialize( $this->options )) |
|
278 | - ; |
|
276 | + .'-' |
|
277 | + .hash('md4', serialize( $this->options )) |
|
278 | + ; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public static function findSymbolicOperator($english_operator) |
35 | 35 | { |
36 | - $association = array_flip( self::$ruleAliases ); |
|
37 | - if (isset($association[ $english_operator ])) { |
|
38 | - return $association[ $english_operator ]; |
|
36 | + $association = array_flip(self::$ruleAliases); |
|
37 | + if (isset($association[$english_operator])) { |
|
38 | + return $association[$english_operator]; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return $english_operator; |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | public static function findEnglishOperator($symbolic_operator) |
47 | 47 | { |
48 | 48 | $association = self::$ruleAliases; |
49 | - if (isset($association[ $symbolic_operator ])) { |
|
50 | - return $association[ $symbolic_operator ]; |
|
49 | + if (isset($association[$symbolic_operator])) { |
|
50 | + return $association[$symbolic_operator]; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | return $symbolic_operator; |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return AbstractRule |
68 | 68 | */ |
69 | - public static function generateSimpleRule($field, $type, $values, array $options=[]) |
|
69 | + public static function generateSimpleRule($field, $type, $values, array $options = []) |
|
70 | 70 | { |
71 | - $cache_key = hash('md4', serialize( func_get_args()) ); |
|
71 | + $cache_key = hash('md4', serialize(func_get_args())); |
|
72 | 72 | if (isset(self::$static_cache['rules_generation'][$cache_key])) { |
73 | 73 | return self::$static_cache['rules_generation'][$cache_key]->copy(); |
74 | 74 | } |
75 | 75 | |
76 | 76 | $ruleClass = self::getRuleClass($type); |
77 | 77 | |
78 | - return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass( $field, $values, $options ); |
|
78 | + return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass($field, $values, $options); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | . str_replace('_', '', ucwords($english_rule_operator, '_')) |
93 | 93 | . 'Rule'; |
94 | 94 | |
95 | - if ( ! class_exists( $rule_class)) { |
|
95 | + if (!class_exists($rule_class)) { |
|
96 | 96 | throw new \InvalidArgumentException( |
97 | 97 | "The class '$rule_class' corresponding to the operator " |
98 | 98 | ."'$rule_operator' / '$english_rule_operator' cannot be found." |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return $this |
123 | 123 | */ |
124 | - final public function dump($exit=false, array $options=[]) |
|
124 | + final public function dump($exit = false, array $options = []) |
|
125 | 125 | { |
126 | 126 | $default_options = [ |
127 | 127 | 'callstack_depth' => 2, |
@@ -129,18 +129,18 @@ discard block |
||
129 | 129 | // 'show_instance' => false, |
130 | 130 | ]; |
131 | 131 | foreach ($default_options as $default_option => &$default_value) { |
132 | - if ( ! isset($options[ $default_option ])) { |
|
133 | - $options[ $default_option ] = $default_value; |
|
132 | + if (!isset($options[$default_option])) { |
|
133 | + $options[$default_option] = $default_value; |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | extract($options); |
137 | 137 | |
138 | 138 | $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth); |
139 | - $caller = $bt[ $callstack_depth - 2 ]; |
|
139 | + $caller = $bt[$callstack_depth - 2]; |
|
140 | 140 | |
141 | - echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n"; |
|
141 | + echo "\n".$caller['file'].':'.$caller['line']."\n"; |
|
142 | 142 | if ('string' == $mode) { |
143 | - if ( ! isset($options['indent_unit'])) { |
|
143 | + if (!isset($options['indent_unit'])) { |
|
144 | 144 | $options['indent_unit'] = " "; |
145 | 145 | } |
146 | 146 | |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | } |
159 | 159 | } |
160 | 160 | elseif ('xdebug' == $mode) { |
161 | - if ( ! function_exists('xdebug_is_enabled')) { |
|
161 | + if (!function_exists('xdebug_is_enabled')) { |
|
162 | 162 | throw new \RuntimeException("Xdebug is not installed"); |
163 | 163 | } |
164 | - if ( ! xdebug_is_enabled()) { |
|
164 | + if (!xdebug_is_enabled()) { |
|
165 | 165 | throw new \RuntimeException("Xdebug is disabled"); |
166 | 166 | } |
167 | 167 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | else { |
182 | 182 | throw new \InvalidArgumentException( |
183 | 183 | "'mode' option must belong to ['string', 'export', 'dump'] " |
184 | - ."instead of " . var_export($mode, true) |
|
184 | + ."instead of ".var_export($mode, true) |
|
185 | 185 | ); |
186 | 186 | } |
187 | 187 | echo "\n\n"; |
@@ -236,12 +236,12 @@ discard block |
||
236 | 236 | /** |
237 | 237 | * @return string |
238 | 238 | */ |
239 | - abstract public function toString(array $options=[]); |
|
239 | + abstract public function toString(array $options = []); |
|
240 | 240 | |
241 | 241 | /** |
242 | 242 | * @return array |
243 | 243 | */ |
244 | - abstract public function toArray(array $options=[]); |
|
244 | + abstract public function toArray(array $options = []); |
|
245 | 245 | |
246 | 246 | protected $instance_id; |
247 | 247 | |
@@ -272,9 +272,9 @@ discard block |
||
272 | 272 | return $this->cache['semantic_id']; |
273 | 273 | } |
274 | 274 | |
275 | - return hash('md4', serialize( $this->toArray(['semantic' => true]) )) // faster but longer |
|
275 | + return hash('md4', serialize($this->toArray(['semantic' => true]))) // faster but longer |
|
276 | 276 | .'-' |
277 | - .hash('md4', serialize( $this->options )) |
|
277 | + .hash('md4', serialize($this->options)) |
|
278 | 278 | ; |
279 | 279 | } |
280 | 280 | |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | } |
307 | 307 | elseif ($this instanceof OrRule) { |
308 | 308 | foreach ($this->operands as $i => $operand) { |
309 | - if ( ! $operand instanceof AndRule) { |
|
309 | + if (!$operand instanceof AndRule) { |
|
310 | 310 | $this->operands[$i] = new AndRule([$operand]); |
311 | 311 | } |
312 | 312 | } |