@@ -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 | /** |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | else { |
84 | 84 | throw new \InvalidArgumentException( |
85 | 85 | "\$renamings MUST be a callable or an associative array " |
86 | - ."instead of: " . var_export($renamings, true) |
|
86 | + ."instead of: ".var_export($renamings, true) |
|
87 | 87 | ); |
88 | 88 | } |
89 | 89 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function getPossibilities() |
100 | 100 | { |
101 | - return array_values( $this->native_possibilities ); |
|
101 | + return array_values($this->native_possibilities); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function addPossibilities($possibilities) |
110 | 110 | { |
111 | - if ( is_object($possibilities) |
|
111 | + if (is_object($possibilities) |
|
112 | 112 | && $possibilities instanceof \IteratorAggregate |
113 | 113 | && method_exists($possibilities, 'toArray') |
114 | 114 | ) { |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | else |
129 | 129 | $id = hash('crc32b', serialize($possibility)); |
130 | 130 | |
131 | - if (!isset($this->native_possibilities[ $id ])) { |
|
132 | - $this->native_possibilities[ $id ] = $possibility; |
|
131 | + if (!isset($this->native_possibilities[$id])) { |
|
132 | + $this->native_possibilities[$id] = $possibility; |
|
133 | 133 | $require_cache_flush = true; |
134 | 134 | } |
135 | 135 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return InRule $this |
147 | 147 | */ |
148 | - public function addOperand( AbstractRule $operand ) |
|
148 | + public function addOperand(AbstractRule $operand) |
|
149 | 149 | { |
150 | 150 | $this->addPossibilities([$operand->getValue()]); |
151 | 151 | |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | */ |
184 | 184 | protected function checkOperandAndExtractValue($operand) |
185 | 185 | { |
186 | - if (! $operand instanceof AbstractAtomicRule) |
|
186 | + if (!$operand instanceof AbstractAtomicRule) |
|
187 | 187 | return $operand; |
188 | 188 | |
189 | - if ( ! ($operand instanceof EqualRule && $operand->getField() == $this->field) ) { |
|
189 | + if (!($operand instanceof EqualRule && $operand->getField() == $this->field)) { |
|
190 | 190 | throw new \InvalidArgumentException( |
191 | 191 | "Trying to set an invalid operand of an InRule: " |
192 | 192 | .var_export($operand, true) |
@@ -225,14 +225,14 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @return array |
227 | 227 | */ |
228 | - public function toArray(array $options=[]) |
|
228 | + public function toArray(array $options = []) |
|
229 | 229 | { |
230 | 230 | $default_options = [ |
231 | 231 | 'show_instance' => false, |
232 | 232 | ]; |
233 | 233 | foreach ($default_options as $default_option => &$default_value) { |
234 | - if (!isset($options[ $default_option ])) |
|
235 | - $options[ $default_option ] = $default_value; |
|
234 | + if (!isset($options[$default_option])) |
|
235 | + $options[$default_option] = $default_value; |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | $class = get_class($this); |
@@ -254,16 +254,16 @@ discard block |
||
254 | 254 | |
255 | 255 | /** |
256 | 256 | */ |
257 | - public function toString(array $options=[]) |
|
257 | + public function toString(array $options = []) |
|
258 | 258 | { |
259 | 259 | if (isset($this->cache['string'])) |
260 | 260 | return $this->cache['string']; |
261 | 261 | |
262 | 262 | $operator = self::operator; |
263 | 263 | |
264 | - $stringified_possibilities = '[' . implode(', ', array_map(function($possibility) { |
|
264 | + $stringified_possibilities = '['.implode(', ', array_map(function($possibility) { |
|
265 | 265 | return var_export($possibility, true); |
266 | - }, $this->getPossibilities()) ) .']'; |
|
266 | + }, $this->getPossibilities())).']'; |
|
267 | 267 | |
268 | 268 | return $this->cache['string'] = "['{$this->getField()}', '$operator', $stringified_possibilities]"; |
269 | 269 | } |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | /** |
283 | 283 | * @return bool If the InRule can have a solution or not |
284 | 284 | */ |
285 | - public function hasSolution(array $contextual_options=[]) |
|
285 | + public function hasSolution(array $contextual_options = []) |
|
286 | 286 | { |
287 | 287 | return !empty($this->getPossibilities()); |
288 | 288 | } |
@@ -75,20 +75,20 @@ discard block |
||
75 | 75 | |
76 | 76 | if (is_callable($renamings)) { |
77 | 77 | $this->field = call_user_func($renamings, $this->field); |
78 | - } |
|
79 | - elseif (is_array($renamings)) { |
|
80 | - if (isset($renamings[$this->field])) |
|
81 | - $this->field = $renamings[$this->field]; |
|
82 | - } |
|
83 | - else { |
|
78 | + } elseif (is_array($renamings)) { |
|
79 | + if (isset($renamings[$this->field])) { |
|
80 | + $this->field = $renamings[$this->field]; |
|
81 | + } |
|
82 | + } else { |
|
84 | 83 | throw new \InvalidArgumentException( |
85 | 84 | "\$renamings MUST be a callable or an associative array " |
86 | 85 | ."instead of: " . var_export($renamings, true) |
87 | 86 | ); |
88 | 87 | } |
89 | 88 | |
90 | - if ($old_field != $this->field) |
|
91 | - $this->flushCache(); |
|
89 | + if ($old_field != $this->field) { |
|
90 | + $this->flushCache(); |
|
91 | + } |
|
92 | 92 | |
93 | 93 | return $this; |
94 | 94 | } |
@@ -115,18 +115,20 @@ discard block |
||
115 | 115 | $possibilities = $possibilities->toArray(); |
116 | 116 | } |
117 | 117 | |
118 | - if (!is_array($possibilities)) |
|
119 | - $possibilities = [$possibilities]; |
|
118 | + if (!is_array($possibilities)) { |
|
119 | + $possibilities = [$possibilities]; |
|
120 | + } |
|
120 | 121 | |
121 | 122 | $possibilities = array_map([$this, 'checkOperandAndExtractValue'], $possibilities); |
122 | 123 | |
123 | 124 | // unique possibilities |
124 | 125 | foreach ($possibilities as &$possibility) { |
125 | 126 | |
126 | - if (is_scalar($possibility)) |
|
127 | - $id = hash('crc32b', $possibility); |
|
128 | - else |
|
129 | - $id = hash('crc32b', serialize($possibility)); |
|
127 | + if (is_scalar($possibility)) { |
|
128 | + $id = hash('crc32b', $possibility); |
|
129 | + } else { |
|
130 | + $id = hash('crc32b', serialize($possibility)); |
|
131 | + } |
|
130 | 132 | |
131 | 133 | if (!isset($this->native_possibilities[ $id ])) { |
132 | 134 | $this->native_possibilities[ $id ] = $possibility; |
@@ -134,8 +136,9 @@ discard block |
||
134 | 136 | } |
135 | 137 | } |
136 | 138 | |
137 | - if (isset($require_cache_flush)) |
|
138 | - $this->flushCache(); |
|
139 | + if (isset($require_cache_flush)) { |
|
140 | + $this->flushCache(); |
|
141 | + } |
|
139 | 142 | |
140 | 143 | return $this; |
141 | 144 | } |
@@ -183,8 +186,9 @@ discard block |
||
183 | 186 | */ |
184 | 187 | protected function checkOperandAndExtractValue($operand) |
185 | 188 | { |
186 | - if (! $operand instanceof AbstractAtomicRule) |
|
187 | - return $operand; |
|
189 | + if (! $operand instanceof AbstractAtomicRule) { |
|
190 | + return $operand; |
|
191 | + } |
|
188 | 192 | |
189 | 193 | if ( ! ($operand instanceof EqualRule && $operand->getField() == $this->field) ) { |
190 | 194 | throw new \InvalidArgumentException( |
@@ -206,8 +210,9 @@ discard block |
||
206 | 210 | } |
207 | 211 | |
208 | 212 | $operands = []; |
209 | - foreach ($this->native_possibilities as $value) |
|
210 | - $operands[] = new EqualRule($this->field, $value); |
|
213 | + foreach ($this->native_possibilities as $value) { |
|
214 | + $operands[] = new EqualRule($this->field, $value); |
|
215 | + } |
|
211 | 216 | |
212 | 217 | return $this->cache['operands'] = $operands; |
213 | 218 | } |
@@ -231,14 +236,16 @@ discard block |
||
231 | 236 | 'show_instance' => false, |
232 | 237 | ]; |
233 | 238 | foreach ($default_options as $default_option => &$default_value) { |
234 | - if (!isset($options[ $default_option ])) |
|
235 | - $options[ $default_option ] = $default_value; |
|
239 | + if (!isset($options[ $default_option ])) { |
|
240 | + $options[ $default_option ] = $default_value; |
|
241 | + } |
|
236 | 242 | } |
237 | 243 | |
238 | 244 | $class = get_class($this); |
239 | 245 | |
240 | - if (!$options['show_instance'] && isset($this->cache['array'])) |
|
241 | - return $this->cache['array']; |
|
246 | + if (!$options['show_instance'] && isset($this->cache['array'])) { |
|
247 | + return $this->cache['array']; |
|
248 | + } |
|
242 | 249 | |
243 | 250 | $array = [ |
244 | 251 | $this->getField(), |
@@ -246,18 +253,20 @@ discard block |
||
246 | 253 | $this->getValues(), |
247 | 254 | ]; |
248 | 255 | |
249 | - if (!$options['show_instance']) |
|
250 | - return $this->cache['array'] = $array; |
|
251 | - else |
|
252 | - return $array; |
|
256 | + if (!$options['show_instance']) { |
|
257 | + return $this->cache['array'] = $array; |
|
258 | + } else { |
|
259 | + return $array; |
|
260 | + } |
|
253 | 261 | } |
254 | 262 | |
255 | 263 | /** |
256 | 264 | */ |
257 | 265 | public function toString(array $options=[]) |
258 | 266 | { |
259 | - if (isset($this->cache['string'])) |
|
260 | - return $this->cache['string']; |
|
267 | + if (isset($this->cache['string'])) { |
|
268 | + return $this->cache['string']; |
|
269 | + } |
|
261 | 270 | |
262 | 271 | $operator = self::operator; |
263 | 272 |