@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! function_exists('spl_object_id')) { |
|
2 | +if (!function_exists('spl_object_id')) { |
|
3 | 3 | /** |
4 | 4 | * @see https://secure.php.net/manual/en/function.spl-object-id.php |
5 | 5 | * This method doesn't exist before PHP 7.2.0 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | } |
13 | 13 | } |
14 | 14 | |
15 | -if ( ! function_exists('is_iterable')) { |
|
15 | +if (!function_exists('is_iterable')) { |
|
16 | 16 | /** |
17 | 17 | * @see https://github.com/symfony/polyfill-php71/commit/36004d119352f4506398032259a08e4ca9607285 |
18 | 18 | * This method doesn't exist before PHP 7.1.0 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @param LogicalFilter $filter |
20 | 20 | */ |
21 | - public function convert( LogicalFilter $filter ) |
|
21 | + public function convert(LogicalFilter $filter) |
|
22 | 22 | { |
23 | 23 | $rootOr = $filter->simplify(['force_logical_core' => true])->getRules(); |
24 | 24 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | return $this; |
28 | 28 | } |
29 | 29 | |
30 | - if ( ! $rootOr->hasSolution()) { |
|
30 | + if (!$rootOr->hasSolution()) { |
|
31 | 31 | return $this; |
32 | 32 | } |
33 | 33 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | ); |
46 | 46 | } |
47 | 47 | |
48 | - $operandsByFields[ $field ][ $operator ] = $operandsOfOperator[0]; |
|
48 | + $operandsByFields[$field][$operator] = $operandsOfOperator[0]; |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * @return string $field |
25 | 25 | */ |
26 | - final public function setField( $field ) |
|
26 | + final public function setField($field) |
|
27 | 27 | { |
28 | - if ( ! is_scalar($field)) { |
|
28 | + if (!is_scalar($field)) { |
|
29 | 29 | throw new \InvalidArgumentEXception( |
30 | 30 | "\$field property of a logical rule must be a scalar contrary to: " |
31 | 31 | .var_export($field, true) |
@@ -49,17 +49,17 @@ discard block |
||
49 | 49 | final public function renameField($renamings) |
50 | 50 | { |
51 | 51 | if (is_callable($renamings)) { |
52 | - $this->setField( call_user_func($renamings, $this->field) ); |
|
52 | + $this->setField(call_user_func($renamings, $this->field)); |
|
53 | 53 | } |
54 | 54 | elseif (is_array($renamings)) { |
55 | 55 | if (isset($renamings[$this->field])) { |
56 | - $this->setField( $renamings[$this->field] ); |
|
56 | + $this->setField($renamings[$this->field]); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | else { |
60 | 60 | throw new \InvalidArgumentException( |
61 | 61 | "\$renamings MUST be a callable or an associative array " |
62 | - ."instead of: " . var_export($renamings, true) |
|
62 | + ."instead of: ".var_export($renamings, true) |
|
63 | 63 | ); |
64 | 64 | } |
65 | 65 |
@@ -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; |
@@ -65,16 +65,16 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return $this |
67 | 67 | */ |
68 | - public static function generateSimpleRule($field, $type, $values, array $options=[]) |
|
68 | + public static function generateSimpleRule($field, $type, $values, array $options = []) |
|
69 | 69 | { |
70 | - $cache_key = hash('md4', serialize( func_get_args()) ); |
|
70 | + $cache_key = hash('md4', serialize(func_get_args())); |
|
71 | 71 | if (isset(self::$static_cache['rules_generation'][$cache_key])) { |
72 | 72 | return self::$static_cache['rules_generation'][$cache_key]->copy(); |
73 | 73 | } |
74 | 74 | |
75 | 75 | $ruleClass = self::getRuleClass($type); |
76 | 76 | |
77 | - return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass( $field, $values, $options ); |
|
77 | + return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass($field, $values, $options); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | . str_replace('_', '', ucwords($english_rule_operator, '_')) |
92 | 92 | . 'Rule'; |
93 | 93 | |
94 | - if ( ! class_exists( $rule_class)) { |
|
94 | + if (!class_exists($rule_class)) { |
|
95 | 95 | throw new \InvalidArgumentException( |
96 | 96 | "The class '$rule_class' corresponding to the operator " |
97 | 97 | ."'$rule_operator' / '$english_rule_operator' cannot be found." |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return $this |
122 | 122 | */ |
123 | - final public function dump($exit=false, array $options=[]) |
|
123 | + final public function dump($exit = false, array $options = []) |
|
124 | 124 | { |
125 | 125 | $default_options = [ |
126 | 126 | 'callstack_depth' => 2, |
@@ -128,18 +128,18 @@ discard block |
||
128 | 128 | // 'show_instance' => false, |
129 | 129 | ]; |
130 | 130 | foreach ($default_options as $default_option => &$default_value) { |
131 | - if ( ! isset($options[ $default_option ])) { |
|
132 | - $options[ $default_option ] = $default_value; |
|
131 | + if (!isset($options[$default_option])) { |
|
132 | + $options[$default_option] = $default_value; |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | extract($options); |
136 | 136 | |
137 | 137 | $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth); |
138 | - $caller = $bt[ $callstack_depth - 2 ]; |
|
138 | + $caller = $bt[$callstack_depth - 2]; |
|
139 | 139 | |
140 | - echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n"; |
|
140 | + echo "\n".$caller['file'].':'.$caller['line']."\n"; |
|
141 | 141 | if ($mode == 'string') { |
142 | - if ( ! isset($options['indent_unit'])) { |
|
142 | + if (!isset($options['indent_unit'])) { |
|
143 | 143 | $options['indent_unit'] = " "; |
144 | 144 | } |
145 | 145 | |
@@ -157,10 +157,10 @@ discard block |
||
157 | 157 | } |
158 | 158 | } |
159 | 159 | elseif ($mode == 'xdebug') { |
160 | - if ( ! function_exists('xdebug_is_enabled')) { |
|
160 | + if (!function_exists('xdebug_is_enabled')) { |
|
161 | 161 | throw new \RuntimeException("Xdebug is not installed"); |
162 | 162 | } |
163 | - if ( ! xdebug_is_enabled()) { |
|
163 | + if (!xdebug_is_enabled()) { |
|
164 | 164 | throw new \RuntimeException("Xdebug is disabled"); |
165 | 165 | } |
166 | 166 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | else { |
181 | 181 | throw new \InvalidArgumentException( |
182 | 182 | "'mode' option must belong to ['string', 'export', 'dump'] " |
183 | - ."instead of " . var_export($mode, true) |
|
183 | + ."instead of ".var_export($mode, true) |
|
184 | 184 | ); |
185 | 185 | } |
186 | 186 | echo "\n\n"; |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | } |
263 | 263 | |
264 | 264 | // return hash('crc32b', serialize( $this->toArray() )); |
265 | - return hash('md4', serialize( $this->toArray(['semantic' => true]) )) // faster but longer |
|
265 | + return hash('md4', serialize($this->toArray(['semantic' => true]))) // faster but longer |
|
266 | 266 | .'-' |
267 | - .hash('md4', serialize( $this->options )) |
|
267 | + .hash('md4', serialize($this->options)) |
|
268 | 268 | ; |
269 | 269 | } |
270 | 270 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | } |
297 | 297 | elseif ($this instanceof OrRule) { |
298 | 298 | foreach ($this->operands as $i => $operand) { |
299 | - if ( ! $operand instanceof AndRule) { |
|
299 | + if (!$operand instanceof AndRule) { |
|
300 | 300 | $this->operands[$i] = new AndRule([$operand]); |
301 | 301 | } |
302 | 302 | } |
@@ -144,8 +144,7 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | echo ($this->toString($options)); |
147 | - } |
|
148 | - elseif ($mode == 'dump') { |
|
147 | + } elseif ($mode == 'dump') { |
|
149 | 148 | if ($xdebug_enabled = ini_get('xdebug.overload_var_dump')) { |
150 | 149 | ini_set('xdebug.overload_var_dump', 0); |
151 | 150 | } |
@@ -155,8 +154,7 @@ discard block |
||
155 | 154 | if ($xdebug_enabled) { |
156 | 155 | ini_set('xdebug.overload_var_dump', 1); |
157 | 156 | } |
158 | - } |
|
159 | - elseif ($mode == 'xdebug') { |
|
157 | + } elseif ($mode == 'xdebug') { |
|
160 | 158 | if ( ! function_exists('xdebug_is_enabled')) { |
161 | 159 | throw new \RuntimeException("Xdebug is not installed"); |
162 | 160 | } |
@@ -173,11 +171,9 @@ discard block |
||
173 | 171 | if ($xdebug_enabled) { |
174 | 172 | ini_set('xdebug.overload_var_dump', 0); |
175 | 173 | } |
176 | - } |
|
177 | - elseif ($mode == 'export') { |
|
174 | + } elseif ($mode == 'export') { |
|
178 | 175 | var_export($this->toArray($options)); |
179 | - } |
|
180 | - else { |
|
176 | + } else { |
|
181 | 177 | throw new \InvalidArgumentException( |
182 | 178 | "'mode' option must belong to ['string', 'export', 'dump'] " |
183 | 179 | ."instead of " . var_export($mode, true) |
@@ -288,21 +284,18 @@ discard block |
||
288 | 284 | $this |
289 | 285 | ]) |
290 | 286 | ]); |
291 | - } |
|
292 | - elseif ($this instanceof AndRule) { |
|
287 | + } elseif ($this instanceof AndRule) { |
|
293 | 288 | $ruleTree = new OrRule([ |
294 | 289 | $this |
295 | 290 | ]); |
296 | - } |
|
297 | - elseif ($this instanceof OrRule) { |
|
291 | + } elseif ($this instanceof OrRule) { |
|
298 | 292 | foreach ($this->operands as $i => $operand) { |
299 | 293 | if ( ! $operand instanceof AndRule) { |
300 | 294 | $this->operands[$i] = new AndRule([$operand]); |
301 | 295 | } |
302 | 296 | } |
303 | 297 | $ruleTree = $this; |
304 | - } |
|
305 | - else { |
|
298 | + } else { |
|
306 | 299 | throw new \LogicException( |
307 | 300 | "Unhandled type of simplified rules provided for conversion: " |
308 | 301 | .$this |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param string $field The field to apply the rule on. |
19 | 19 | * @param array $value The value the field can equal to. |
20 | 20 | */ |
21 | - public function __construct( $field, $value, array $options=[] ) |
|
21 | + public function __construct($field, $value, array $options = []) |
|
22 | 22 | { |
23 | 23 | $this->field = $field; |
24 | 24 | $this->value = $value; |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | /** |
31 | 31 | */ |
32 | - public function isNormalizationAllowed(array $contextual_options=[]) |
|
32 | + public function isNormalizationAllowed(array $contextual_options = []) |
|
33 | 33 | { |
34 | 34 | $operand = $this->getOperandAt(0); |
35 | 35 | |
@@ -58,18 +58,18 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return array |
60 | 60 | */ |
61 | - public function toArray(array $options=[]) |
|
61 | + public function toArray(array $options = []) |
|
62 | 62 | { |
63 | 63 | $default_options = [ |
64 | 64 | 'show_instance' => false, |
65 | 65 | ]; |
66 | 66 | foreach ($default_options as $default_option => &$default_value) { |
67 | - if ( ! isset($options[ $default_option ])) { |
|
68 | - $options[ $default_option ] = $default_value; |
|
67 | + if (!isset($options[$default_option])) { |
|
68 | + $options[$default_option] = $default_value; |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | - if ( ! $options['show_instance'] && isset($this->cache['array'])) { |
|
72 | + if (!$options['show_instance'] && isset($this->cache['array'])) { |
|
73 | 73 | return $this->cache['array']; |
74 | 74 | } |
75 | 75 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $this->getValue(), |
80 | 80 | ]; |
81 | 81 | |
82 | - if ( ! $options['show_instance']) { |
|
82 | + if (!$options['show_instance']) { |
|
83 | 83 | return $this->cache['array'] = $array; |
84 | 84 | } |
85 | 85 | else { |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | |
90 | 90 | /** |
91 | 91 | */ |
92 | - public function toString(array $options=[]) |
|
92 | + public function toString(array $options = []) |
|
93 | 93 | { |
94 | - if ( ! empty($this->cache['string'])) { |
|
94 | + if (!empty($this->cache['string'])) { |
|
95 | 95 | return $this->cache['string']; |
96 | 96 | } |
97 | 97 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return bool |
110 | 110 | */ |
111 | - public function hasSolution(array $simplification_options=[]) |
|
111 | + public function hasSolution(array $simplification_options = []) |
|
112 | 112 | { |
113 | 113 | return true; |
114 | 114 | } |
@@ -81,8 +81,7 @@ |
||
81 | 81 | |
82 | 82 | if ( ! $options['show_instance']) { |
83 | 83 | return $this->cache['array'] = $array; |
84 | - } |
|
85 | - else { |
|
84 | + } else { |
|
86 | 85 | return $array; |
87 | 86 | } |
88 | 87 | } |
@@ -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 && $this->current_simplification_step !== null) { |
|
140 | + if (!$force && $this->current_simplification_step !== null) { |
|
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 | |
@@ -227,14 +227,14 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @return $this; |
229 | 229 | */ |
230 | - public function cleanOperations($simplification_options, $recurse=true) |
|
230 | + public function cleanOperations($simplification_options, $recurse = true) |
|
231 | 231 | { |
232 | 232 | if ($recurse) { |
233 | 233 | foreach ($this->operands as $i => $operand) { |
234 | - if ( $operand instanceof AbstractOperationRule |
|
235 | - && ! $operand instanceof InRule |
|
236 | - && ! $operand instanceof NotEqualRule |
|
237 | - && ! $operand instanceof NotInRule |
|
234 | + if ($operand instanceof AbstractOperationRule |
|
235 | + && !$operand instanceof InRule |
|
236 | + && !$operand instanceof NotEqualRule |
|
237 | + && !$operand instanceof NotInRule |
|
238 | 238 | ) { |
239 | 239 | $this->operands[$i] = $operand->cleanOperations($simplification_options); |
240 | 240 | } |
@@ -273,11 +273,11 @@ discard block |
||
273 | 273 | public function removeMonooperandOperationsOperands(array $simplification_options) |
274 | 274 | { |
275 | 275 | foreach ($this->operands as $i => $operand) { |
276 | - if ( ! $operand instanceof AbstractOperationRule || $operand instanceof NotRule) { |
|
276 | + if (!$operand instanceof AbstractOperationRule || $operand instanceof NotRule) { |
|
277 | 277 | continue; |
278 | 278 | } |
279 | 279 | |
280 | - if ($operand instanceof InRule && ! $operand->isNormalizationAllowed($simplification_options)) { |
|
280 | + if ($operand instanceof InRule && !$operand->isNormalizationAllowed($simplification_options)) { |
|
281 | 281 | $count = count($operand->getPossibilities()); |
282 | 282 | } |
283 | 283 | else { |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
297 | - return ! empty($has_been_changed); |
|
297 | + return !empty($has_been_changed); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -305,12 +305,12 @@ discard block |
||
305 | 305 | public function unifyAtomicOperands($simplification_strategy_step = false, array $contextual_options) |
306 | 306 | { |
307 | 307 | if ($simplification_strategy_step) { |
308 | - $this->moveSimplificationStepForward( self::unify_atomic_operands, $contextual_options ); |
|
308 | + $this->moveSimplificationStepForward(self::unify_atomic_operands, $contextual_options); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | // $this->dump(true); |
312 | 312 | |
313 | - if ( ! $this->isNormalizationAllowed($contextual_options)) { |
|
313 | + if (!$this->isNormalizationAllowed($contextual_options)) { |
|
314 | 314 | return $this; |
315 | 315 | } |
316 | 316 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | catch (\Exception $e) { |
342 | 342 | VisibilityViolator::setHiddenProperty( |
343 | 343 | $e, 'message', |
344 | - $e->getMessage() . "\n" . var_export($operandsByOperator, true) |
|
344 | + $e->getMessage()."\n".var_export($operandsByOperator, true) |
|
345 | 345 | ); |
346 | 346 | |
347 | 347 | throw $e; |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
352 | - return $this->setOperandsOrReplaceByOperation( $unifiedOperands, $contextual_options ); |
|
352 | + return $this->setOperandsOrReplaceByOperation($unifiedOperands, $contextual_options); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | private static $simplification_cache = []; |
@@ -365,13 +365,13 @@ discard block |
||
365 | 365 | * |
366 | 366 | * @return AbstractRule the simplified rule |
367 | 367 | */ |
368 | - final public function simplify($options=[]) |
|
368 | + final public function simplify($options = []) |
|
369 | 369 | { |
370 | - $step_to_stop_before = ! empty($options['stop_before']) ? $options['stop_before'] : null; |
|
371 | - $step_to_stop_after = ! empty($options['stop_after']) ? $options['stop_after'] : null; |
|
372 | - $force_logical_core = ! empty($options['force_logical_core']) ? $options['force_logical_core'] : false; |
|
370 | + $step_to_stop_before = !empty($options['stop_before']) ? $options['stop_before'] : null; |
|
371 | + $step_to_stop_after = !empty($options['stop_after']) ? $options['stop_after'] : null; |
|
372 | + $force_logical_core = !empty($options['force_logical_core']) ? $options['force_logical_core'] : false; |
|
373 | 373 | |
374 | - if ($step_to_stop_before && ! in_array($step_to_stop_before, self::simplification_steps)) { |
|
374 | + if ($step_to_stop_before && !in_array($step_to_stop_before, self::simplification_steps)) { |
|
375 | 375 | throw new \InvalidArgumentException( |
376 | 376 | "Invalid simplification step to stop at: ".$step_to_stop_before |
377 | 377 | ); |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | // $instance->dump(true); |
407 | 407 | |
408 | 408 | if ($step_to_stop_after == self::remove_negations || |
409 | - $step_to_stop_before == self::rootify_disjunctions ) { |
|
409 | + $step_to_stop_before == self::rootify_disjunctions) { |
|
410 | 410 | return $instance; |
411 | 411 | } |
412 | 412 | |
@@ -418,18 +418,18 @@ discard block |
||
418 | 418 | // $instance->dump(true); |
419 | 419 | |
420 | 420 | if ($step_to_stop_after == self::rootify_disjunctions || |
421 | - $step_to_stop_before == self::unify_atomic_operands ) { |
|
421 | + $step_to_stop_before == self::unify_atomic_operands) { |
|
422 | 422 | return $instance; |
423 | 423 | } |
424 | 424 | |
425 | - if ( ! $instance instanceof AbstractAtomicRule) { |
|
425 | + if (!$instance instanceof AbstractAtomicRule) { |
|
426 | 426 | $instance->cleanOperations($options); |
427 | 427 | $instance->unifyAtomicOperands(true, $options); |
428 | 428 | |
429 | 429 | // $instance->dump(true); |
430 | 430 | |
431 | 431 | if ($step_to_stop_after == self::unify_atomic_operands || |
432 | - $step_to_stop_before == self::remove_invalid_branches ) { |
|
432 | + $step_to_stop_before == self::remove_invalid_branches) { |
|
433 | 433 | return $instance; |
434 | 434 | } |
435 | 435 | |
@@ -446,8 +446,8 @@ discard block |
||
446 | 446 | // last non recursive clean |
447 | 447 | // TODO kind of monad|become|cese |
448 | 448 | //@see https://github.com/jclaveau/php-logical-filter/issues/20 |
449 | - if ($instance instanceof AndRule || $instance instanceof OrRule ) { |
|
450 | - if ( ! $instance->getOperands()) { |
|
449 | + if ($instance instanceof AndRule || $instance instanceof OrRule) { |
|
450 | + if (!$instance->getOperands()) { |
|
451 | 451 | return $instance; |
452 | 452 | } |
453 | 453 | |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | $instance = $instance->forceLogicalCore(); |
467 | 467 | // for the simplification status at |
468 | 468 | foreach ($operands = $instance->getOperands() as $andOperand) { |
469 | - if ( ! $andOperand instanceof AndRule) { |
|
469 | + if (!$andOperand instanceof AndRule) { |
|
470 | 470 | throw new \LogicException( |
471 | 471 | "A rule is intended to be an and case: \n" |
472 | 472 | .$andOperand |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | |
487 | 487 | $cache_keys[] = $instance->getSemanticId().'-'.$options_id; |
488 | 488 | foreach ($cache_keys as $cache_key) { |
489 | - self::$simplification_cache[ $cache_key ] = $instance; |
|
489 | + self::$simplification_cache[$cache_key] = $instance; |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | return $instance->copy(); |
@@ -509,15 +509,15 @@ discard block |
||
509 | 509 | // For FilteredValue and FilteredKey |
510 | 510 | $field = (string) $field; |
511 | 511 | |
512 | - if ( ! isset($operandsByFields[ $field ])) { |
|
513 | - $operandsByFields[ $field ] = []; |
|
512 | + if (!isset($operandsByFields[$field])) { |
|
513 | + $operandsByFields[$field] = []; |
|
514 | 514 | } |
515 | 515 | |
516 | - if ( ! isset($operandsByFields[ $field ][ $operand::operator ])) { |
|
517 | - $operandsByFields[ $field ][ $operand::operator ] = []; |
|
516 | + if (!isset($operandsByFields[$field][$operand::operator])) { |
|
517 | + $operandsByFields[$field][$operand::operator] = []; |
|
518 | 518 | } |
519 | 519 | |
520 | - $operandsByFields[ $field ][ $operand::operator ][] = $operand; |
|
520 | + $operandsByFields[$field][$operand::operator][] = $operand; |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | return $operandsByFields; |
@@ -540,15 +540,15 @@ discard block |
||
540 | 540 | // For FilteredValue and FilteredKey |
541 | 541 | $field = (string) $field; |
542 | 542 | |
543 | - if ( ! isset($operandsByFields[ $field ])) { |
|
544 | - $operandsByFields[ $field ] = []; |
|
543 | + if (!isset($operandsByFields[$field])) { |
|
544 | + $operandsByFields[$field] = []; |
|
545 | 545 | } |
546 | 546 | |
547 | - if ( ! isset($operandsByFields[ $field ][ $operand::operator ])) { |
|
548 | - $operandsByFields[ $field ][ $operand::operator ] = []; |
|
547 | + if (!isset($operandsByFields[$field][$operand::operator])) { |
|
548 | + $operandsByFields[$field][$operand::operator] = []; |
|
549 | 549 | } |
550 | 550 | |
551 | - $operandsByFields[ $field ][ $operand::operator ][] = $operand; |
|
551 | + $operandsByFields[$field][$operand::operator][] = $operand; |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | return $operandsByFields; |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | * |
587 | 587 | * @return AbstractRule|null The operand if it exists or null |
588 | 588 | */ |
589 | - protected function getOperandAt($index=0) |
|
589 | + protected function getOperandAt($index = 0) |
|
590 | 590 | { |
591 | 591 | $operands = array_values($this->operands); |
592 | 592 | if (isset($operands[$index])) { |
@@ -111,8 +111,7 @@ discard block |
||
111 | 111 | foreach ($this->operands as $operand) { |
112 | 112 | if (method_exists($operand, 'renameField')) { |
113 | 113 | $operand->renameField($renamings); |
114 | - } |
|
115 | - else { |
|
114 | + } else { |
|
116 | 115 | $operand->renameFields($renamings); |
117 | 116 | } |
118 | 117 | } |
@@ -146,8 +145,7 @@ discard block |
||
146 | 145 | if ( $current_index >= $target_index ) { |
147 | 146 | // allow recall of previous step without going back |
148 | 147 | return; |
149 | - } |
|
150 | - elseif ( $current_index < $target_index - 1 ) { |
|
148 | + } elseif ( $current_index < $target_index - 1 ) { |
|
151 | 149 | throw new \LogicException( |
152 | 150 | "$step_to_go_to MUST be fullfilled after " . self::simplification_steps[$target_index - 1] |
153 | 151 | . " instead of the current step: " . $this->current_simplification_step |
@@ -279,8 +277,7 @@ discard block |
||
279 | 277 | |
280 | 278 | if ($operand instanceof InRule && ! $operand->isNormalizationAllowed($simplification_options)) { |
281 | 279 | $count = count($operand->getPossibilities()); |
282 | - } |
|
283 | - else { |
|
280 | + } else { |
|
284 | 281 | $count = count($operand->getOperands()); |
285 | 282 | } |
286 | 283 | |
@@ -337,8 +334,7 @@ discard block |
||
337 | 334 | foreach ($operandsByOperator as $operator => $operands) { |
338 | 335 | try { |
339 | 336 | $unifiedOperands = array_merge($unifiedOperands, $operands); |
340 | - } |
|
341 | - catch (\Exception $e) { |
|
337 | + } catch (\Exception $e) { |
|
342 | 338 | VisibilityViolator::setHiddenProperty( |
343 | 339 | $e, 'message', |
344 | 340 | $e->getMessage() . "\n" . var_export($operandsByOperator, true) |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | * @param string $field The field to apply the rule on. |
17 | 17 | * @param array $value The value the field can below to. |
18 | 18 | */ |
19 | - public function __construct( $field, $maximum ) |
|
19 | + public function __construct($field, $maximum) |
|
20 | 20 | { |
21 | - if ( ! is_scalar($maximum) |
|
22 | - && ! $maximum instanceof \DateTimeInterface |
|
21 | + if (!is_scalar($maximum) |
|
22 | + && !$maximum instanceof \DateTimeInterface |
|
23 | 23 | && null !== $maximum |
24 | 24 | ) { |
25 | 25 | throw new \InvalidArgumentException( |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return bool |
40 | 40 | */ |
41 | - public function hasSolution(array $contextual_options=[]) |
|
41 | + public function hasSolution(array $contextual_options = []) |
|
42 | 42 | { |
43 | 43 | // if minimum is null, the rule is equivalent to true |
44 | - if (is_numeric( $this->maximum )) { |
|
45 | - if (is_nan( $this->maximum )) { |
|
44 | + if (is_numeric($this->maximum)) { |
|
45 | + if (is_nan($this->maximum)) { |
|
46 | 46 | return false; |
47 | 47 | } |
48 | 48 | |
49 | - if (is_infinite( $this->maximum ) && $this->maximum < 0) { |
|
49 | + if (is_infinite($this->maximum) && $this->maximum < 0) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @todo Support Posix? |
25 | 25 | */ |
26 | - public function __construct( $field, $pattern ) |
|
26 | + public function __construct($field, $pattern) |
|
27 | 27 | { |
28 | 28 | $this->field = $field; |
29 | 29 | $this->pattern = $pattern; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @return bool |
51 | 51 | */ |
52 | - public function hasSolution(array $simplification_options=[]) |
|
52 | + public function hasSolution(array $simplification_options = []) |
|
53 | 53 | { |
54 | 54 | return true; |
55 | 55 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $delimiter = substr($php_regexp, 0, 1); |
69 | 69 | $quoted_delimiter = preg_quote($delimiter, '#'); |
70 | 70 | |
71 | - if ( ! preg_match("#^$quoted_delimiter(.*)$quoted_delimiter([^$quoted_delimiter]*)$#", $php_regexp, $matches)) { |
|
71 | + if (!preg_match("#^$quoted_delimiter(.*)$quoted_delimiter([^$quoted_delimiter]*)$#", $php_regexp, $matches)) { |
|
72 | 72 | throw new \InvalidArgumentException( |
73 | 73 | "The provided PCRE regular expression (with the delimiter '$delimiter') cannot be parsed: " |
74 | 74 | .var_export($php_regexp, true) |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $pattern = $matches[1]; |
79 | 79 | $options = $matches[2]; |
80 | 80 | |
81 | - return ($options ? "(?$options)" : '') . $pattern; |
|
81 | + return ($options ? "(?$options)" : '').$pattern; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /**/ |
@@ -21,19 +21,19 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @return array |
23 | 23 | */ |
24 | - public function toArray(array $options=[]) |
|
24 | + public function toArray(array $options = []) |
|
25 | 25 | { |
26 | 26 | $default_options = [ |
27 | 27 | 'show_instance' => false, |
28 | 28 | ]; |
29 | 29 | foreach ($default_options as $default_option => &$default_value) { |
30 | - if ( ! isset($options[ $default_option ])) { |
|
31 | - $options[ $default_option ] = $default_value; |
|
30 | + if (!isset($options[$default_option])) { |
|
31 | + $options[$default_option] = $default_value; |
|
32 | 32 | } |
33 | 33 | } |
34 | 34 | |
35 | 35 | |
36 | - if ( ! $options['show_instance'] && ! empty($this->cache['array'])) { |
|
36 | + if (!$options['show_instance'] && !empty($this->cache['array'])) { |
|
37 | 37 | return $this->cache['array']; |
38 | 38 | } |
39 | 39 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $this->getValues(), |
46 | 46 | ]; |
47 | 47 | |
48 | - if ( ! $options['show_instance']) { |
|
48 | + if (!$options['show_instance']) { |
|
49 | 49 | return $this->cache['array'] = $array; |
50 | 50 | } |
51 | 51 | else { |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | |
56 | 56 | /** |
57 | 57 | */ |
58 | - public function toString(array $options=[]) |
|
58 | + public function toString(array $options = []) |
|
59 | 59 | { |
60 | - if ( ! empty($this->cache['string'])) { |
|
60 | + if (!empty($this->cache['string'])) { |
|
61 | 61 | return $this->cache['string']; |
62 | 62 | } |
63 | 63 |
@@ -47,8 +47,7 @@ discard block |
||
47 | 47 | |
48 | 48 | if ( ! $options['show_instance']) { |
49 | 49 | return $this->cache['array'] = $array; |
50 | - } |
|
51 | - else { |
|
50 | + } else { |
|
52 | 51 | return $array; |
53 | 52 | } |
54 | 53 | } |
@@ -70,11 +69,9 @@ discard block |
||
70 | 69 | |
71 | 70 | if ($field instanceof FilteredValue || $field instanceof FilteredKey) { |
72 | 71 | $field = "$field"; |
73 | - } |
|
74 | - elseif ($field instanceof \Closure) { |
|
72 | + } elseif ($field instanceof \Closure) { |
|
75 | 73 | throw new \Exception("Closures dump not implemented"); |
76 | - } |
|
77 | - else { |
|
74 | + } else { |
|
78 | 75 | $field = "'$field'"; |
79 | 76 | } |
80 | 77 |