@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * @param LogicalFilter $filter |
53 | 53 | */ |
54 | - public function convert( LogicalFilter $filter ) |
|
54 | + public function convert(LogicalFilter $filter) |
|
55 | 55 | { |
56 | 56 | $this->output = []; |
57 | 57 | parent::convert($filter); |
58 | 58 | return [ |
59 | - 'sql' => ! $this->output |
|
59 | + 'sql' => !$this->output |
|
60 | 60 | ? '1' // True |
61 | 61 | : '('.implode(') OR (', $this->output).')', |
62 | 62 | 'parameters' => $this->parameters, |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | public function onCloseOr() |
76 | 76 | { |
77 | 77 | $last_key = $this->getLastOrOperandKey(); |
78 | - $this->output[ $last_key ] = implode(' AND ', $this->output[ $last_key ]); |
|
78 | + $this->output[$last_key] = implode(' AND ', $this->output[$last_key]); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $value = $rule->getValue(); |
117 | 117 | } |
118 | 118 | elseif ($rule instanceof RegexpRule) { |
119 | - $value = RegexpRule::php2mariadbPCRE( $rule->getPattern() ); |
|
119 | + $value = RegexpRule::php2mariadbPCRE($rule->getPattern()); |
|
120 | 120 | } |
121 | 121 | else { |
122 | 122 | throw new \InvalidArgumentException( |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | // TODO disable locale to handle separators |
131 | 131 | } |
132 | 132 | elseif ($value instanceof \DateTime) { |
133 | - $value = "'" . $value->format('Y-m-d H:i:s') . "'"; |
|
133 | + $value = "'".$value->format('Y-m-d H:i:s')."'"; |
|
134 | 134 | } |
135 | 135 | elseif (gettype($value) == 'string') { |
136 | 136 | $value = $this->addParameter($value); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | foreach ($value as $possibility) { |
141 | 141 | $sql_part[] = $this->addParameter($possibility); |
142 | 142 | } |
143 | - $value = '(' . implode(', ', $sql_part) . ')'; |
|
143 | + $value = '('.implode(', ', $sql_part).')'; |
|
144 | 144 | } |
145 | 145 | elseif ($value === null) { |
146 | 146 | $value = "NULL"; |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | } |
159 | 159 | else { |
160 | 160 | throw new \InvalidArgumentException( |
161 | - "Unhandled type of value: ".gettype($value). ' | ' .var_export($value, true) |
|
161 | + "Unhandled type of value: ".gettype($value).' | '.var_export($value, true) |
|
162 | 162 | ); |
163 | 163 | } |
164 | 164 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | protected function appendToLastOrOperandKey($rule) |
184 | 184 | { |
185 | 185 | $last_key = $this->getLastOrOperandKey(); |
186 | - $this->output[ $last_key ][] = $rule; |
|
186 | + $this->output[$last_key][] = $rule; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /**/ |
@@ -86,77 +86,60 @@ |
||
86 | 86 | { |
87 | 87 | if ($rule instanceof EqualRule) { |
88 | 88 | $value = $rule->getValue(); |
89 | - } |
|
90 | - elseif ($rule instanceof InRule) { |
|
89 | + } elseif ($rule instanceof InRule) { |
|
91 | 90 | $value = $rule->getPossibilities(); |
92 | 91 | if (is_object($value) && method_exists('toArray', $value)) { |
93 | 92 | $value = $value->toArray(); |
94 | 93 | } |
95 | - } |
|
96 | - elseif ($rule instanceof NotInRule) { |
|
94 | + } elseif ($rule instanceof NotInRule) { |
|
97 | 95 | $operator = 'NOT IN'; |
98 | 96 | $value = $rule->getPossibilities(); |
99 | 97 | if (is_object($value) && method_exists('toArray', $value)) { |
100 | 98 | $value = $value->toArray(); |
101 | 99 | } |
102 | - } |
|
103 | - elseif ($rule instanceof AboveRule) { |
|
100 | + } elseif ($rule instanceof AboveRule) { |
|
104 | 101 | $value = $rule->getLowerLimit(); |
105 | - } |
|
106 | - elseif ($rule instanceof BelowRule) { |
|
102 | + } elseif ($rule instanceof BelowRule) { |
|
107 | 103 | $value = $rule->getUpperLimit(); |
108 | - } |
|
109 | - elseif ($rule instanceof AboveOrEqualRule) { |
|
104 | + } elseif ($rule instanceof AboveOrEqualRule) { |
|
110 | 105 | $value = $rule->getMinimum(); |
111 | - } |
|
112 | - elseif ($rule instanceof BelowOrEqualRule) { |
|
106 | + } elseif ($rule instanceof BelowOrEqualRule) { |
|
113 | 107 | $value = $rule->getMaximum(); |
114 | - } |
|
115 | - elseif ($rule instanceof NotEqualRule) { |
|
108 | + } elseif ($rule instanceof NotEqualRule) { |
|
116 | 109 | $value = $rule->getValue(); |
117 | - } |
|
118 | - elseif ($rule instanceof RegexpRule) { |
|
110 | + } elseif ($rule instanceof RegexpRule) { |
|
119 | 111 | $value = RegexpRule::php2mariadbPCRE( $rule->getPattern() ); |
120 | - } |
|
121 | - else { |
|
112 | + } else { |
|
122 | 113 | throw new \InvalidArgumentException( |
123 | 114 | "Unhandled operator '$operator' during SQL query generation" |
124 | 115 | ); |
125 | 116 | } |
126 | 117 | |
127 | 118 | if (gettype($value) == 'integer') { |
128 | - } |
|
129 | - elseif (gettype($value) == 'double') { |
|
119 | + } elseif (gettype($value) == 'double') { |
|
130 | 120 | // TODO disable locale to handle separators |
131 | - } |
|
132 | - elseif ($value instanceof \DateTime) { |
|
121 | + } elseif ($value instanceof \DateTime) { |
|
133 | 122 | $value = "'" . $value->format('Y-m-d H:i:s') . "'"; |
134 | - } |
|
135 | - elseif (gettype($value) == 'string') { |
|
123 | + } elseif (gettype($value) == 'string') { |
|
136 | 124 | $value = $this->addParameter($value); |
137 | - } |
|
138 | - elseif (gettype($value) == 'array') { |
|
125 | + } elseif (gettype($value) == 'array') { |
|
139 | 126 | $sql_part = []; |
140 | 127 | foreach ($value as $possibility) { |
141 | 128 | $sql_part[] = $this->addParameter($possibility); |
142 | 129 | } |
143 | 130 | $value = '(' . implode(', ', $sql_part) . ')'; |
144 | - } |
|
145 | - elseif ($value === null) { |
|
131 | + } elseif ($value === null) { |
|
146 | 132 | $value = "NULL"; |
147 | 133 | if ($rule instanceof EqualRule) { |
148 | 134 | $operator = 'IS'; |
149 | - } |
|
150 | - elseif ($rule instanceof NotEqualRule) { |
|
135 | + } elseif ($rule instanceof NotEqualRule) { |
|
151 | 136 | $operator = 'IS NOT'; |
152 | - } |
|
153 | - else { |
|
137 | + } else { |
|
154 | 138 | throw new \InvalidArgumentException( |
155 | 139 | "NULL is only handled for equality / difference" |
156 | 140 | ); |
157 | 141 | } |
158 | - } |
|
159 | - else { |
|
142 | + } else { |
|
160 | 143 | throw new \InvalidArgumentException( |
161 | 144 | "Unhandled type of value: ".gettype($value). ' | ' .var_export($value, true) |
162 | 145 | ); |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @param LogicalFilter $filter |
21 | 21 | */ |
22 | - public function convert( LogicalFilter $filter ) |
|
22 | + public function convert(LogicalFilter $filter) |
|
23 | 23 | { |
24 | 24 | $this->output = [ |
25 | 25 | ]; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | protected function appendToLastOrOperandKey($rule) |
163 | 163 | { |
164 | 164 | $last_key = $this->getLastOrOperandKey(); |
165 | - $this->output[ $last_key ]['bool']['must'][] = $rule; |
|
165 | + $this->output[$last_key]['bool']['must'][] = $rule; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /**/ |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | * @param string $field The field to apply the rule on. |
17 | 17 | * @param array $value The value the field can above to. |
18 | 18 | */ |
19 | - public function __construct( $field, $minimum ) |
|
19 | + public function __construct($field, $minimum) |
|
20 | 20 | { |
21 | - if ( !is_scalar($minimum) |
|
21 | + if (!is_scalar($minimum) |
|
22 | 22 | && !$minimum instanceof \DateTimeInterface |
23 | 23 | && null !== $minimum |
24 | 24 | ) { |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return bool |
63 | 63 | */ |
64 | - public function hasSolution(array $simplification_options=[]) |
|
64 | + public function hasSolution(array $simplification_options = []) |
|
65 | 65 | { |
66 | 66 | // if minimum is null, the rule is equivalent to true |
67 | - if (is_numeric( $this->minimum )) { |
|
68 | - if (is_nan( $this->minimum )) { |
|
67 | + if (is_numeric($this->minimum)) { |
|
68 | + if (is_nan($this->minimum)) { |
|
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | |
72 | - if (is_infinite( $this->minimum ) && $this->minimum > 0) { |
|
72 | + if (is_infinite($this->minimum) && $this->minimum > 0) { |
|
73 | 73 | return false; |
74 | 74 | } |
75 | 75 | } |
@@ -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 | } |
@@ -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 | /**/ |
@@ -13,17 +13,17 @@ discard block |
||
13 | 13 | * @param string $field The field to apply the rule on. |
14 | 14 | * @param array $value The value the field can equal to. |
15 | 15 | */ |
16 | - public function __construct( $field, $possibilities ) |
|
16 | + public function __construct($field, $possibilities) |
|
17 | 17 | { |
18 | 18 | $this->addOperand(new InRule($field, $possibilities)); |
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
22 | 22 | */ |
23 | - public function isNormalizationAllowed(array $contextual_options=[]) |
|
23 | + public function isNormalizationAllowed(array $contextual_options = []) |
|
24 | 24 | { |
25 | 25 | $operand = $this->getOperandAt(0); |
26 | - if ( ! $operand->getPossibilities()) { |
|
26 | + if (!$operand->getPossibilities()) { |
|
27 | 27 | return false; |
28 | 28 | } |
29 | 29 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function setPossibilities($possibilities) |
80 | 80 | { |
81 | - if ( is_object($possibilities) |
|
81 | + if (is_object($possibilities) |
|
82 | 82 | && $possibilities instanceof \IteratorAggregate |
83 | 83 | && method_exists($possibilities, 'toArray') |
84 | 84 | ) { |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | /** |
115 | 115 | */ |
116 | - public function hasSolution(array $contextual_options=[]) |
|
116 | + public function hasSolution(array $contextual_options = []) |
|
117 | 117 | { |
118 | 118 | return true; |
119 | 119 | } |
@@ -123,14 +123,14 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return array |
125 | 125 | */ |
126 | - public function toArray(array $options=[]) |
|
126 | + public function toArray(array $options = []) |
|
127 | 127 | { |
128 | 128 | $default_options = [ |
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 | |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | /** |
150 | 150 | * @todo cache support |
151 | 151 | */ |
152 | - public function toString(array $options=[]) |
|
152 | + public function toString(array $options = []) |
|
153 | 153 | { |
154 | 154 | try { |
155 | 155 | $operator = self::operator; |
156 | 156 | |
157 | - $stringified_possibilities = '[' . implode(', ', array_map(function($possibility) { |
|
157 | + $stringified_possibilities = '['.implode(', ', array_map(function($possibility) { |
|
158 | 158 | return var_export($possibility, true); |
159 | - }, $this->getPossibilities()) ) .']'; |
|
159 | + }, $this->getPossibilities())).']'; |
|
160 | 160 | |
161 | 161 | return "['{$this->getField()}', '$operator', $stringified_possibilities]"; |
162 | 162 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | && null !== $maximum |
24 | 24 | ) { |
25 | 25 | throw new \InvalidArgumentException( |
26 | - "Maximum parameter must be a scalar or null " |
|
26 | + "Maximum parameter must be a scalar or null " |
|
27 | 27 | ."or implements DateTimeInterface instead of: " |
28 | 28 | .var_export($maximum, true) |
29 | 29 | ); |
@@ -16,9 +16,9 @@ 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) |
|
21 | + if (!is_scalar($maximum) |
|
22 | 22 | && !$maximum instanceof \DateTimeInterface |
23 | 23 | && null !== $maximum |
24 | 24 | ) { |
@@ -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 | } |
@@ -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,7 +128,7 @@ 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 | 133 | if (!in_array($step_to_go_to, self::simplification_steps)) { |
134 | 134 | throw new \InvalidArgumentException( |
@@ -140,18 +140,18 @@ discard block |
||
140 | 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 | } |
@@ -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 | } |
@@ -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,11 +227,11 @@ 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 |
|
234 | + if ($operand instanceof AbstractOperationRule |
|
235 | 235 | && !$operand instanceof InRule |
236 | 236 | && !$operand instanceof NotEqualRule |
237 | 237 | && !$operand instanceof NotInRule |
@@ -305,7 +305,7 @@ 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); |
@@ -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,10 +365,10 @@ 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; |
|
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 | 372 | $force_logical_core = !empty($options['force_logical_core']) ? $options['force_logical_core'] : false; |
373 | 373 | |
374 | 374 | if ($step_to_stop_before && !in_array($step_to_stop_before, self::simplification_steps)) { |
@@ -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,7 +418,7 @@ 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 | |
@@ -429,7 +429,7 @@ discard block |
||
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,7 +446,7 @@ 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 ) { |
|
449 | + if ($instance instanceof AndRule || $instance instanceof OrRule) { |
|
450 | 450 | if (!$instance->getOperands()) { |
451 | 451 | return $instance; |
452 | 452 | } |
@@ -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])) { |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | * @param string $field The field to apply the rule on. |
33 | 33 | * @param mixed $possibilities The values the field can belong to. |
34 | 34 | */ |
35 | - public function __construct( $field, $possibilities, array $options=[] ) |
|
35 | + public function __construct($field, $possibilities, array $options = []) |
|
36 | 36 | { |
37 | 37 | if (!empty($options)) { |
38 | 38 | $this->setOptions($options); |
39 | 39 | } |
40 | 40 | |
41 | 41 | $this->field = $field; |
42 | - $this->addPossibilities( $possibilities ); |
|
42 | + $this->addPossibilities($possibilities); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | else { |
85 | 85 | throw new \InvalidArgumentException( |
86 | 86 | "\$renamings MUST be a callable or an associative array " |
87 | - ."instead of: " . var_export($renamings, true) |
|
87 | + ."instead of: ".var_export($renamings, true) |
|
88 | 88 | ); |
89 | 89 | } |
90 | 90 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function getPossibilities() |
102 | 102 | { |
103 | - return array_values( $this->native_possibilities ); |
|
103 | + return array_values($this->native_possibilities); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function addPossibilities($possibilities) |
112 | 112 | { |
113 | - if ( is_object($possibilities) |
|
113 | + if (is_object($possibilities) |
|
114 | 114 | && $possibilities instanceof \IteratorAggregate |
115 | 115 | && method_exists($possibilities, 'toArray') |
116 | 116 | ) { |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | $id = hash('crc32b', serialize($possibility)); |
133 | 133 | } |
134 | 134 | |
135 | - if (!isset($this->native_possibilities[ $id ])) { |
|
136 | - $this->native_possibilities[ $id ] = $possibility; |
|
135 | + if (!isset($this->native_possibilities[$id])) { |
|
136 | + $this->native_possibilities[$id] = $possibility; |
|
137 | 137 | $require_cache_flush = true; |
138 | 138 | } |
139 | 139 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @return InRule $this |
152 | 152 | */ |
153 | - public function addOperand( AbstractRule $operand ) |
|
153 | + public function addOperand(AbstractRule $operand) |
|
154 | 154 | { |
155 | 155 | $this->addPossibilities([$operand->getValue()]); |
156 | 156 | |
@@ -188,11 +188,11 @@ discard block |
||
188 | 188 | */ |
189 | 189 | protected function checkOperandAndExtractValue($operand) |
190 | 190 | { |
191 | - if (! $operand instanceof AbstractAtomicRule) { |
|
191 | + if (!$operand instanceof AbstractAtomicRule) { |
|
192 | 192 | return $operand; |
193 | 193 | } |
194 | 194 | |
195 | - if ( ! ($operand instanceof EqualRule && $operand->getField() == $this->field) ) { |
|
195 | + if (!($operand instanceof EqualRule && $operand->getField() == $this->field)) { |
|
196 | 196 | throw new \InvalidArgumentException( |
197 | 197 | "Trying to set an invalid operand of an InRule: " |
198 | 198 | .var_export($operand, true) |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | * |
233 | 233 | * @return array |
234 | 234 | */ |
235 | - public function toArray(array $options=[]) |
|
235 | + public function toArray(array $options = []) |
|
236 | 236 | { |
237 | 237 | $default_options = [ |
238 | 238 | 'show_instance' => false, |
239 | 239 | ]; |
240 | 240 | foreach ($default_options as $default_option => &$default_value) { |
241 | - if (!isset($options[ $default_option ])) { |
|
242 | - $options[ $default_option ] = $default_value; |
|
241 | + if (!isset($options[$default_option])) { |
|
242 | + $options[$default_option] = $default_value; |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | |
266 | 266 | /** |
267 | 267 | */ |
268 | - public function toString(array $options=[]) |
|
268 | + public function toString(array $options = []) |
|
269 | 269 | { |
270 | 270 | if (isset($this->cache['string'])) { |
271 | 271 | return $this->cache['string']; |
@@ -273,9 +273,9 @@ discard block |
||
273 | 273 | |
274 | 274 | $operator = self::operator; |
275 | 275 | |
276 | - $stringified_possibilities = '[' . implode(', ', array_map(function($possibility) { |
|
276 | + $stringified_possibilities = '['.implode(', ', array_map(function($possibility) { |
|
277 | 277 | return var_export($possibility, true); |
278 | - }, $this->getPossibilities()) ) .']'; |
|
278 | + }, $this->getPossibilities())).']'; |
|
279 | 279 | |
280 | 280 | return $this->cache['string'] = "['{$this->getField()}', '$operator', $stringified_possibilities]"; |
281 | 281 | } |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | /** |
295 | 295 | * @return bool If the InRule can have a solution or not |
296 | 296 | */ |
297 | - public function hasSolution(array $contextual_options=[]) |
|
297 | + public function hasSolution(array $contextual_options = []) |
|
298 | 298 | { |
299 | 299 | return !empty($this->getPossibilities()); |
300 | 300 | } |
@@ -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 |