@@ -46,11 +46,11 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function onRowMatches(&$row, $key, &$rows, $matching_case, $options) |
| 48 | 48 | { |
| 49 | - if (isset($options[ self::on_row_matches ])) { |
|
| 50 | - $callback = $options[ self::on_row_matches ]; |
|
| 49 | + if (isset($options[self::on_row_matches])) { |
|
| 50 | + $callback = $options[self::on_row_matches]; |
|
| 51 | 51 | } |
| 52 | - elseif (isset($this->custom_actions[ self::on_row_matches ])) { |
|
| 53 | - $callback = $this->custom_actions[ self::on_row_matches ]; |
|
| 52 | + elseif (isset($this->custom_actions[self::on_row_matches])) { |
|
| 53 | + $callback = $this->custom_actions[self::on_row_matches]; |
|
| 54 | 54 | } |
| 55 | 55 | else { |
| 56 | 56 | return; |
@@ -72,20 +72,20 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function onRowMismatches(&$row, $key, &$rows, $matching_case, $options) |
| 74 | 74 | { |
| 75 | - if ( ! $this->custom_actions |
|
| 76 | - && ! isset($options[self::on_row_mismatches]) |
|
| 77 | - && ! isset($options[self::on_row_matches]) |
|
| 75 | + if (!$this->custom_actions |
|
| 76 | + && !isset($options[self::on_row_mismatches]) |
|
| 77 | + && !isset($options[self::on_row_matches]) |
|
| 78 | 78 | ) { |
| 79 | 79 | // Unset by default ONLY if NO custom action defined |
| 80 | 80 | unset($rows[$key]); |
| 81 | 81 | return; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if (isset($options[ self::on_row_mismatches ])) { |
|
| 85 | - $callback = $options[ self::on_row_mismatches ]; |
|
| 84 | + if (isset($options[self::on_row_mismatches])) { |
|
| 85 | + $callback = $options[self::on_row_mismatches]; |
|
| 86 | 86 | } |
| 87 | - elseif (isset($this->custom_actions[ self::on_row_mismatches ])) { |
|
| 88 | - $callback = $this->custom_actions[ self::on_row_mismatches ]; |
|
| 87 | + elseif (isset($this->custom_actions[self::on_row_mismatches])) { |
|
| 88 | + $callback = $this->custom_actions[self::on_row_mismatches]; |
|
| 89 | 89 | } |
| 90 | 90 | else { |
| 91 | 91 | return; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param Iterable $tree_to_filter |
| 123 | 123 | * @param array $options |
| 124 | 124 | */ |
| 125 | - public function apply( LogicalFilter $filter, $tree_to_filter, $options=[] ) |
|
| 125 | + public function apply(LogicalFilter $filter, $tree_to_filter, $options = []) |
|
| 126 | 126 | { |
| 127 | 127 | $root_OrRule = $filter |
| 128 | 128 | ->simplify(['force_logical_core' => true]) |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | ; |
| 132 | 132 | |
| 133 | 133 | if ($root_OrRule !== null) { |
| 134 | - if ( ! $root_OrRule->hasSolution()) { |
|
| 134 | + if (!$root_OrRule->hasSolution()) { |
|
| 135 | 135 | return null; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | $root_cases = []; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ( ! isset($options['recurse'])) { |
|
| 144 | + if (!isset($options['recurse'])) { |
|
| 145 | 145 | $options['recurse'] = 'before'; |
| 146 | 146 | } |
| 147 | - elseif ( ! in_array($options['recurse'], ['before', 'after', null])) { |
|
| 147 | + elseif (!in_array($options['recurse'], ['before', 'after', null])) { |
|
| 148 | 148 | throw new \InvalidArgumentException( |
| 149 | 149 | "Invalid value for 'recurse' option: " |
| 150 | 150 | .var_export($options['recurse'], true) |
@@ -155,14 +155,14 @@ discard block |
||
| 155 | 155 | return $this->foreachRow( |
| 156 | 156 | $root_cases, |
| 157 | 157 | $tree_to_filter, |
| 158 | - $path=[], |
|
| 158 | + $path = [], |
|
| 159 | 159 | $options |
| 160 | 160 | ); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
| 164 | 164 | */ |
| 165 | - protected function foreachRow(array $root_cases, $tree_to_filter, array $path, $options=[]) |
|
| 165 | + protected function foreachRow(array $root_cases, $tree_to_filter, array $path, $options = []) |
|
| 166 | 166 | { |
| 167 | 167 | // Once the rules are prepared, we parse the data |
| 168 | 168 | foreach ($tree_to_filter as $row_index => $row_to_filter) { |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return bool |
| 223 | 223 | */ |
| 224 | - public function hasMatchingCase( LogicalFilter $filter, $row_to_check, $key_to_check, $options=[] ) |
|
| 224 | + public function hasMatchingCase(LogicalFilter $filter, $row_to_check, $key_to_check, $options = []) |
|
| 225 | 225 | { |
| 226 | 226 | $root_OrRule = $filter |
| 227 | 227 | ->simplify(['force_logical_core' => true]) |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | ; |
| 231 | 231 | |
| 232 | 232 | if ($root_OrRule !== null) { |
| 233 | - if ( ! $root_OrRule->hasSolution()) { |
|
| 233 | + if (!$root_OrRule->hasSolution()) { |
|
| 234 | 234 | return null; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -243,24 +243,24 @@ discard block |
||
| 243 | 243 | return $this->applyOnRow( |
| 244 | 244 | $root_cases, |
| 245 | 245 | $row_to_check, |
| 246 | - $path=[$key_to_check], |
|
| 246 | + $path = [$key_to_check], |
|
| 247 | 247 | $options |
| 248 | 248 | ); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
| 252 | 252 | */ |
| 253 | - protected function applyOnRow(array $root_cases, $row_to_filter, array $path, $options=[]) |
|
| 253 | + protected function applyOnRow(array $root_cases, $row_to_filter, array $path, $options = []) |
|
| 254 | 254 | { |
| 255 | 255 | $operands_validation_row_cache = []; |
| 256 | 256 | |
| 257 | - if ( ! $root_cases) { |
|
| 257 | + if (!$root_cases) { |
|
| 258 | 258 | $matching_case = true; |
| 259 | 259 | } |
| 260 | 260 | else { |
| 261 | 261 | $matching_case = null; |
| 262 | 262 | foreach ($root_cases as $and_case_index => $and_case) { |
| 263 | - if ( ! empty($options['debug'])) { |
|
| 263 | + if (!empty($options['debug'])) { |
|
| 264 | 264 | var_dump("Case $and_case_index: ".$and_case); |
| 265 | 265 | } |
| 266 | 266 | |
@@ -288,8 +288,8 @@ discard block |
||
| 288 | 288 | |
| 289 | 289 | $cache_key = $and_case_index.'~|~'.$field.'~|~'.$operator; |
| 290 | 290 | |
| 291 | - if ( ! empty($operands_validation_row_cache[ $cache_key ])) { |
|
| 292 | - $is_valid = $operands_validation_row_cache[ $cache_key ]; |
|
| 291 | + if (!empty($operands_validation_row_cache[$cache_key])) { |
|
| 292 | + $is_valid = $operands_validation_row_cache[$cache_key]; |
|
| 293 | 293 | } |
| 294 | 294 | else { |
| 295 | 295 | $is_valid = $this->validateRule( |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | $options |
| 303 | 303 | ); |
| 304 | 304 | |
| 305 | - $operands_validation_row_cache[ $cache_key ] = $is_valid; |
|
| 305 | + $operands_validation_row_cache[$cache_key] = $is_valid; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | if ($is_valid === false) { |
@@ -48,11 +48,9 @@ discard block |
||
| 48 | 48 | { |
| 49 | 49 | if (isset($options[ self::on_row_matches ])) { |
| 50 | 50 | $callback = $options[ self::on_row_matches ]; |
| 51 | - } |
|
| 52 | - elseif (isset($this->custom_actions[ self::on_row_matches ])) { |
|
| 51 | + } elseif (isset($this->custom_actions[ self::on_row_matches ])) { |
|
| 53 | 52 | $callback = $this->custom_actions[ self::on_row_matches ]; |
| 54 | - } |
|
| 55 | - else { |
|
| 53 | + } else { |
|
| 56 | 54 | return; |
| 57 | 55 | } |
| 58 | 56 | |
@@ -83,11 +81,9 @@ discard block |
||
| 83 | 81 | |
| 84 | 82 | if (isset($options[ self::on_row_mismatches ])) { |
| 85 | 83 | $callback = $options[ self::on_row_mismatches ]; |
| 86 | - } |
|
| 87 | - elseif (isset($this->custom_actions[ self::on_row_mismatches ])) { |
|
| 84 | + } elseif (isset($this->custom_actions[ self::on_row_mismatches ])) { |
|
| 88 | 85 | $callback = $this->custom_actions[ self::on_row_mismatches ]; |
| 89 | - } |
|
| 90 | - else { |
|
| 86 | + } else { |
|
| 91 | 87 | return; |
| 92 | 88 | } |
| 93 | 89 | |
@@ -136,15 +132,13 @@ discard block |
||
| 136 | 132 | } |
| 137 | 133 | |
| 138 | 134 | $root_cases = $root_OrRule->getOperands(); |
| 139 | - } |
|
| 140 | - else { |
|
| 135 | + } else { |
|
| 141 | 136 | $root_cases = []; |
| 142 | 137 | } |
| 143 | 138 | |
| 144 | 139 | if ( ! isset($options['recurse'])) { |
| 145 | 140 | $options['recurse'] = 'before'; |
| 146 | - } |
|
| 147 | - elseif ( ! in_array($options['recurse'], ['before', 'after', null])) { |
|
| 141 | + } elseif ( ! in_array($options['recurse'], ['before', 'after', null])) { |
|
| 148 | 142 | throw new \InvalidArgumentException( |
| 149 | 143 | "Invalid value for 'recurse' option: " |
| 150 | 144 | .var_export($options['recurse'], true) |
@@ -185,12 +179,10 @@ discard block |
||
| 185 | 179 | |
| 186 | 180 | if ($matching_case) { |
| 187 | 181 | $this->onRowMatches($row_to_filter, $row_index, $tree_to_filter, $matching_case, $options); |
| 188 | - } |
|
| 189 | - elseif ($matching_case === false) { |
|
| 182 | + } elseif ($matching_case === false) { |
|
| 190 | 183 | // No case match the rule |
| 191 | 184 | $this->onRowMismatches($row_to_filter, $row_index, $tree_to_filter, $matching_case, $options); |
| 192 | - } |
|
| 193 | - elseif ($matching_case === null) { |
|
| 185 | + } elseif ($matching_case === null) { |
|
| 194 | 186 | // We simply avoid rules |
| 195 | 187 | // row out of scope |
| 196 | 188 | } |
@@ -235,8 +227,7 @@ discard block |
||
| 235 | 227 | } |
| 236 | 228 | |
| 237 | 229 | $root_cases = $root_OrRule->getOperands(); |
| 238 | - } |
|
| 239 | - else { |
|
| 230 | + } else { |
|
| 240 | 231 | $root_cases = []; |
| 241 | 232 | } |
| 242 | 233 | |
@@ -256,8 +247,7 @@ discard block |
||
| 256 | 247 | |
| 257 | 248 | if ( ! $root_cases) { |
| 258 | 249 | $matching_case = true; |
| 259 | - } |
|
| 260 | - else { |
|
| 250 | + } else { |
|
| 261 | 251 | $matching_case = null; |
| 262 | 252 | foreach ($root_cases as $and_case_index => $and_case) { |
| 263 | 253 | if ( ! empty($options['debug'])) { |
@@ -269,16 +259,14 @@ discard block |
||
| 269 | 259 | if ($rule instanceof OrRule && $rule instanceof AndRule) { |
| 270 | 260 | $field = null; |
| 271 | 261 | $value = $rule->getOperands(); |
| 272 | - } |
|
| 273 | - elseif ($rule instanceof NotEqualRule |
|
| 262 | + } elseif ($rule instanceof NotEqualRule |
|
| 274 | 263 | || $rule instanceof AbstractAtomicRule |
| 275 | 264 | || $rule instanceof InRule |
| 276 | 265 | || $rule instanceof NotInRule |
| 277 | 266 | ) { |
| 278 | 267 | $field = $rule->getField(); |
| 279 | 268 | $value = $rule->getValues(); |
| 280 | - } |
|
| 281 | - else { |
|
| 269 | + } else { |
|
| 282 | 270 | throw new \LogicException( |
| 283 | 271 | "Filtering with a rule which has not been simplified: $rule" |
| 284 | 272 | ); |
@@ -290,8 +278,7 @@ discard block |
||
| 290 | 278 | |
| 291 | 279 | if ( ! empty($operands_validation_row_cache[ $cache_key ])) { |
| 292 | 280 | $is_valid = $operands_validation_row_cache[ $cache_key ]; |
| 293 | - } |
|
| 294 | - else { |
|
| 281 | + } else { |
|
| 295 | 282 | $is_valid = $this->validateRule( |
| 296 | 283 | $field, |
| 297 | 284 | $operator, |
@@ -310,8 +297,7 @@ discard block |
||
| 310 | 297 | // so all the and_case is invalid |
| 311 | 298 | $case_is_good = false; |
| 312 | 299 | break; |
| 313 | - } |
|
| 314 | - elseif ($is_valid === true) { |
|
| 300 | + } elseif ($is_valid === true) { |
|
| 315 | 301 | // one of the rules of the and_case do not validate |
| 316 | 302 | // so all the and_case is invalid |
| 317 | 303 | $case_is_good = true; |
@@ -322,11 +308,9 @@ discard block |
||
| 322 | 308 | // at least one and_case works so we can stop here |
| 323 | 309 | $matching_case = $and_case; |
| 324 | 310 | break; |
| 325 | - } |
|
| 326 | - elseif ($case_is_good === false) { |
|
| 311 | + } elseif ($case_is_good === false) { |
|
| 327 | 312 | $matching_case = false; |
| 328 | - } |
|
| 329 | - elseif ($case_is_good === null) { |
|
| 313 | + } elseif ($case_is_good === null) { |
|
| 330 | 314 | // row out of scope |
| 331 | 315 | } |
| 332 | 316 | } |
@@ -191,9 +191,9 @@ |
||
| 191 | 191 | if ( ! empty($options['debug'])) { |
| 192 | 192 | var_dump( |
| 193 | 193 | "$field, $operator, " . var_export($value, true) |
| 194 | - . ' || '. $value_to_compare . ' => ' . var_export($out, true) |
|
| 195 | - . "\n" . get_class($rule) |
|
| 196 | - . "\n" . var_export($options, true) |
|
| 194 | + . ' || '. $value_to_compare . ' => ' . var_export($out, true) |
|
| 195 | + . "\n" . get_class($rule) |
|
| 196 | + . "\n" . var_export($options, true) |
|
| 197 | 197 | ); |
| 198 | 198 | // $rule->dump(); |
| 199 | 199 | } |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | */ |
| 62 | - public function setChildren( &$row, $filtered_children ) // strict issue if forcing AbstractRule with php 5.6 here |
|
| 62 | + public function setChildren(&$row, $filtered_children) // strict issue if forcing AbstractRule with php 5.6 here |
|
| 63 | 63 | { |
| 64 | 64 | if ($row instanceof AbstractOperationRule) { |
| 65 | - return $row->setOperandsOrReplaceByOperation( $filtered_children, [] ); // no simplification options? |
|
| 65 | + return $row->setOperandsOrReplaceByOperation($filtered_children, []); // no simplification options? |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
@@ -70,17 +70,17 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return true | false | null |
| 72 | 72 | */ |
| 73 | - public function validateRule ($field, $operator, $value, $rule, array $path, $all_operands, $options) |
|
| 73 | + public function validateRule($field, $operator, $value, $rule, array $path, $all_operands, $options) |
|
| 74 | 74 | { |
| 75 | - if ( ! empty($options[ Filterer::leaves_only ]) |
|
| 76 | - && in_array( get_class($rule), [OrRule::class, AndRule::class, NotRule::class] ) |
|
| 75 | + if (!empty($options[Filterer::leaves_only]) |
|
| 76 | + && in_array(get_class($rule), [OrRule::class, AndRule::class, NotRule::class]) |
|
| 77 | 77 | ) { |
| 78 | 78 | // return true; |
| 79 | 79 | return null; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | if ($field === self::field) { |
| 83 | - if ( ! method_exists($rule, 'getField')) { |
|
| 83 | + if (!method_exists($rule, 'getField')) { |
|
| 84 | 84 | // if (in_array( get_class($rule), [AndRule::class, OrRule::class])) |
| 85 | 85 | return null; // The filter cannot be applied to this rule |
| 86 | 86 | } |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | elseif ($field === self::value) { |
| 101 | 101 | $description = $rule->toArray(); |
| 102 | 102 | |
| 103 | - if ( count($description) === 3 |
|
| 103 | + if (count($description) === 3 |
|
| 104 | 104 | && is_string($description[0]) |
| 105 | - && is_string($description[1]) ) { |
|
| 105 | + && is_string($description[1])) { |
|
| 106 | 106 | $value_to_compare = $description[2]; |
| 107 | 107 | } |
| 108 | 108 | else { |
@@ -121,10 +121,10 @@ discard block |
||
| 121 | 121 | throw new \InvalidArgumentException('Path rule uppport not implemented'); |
| 122 | 122 | } |
| 123 | 123 | elseif ($field === self::children) { |
| 124 | - if ( ! method_exists($rule, 'getOperands')) { |
|
| 124 | + if (!method_exists($rule, 'getOperands')) { |
|
| 125 | 125 | return null; // The filter cannot be applied to this rule |
| 126 | 126 | } |
| 127 | - $value_to_compare = count( $rule->getOperands() ); |
|
| 127 | + $value_to_compare = count($rule->getOperands()); |
|
| 128 | 128 | } |
| 129 | 129 | else { |
| 130 | 130 | throw new \InvalidArgumentException( |
@@ -173,27 +173,27 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | elseif ($operator === NotEqualRule::operator) { |
| 175 | 175 | if ($value === null) { |
| 176 | - $out = ! is_null($value_to_compare); |
|
| 176 | + $out = !is_null($value_to_compare); |
|
| 177 | 177 | } |
| 178 | 178 | else { |
| 179 | 179 | $out = $value != $value_to_compare; |
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | elseif ($operator === NotInRule::operator) { |
| 183 | - $out = ! in_array($value_to_compare, $value); |
|
| 183 | + $out = !in_array($value_to_compare, $value); |
|
| 184 | 184 | } |
| 185 | 185 | else { |
| 186 | 186 | throw new \InvalidArgumentException( |
| 187 | - "Unhandled operator: " . $operator |
|
| 187 | + "Unhandled operator: ".$operator |
|
| 188 | 188 | ); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if ( ! empty($options['debug'])) { |
|
| 191 | + if (!empty($options['debug'])) { |
|
| 192 | 192 | var_dump( |
| 193 | - "$field, $operator, " . var_export($value, true) |
|
| 194 | - . ' || '. $value_to_compare . ' => ' . var_export($out, true) |
|
| 195 | - . "\n" . get_class($rule) |
|
| 196 | - . "\n" . var_export($options, true) |
|
| 193 | + "$field, $operator, ".var_export($value, true) |
|
| 194 | + . ' || '.$value_to_compare.' => '.var_export($out, true) |
|
| 195 | + . "\n".get_class($rule) |
|
| 196 | + . "\n".var_export($options, true) |
|
| 197 | 197 | ); |
| 198 | 198 | // $rule->dump(); |
| 199 | 199 | } |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | * @param array|AbstractRule $ruleTree_to_filter |
| 207 | 207 | * @param array $options leaves_only | debug |
| 208 | 208 | */ |
| 209 | - public function apply( LogicalFilter $filter, $ruleTree_to_filter, $options=[] ) |
|
| 209 | + public function apply(LogicalFilter $filter, $ruleTree_to_filter, $options = []) |
|
| 210 | 210 | { |
| 211 | - if ( ! $ruleTree_to_filter) { |
|
| 211 | + if (!$ruleTree_to_filter) { |
|
| 212 | 212 | return $ruleTree_to_filter; |
| 213 | 213 | } |
| 214 | 214 | |
@@ -216,17 +216,17 @@ discard block |
||
| 216 | 216 | $ruleTree_to_filter = [$ruleTree_to_filter]; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - if ( ! is_array($ruleTree_to_filter)) { |
|
| 219 | + if (!is_array($ruleTree_to_filter)) { |
|
| 220 | 220 | throw new \InvalidArgumentException( |
| 221 | 221 | "\$ruleTree_to_filter must be an array or an AbstractRule " |
| 222 | - ."instead of: " . var_export($ruleTree_to_filter, true) |
|
| 222 | + ."instead of: ".var_export($ruleTree_to_filter, true) |
|
| 223 | 223 | ); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // Produces "Only variables should be passed by reference" on Travis |
| 227 | 227 | $result = parent::apply($filter, $ruleTree_to_filter, $options); |
| 228 | 228 | |
| 229 | - return reset( $result ); |
|
| 229 | + return reset($result); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /**/ |
@@ -87,46 +87,37 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | try { |
| 89 | 89 | $value_to_compare = $rule->getField(); |
| 90 | - } |
|
| 91 | - catch (\LogicException $e) { |
|
| 90 | + } catch (\LogicException $e) { |
|
| 92 | 91 | // This is due to NotInRule. |
| 93 | 92 | // TODO replace it by a TrueRule in this case |
| 94 | 93 | return null; |
| 95 | 94 | } |
| 96 | - } |
|
| 97 | - elseif ($field === self::operator) { |
|
| 95 | + } elseif ($field === self::operator) { |
|
| 98 | 96 | $value_to_compare = $rule::operator; |
| 99 | - } |
|
| 100 | - elseif ($field === self::value) { |
|
| 97 | + } elseif ($field === self::value) { |
|
| 101 | 98 | $description = $rule->toArray(); |
| 102 | 99 | |
| 103 | 100 | if ( count($description) === 3 |
| 104 | 101 | && is_string($description[0]) |
| 105 | 102 | && is_string($description[1]) ) { |
| 106 | 103 | $value_to_compare = $description[2]; |
| 107 | - } |
|
| 108 | - else { |
|
| 104 | + } else { |
|
| 109 | 105 | return null; // The filter cannot be applied to this rule |
| 110 | 106 | } |
| 111 | - } |
|
| 112 | - elseif ($field === self::description) { |
|
| 107 | + } elseif ($field === self::description) { |
|
| 113 | 108 | $value_to_compare = $rule->toArray(); |
| 114 | - } |
|
| 115 | - elseif ($field === self::depth) { |
|
| 109 | + } elseif ($field === self::depth) { |
|
| 116 | 110 | // original $depth is lost once the filter is simplified |
| 117 | 111 | throw new \InvalidArgumentException('Depth rule uppport not implemented'); |
| 118 | - } |
|
| 119 | - elseif ($field === self::path) { |
|
| 112 | + } elseif ($field === self::path) { |
|
| 120 | 113 | // TODO the description of its parents |
| 121 | 114 | throw new \InvalidArgumentException('Path rule uppport not implemented'); |
| 122 | - } |
|
| 123 | - elseif ($field === self::children) { |
|
| 115 | + } elseif ($field === self::children) { |
|
| 124 | 116 | if ( ! method_exists($rule, 'getOperands')) { |
| 125 | 117 | return null; // The filter cannot be applied to this rule |
| 126 | 118 | } |
| 127 | 119 | $value_to_compare = count( $rule->getOperands() ); |
| 128 | - } |
|
| 129 | - else { |
|
| 120 | + } else { |
|
| 130 | 121 | throw new \InvalidArgumentException( |
| 131 | 122 | "Rule filters must belong to [" |
| 132 | 123 | . implode(', ', [ |
@@ -145,22 +136,17 @@ discard block |
||
| 145 | 136 | if ($operator === EqualRule::operator) { |
| 146 | 137 | if ($value === null) { |
| 147 | 138 | $out = is_null($value_to_compare); |
| 148 | - } |
|
| 149 | - else { |
|
| 139 | + } else { |
|
| 150 | 140 | // TODO support strict comparisons |
| 151 | 141 | $out = $value_to_compare == $value; |
| 152 | 142 | } |
| 153 | - } |
|
| 154 | - elseif ($operator === InRule::operator) { |
|
| 143 | + } elseif ($operator === InRule::operator) { |
|
| 155 | 144 | $out = in_array($value_to_compare, $value); |
| 156 | - } |
|
| 157 | - elseif ($operator === BelowRule::operator) { |
|
| 145 | + } elseif ($operator === BelowRule::operator) { |
|
| 158 | 146 | $out = $value_to_compare < $value; |
| 159 | - } |
|
| 160 | - elseif ($operator === AboveRule::operator) { |
|
| 147 | + } elseif ($operator === AboveRule::operator) { |
|
| 161 | 148 | $out = $value_to_compare > $value; |
| 162 | - } |
|
| 163 | - elseif ($operator === RegexpRule::operator) { |
|
| 149 | + } elseif ($operator === RegexpRule::operator) { |
|
| 164 | 150 | // TODO support optionnal parameters |
| 165 | 151 | $out = preg_match($value, $value_to_compare); |
| 166 | 152 | if ($out === false) { |
@@ -170,19 +156,15 @@ discard block |
||
| 170 | 156 | ); |
| 171 | 157 | } |
| 172 | 158 | $out = (bool) $out; |
| 173 | - } |
|
| 174 | - elseif ($operator === NotEqualRule::operator) { |
|
| 159 | + } elseif ($operator === NotEqualRule::operator) { |
|
| 175 | 160 | if ($value === null) { |
| 176 | 161 | $out = ! is_null($value_to_compare); |
| 177 | - } |
|
| 178 | - else { |
|
| 162 | + } else { |
|
| 179 | 163 | $out = $value != $value_to_compare; |
| 180 | 164 | } |
| 181 | - } |
|
| 182 | - elseif ($operator === NotInRule::operator) { |
|
| 165 | + } elseif ($operator === NotInRule::operator) { |
|
| 183 | 166 | $out = ! in_array($value_to_compare, $value); |
| 184 | - } |
|
| 185 | - else { |
|
| 167 | + } else { |
|
| 186 | 168 | throw new \InvalidArgumentException( |
| 187 | 169 | "Unhandled operator: " . $operator |
| 188 | 170 | ); |
@@ -22,23 +22,23 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | /** |
| 24 | 24 | */ |
| 25 | - public function validateRule ($field, $operator, $value, $row, array $path, $all_operands, $options) |
|
| 25 | + public function validateRule($field, $operator, $value, $row, array $path, $all_operands, $options) |
|
| 26 | 26 | { |
| 27 | 27 | if ($field instanceof FilteredValue) { |
| 28 | - $value_to_validate = $field( $row ); |
|
| 28 | + $value_to_validate = $field($row); |
|
| 29 | 29 | } |
| 30 | 30 | elseif ($field instanceof FilteredKey) { |
| 31 | - $value_to_validate = $field( array_pop($path) ); |
|
| 31 | + $value_to_validate = $field(array_pop($path)); |
|
| 32 | 32 | } |
| 33 | - elseif ( ! isset($row[(string) $field])) { |
|
| 33 | + elseif (!isset($row[(string) $field])) { |
|
| 34 | 34 | $value_to_validate = null; |
| 35 | 35 | } |
| 36 | 36 | else { |
| 37 | - $value_to_validate = $row[ $field ]; |
|
| 37 | + $value_to_validate = $row[$field]; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | if ($operator === EqualRule::operator) { |
| 41 | - if ( ! isset($value_to_validate)) { |
|
| 41 | + if (!isset($value_to_validate)) { |
|
| 42 | 42 | // ['field', '=', null] <=> isset($row['field']) |
| 43 | 43 | // [row, '=', null] <=> $row !== null |
| 44 | 44 | $result = $value === null; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | elseif ($operator === InRule::operator) { |
| 52 | - if ( ! isset($value_to_validate)) { |
|
| 52 | + if (!isset($value_to_validate)) { |
|
| 53 | 53 | $result = false; |
| 54 | 54 | } |
| 55 | 55 | else { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | elseif ($operator === BelowRule::operator) { |
| 60 | - if ( ! isset($value_to_validate)) { |
|
| 60 | + if (!isset($value_to_validate)) { |
|
| 61 | 61 | $result = false; |
| 62 | 62 | } |
| 63 | 63 | else { |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | elseif ($operator === AboveRule::operator) { |
| 68 | - if ( ! isset($value_to_validate)) { |
|
| 68 | + if (!isset($value_to_validate)) { |
|
| 69 | 69 | $result = false; |
| 70 | 70 | } |
| 71 | 71 | else { |
@@ -81,16 +81,16 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | elseif ($operator === NotInRule::operator) { |
| 84 | - if ( ! isset($value_to_validate)) { |
|
| 84 | + if (!isset($value_to_validate)) { |
|
| 85 | 85 | $result = true; |
| 86 | 86 | } |
| 87 | 87 | else { |
| 88 | - $result = ! in_array($value_to_validate, $value); |
|
| 88 | + $result = !in_array($value_to_validate, $value); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | else { |
| 92 | 92 | throw new \InvalidArgumentException( |
| 93 | - "Unhandled operator: " . $operator |
|
| 93 | + "Unhandled operator: ".$operator |
|
| 94 | 94 | ); |
| 95 | 95 | } |
| 96 | 96 | |
@@ -26,14 +26,11 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | if ($field instanceof FilteredValue) { |
| 28 | 28 | $value_to_validate = $field( $row ); |
| 29 | - } |
|
| 30 | - elseif ($field instanceof FilteredKey) { |
|
| 29 | + } elseif ($field instanceof FilteredKey) { |
|
| 31 | 30 | $value_to_validate = $field( array_pop($path) ); |
| 32 | - } |
|
| 33 | - elseif ( ! isset($row[(string) $field])) { |
|
| 31 | + } elseif ( ! isset($row[(string) $field])) { |
|
| 34 | 32 | $value_to_validate = null; |
| 35 | - } |
|
| 36 | - else { |
|
| 33 | + } else { |
|
| 37 | 34 | $value_to_validate = $row[ $field ]; |
| 38 | 35 | } |
| 39 | 36 | |
@@ -42,53 +39,41 @@ discard block |
||
| 42 | 39 | // ['field', '=', null] <=> isset($row['field']) |
| 43 | 40 | // [row, '=', null] <=> $row !== null |
| 44 | 41 | $result = $value === null; |
| 45 | - } |
|
| 46 | - else { |
|
| 42 | + } else { |
|
| 47 | 43 | // TODO support strict comparisons |
| 48 | 44 | $result = $value_to_validate == $value; |
| 49 | 45 | } |
| 50 | - } |
|
| 51 | - elseif ($operator === InRule::operator) { |
|
| 46 | + } elseif ($operator === InRule::operator) { |
|
| 52 | 47 | if ( ! isset($value_to_validate)) { |
| 53 | 48 | $result = false; |
| 54 | - } |
|
| 55 | - else { |
|
| 49 | + } else { |
|
| 56 | 50 | $result = in_array($value_to_validate, $value); |
| 57 | 51 | } |
| 58 | - } |
|
| 59 | - elseif ($operator === BelowRule::operator) { |
|
| 52 | + } elseif ($operator === BelowRule::operator) { |
|
| 60 | 53 | if ( ! isset($value_to_validate)) { |
| 61 | 54 | $result = false; |
| 62 | - } |
|
| 63 | - else { |
|
| 55 | + } else { |
|
| 64 | 56 | $result = $value_to_validate < $value; |
| 65 | 57 | } |
| 66 | - } |
|
| 67 | - elseif ($operator === AboveRule::operator) { |
|
| 58 | + } elseif ($operator === AboveRule::operator) { |
|
| 68 | 59 | if ( ! isset($value_to_validate)) { |
| 69 | 60 | $result = false; |
| 70 | - } |
|
| 71 | - else { |
|
| 61 | + } else { |
|
| 72 | 62 | $result = $value_to_validate > $value; |
| 73 | 63 | } |
| 74 | - } |
|
| 75 | - elseif ($operator === NotEqualRule::operator) { |
|
| 64 | + } elseif ($operator === NotEqualRule::operator) { |
|
| 76 | 65 | if ($value === null) { |
| 77 | 66 | $result = isset($value_to_validate); |
| 78 | - } |
|
| 79 | - else { |
|
| 67 | + } else { |
|
| 80 | 68 | $result = $value_to_validate != $value; |
| 81 | 69 | } |
| 82 | - } |
|
| 83 | - elseif ($operator === NotInRule::operator) { |
|
| 70 | + } elseif ($operator === NotInRule::operator) { |
|
| 84 | 71 | if ( ! isset($value_to_validate)) { |
| 85 | 72 | $result = true; |
| 86 | - } |
|
| 87 | - else { |
|
| 73 | + } else { |
|
| 88 | 74 | $result = ! in_array($value_to_validate, $value); |
| 89 | 75 | } |
| 90 | - } |
|
| 91 | - else { |
|
| 76 | + } else { |
|
| 92 | 77 | throw new \InvalidArgumentException( |
| 93 | 78 | "Unhandled operator: " . $operator |
| 94 | 79 | ); |