@@ -16,7 +16,7 @@ |
||
| 16 | 16 | * @param LogicalFilter $filter |
| 17 | 17 | * @param Iterable $data_to_filter |
| 18 | 18 | */ |
| 19 | - public function apply( LogicalFilter $filter, $tree_to_filter, $options=[] ); |
|
| 19 | + public function apply(LogicalFilter $filter, $tree_to_filter, $options = []); |
|
| 20 | 20 | |
| 21 | 21 | public function validateRule($field, $operator, $value, $row, array $path, $all_operands, $options); |
| 22 | 22 | |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | { |
| 15 | 15 | /** |
| 16 | 16 | * @param LogicalFilter $filter |
| 17 | - * @param Iterable $data_to_filter |
|
| 17 | + * @param Iterable $tree_to_filter |
|
| 18 | 18 | */ |
| 19 | 19 | public function apply( LogicalFilter $filter, $tree_to_filter, $options=[] ); |
| 20 | 20 | |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | * @author Jean Claveau |
| 7 | 7 | */ |
| 8 | 8 | namespace JClaveau\LogicalFilter\Filterer; |
| 9 | -use JClaveau\LogicalFilter\LogicalFilter; |
|
| 9 | +use JClaveau\LogicalFilter\LogicalFilter; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | */ |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | */ |
| 19 | - public function __construct( callable $rule_validator ) |
|
| 19 | + public function __construct(callable $rule_validator) |
|
| 20 | 20 | { |
| 21 | 21 | $this->rule_validator = $rule_validator; |
| 22 | 22 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function validateRule($field, $operator, $value, $row, array $path, $all_operands, $options) |
| 27 | 27 | { |
| 28 | - return call_user_func_array( $this->rule_validator, get_defined_vars() ); |
|
| 28 | + return call_user_func_array($this->rule_validator, get_defined_vars()); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /**/ |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | /** |
| 35 | 35 | * @param LogicalFilter $filter |
| 36 | 36 | */ |
| 37 | - public function convert( LogicalFilter $filter ); |
|
| 37 | + public function convert(LogicalFilter $filter); |
|
| 38 | 38 | |
| 39 | 39 | /**/ |
| 40 | 40 | } |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function onOpenOr() |
| 32 | 32 | { |
| 33 | - call_user_func( $this->callbacks[ __FUNCTION__ ] ); |
|
| 33 | + call_user_func($this->callbacks[__FUNCTION__]); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | */ |
| 38 | 38 | public function onCloseOr() |
| 39 | 39 | { |
| 40 | - call_user_func( $this->callbacks[ __FUNCTION__ ] ); |
|
| 40 | + call_user_func($this->callbacks[__FUNCTION__]); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | public function onAndPossibility($field, $operator, $operand, array $allOperandsByField) |
| 48 | 48 | { |
| 49 | 49 | call_user_func( |
| 50 | - $this->callbacks[ __FUNCTION__ ], |
|
| 50 | + $this->callbacks[__FUNCTION__], |
|
| 51 | 51 | $field, |
| 52 | 52 | $operator, |
| 53 | 53 | $operand, |
@@ -14,10 +14,10 @@ |
||
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | */ |
| 17 | - public function __construct( $field, array $limits ) |
|
| 17 | + public function __construct($field, array $limits) |
|
| 18 | 18 | { |
| 19 | - $this->addOperand( new AboveOrEqualRule($field, $limits[0]) ); |
|
| 20 | - $this->addOperand( new BelowOrEqualRule($field, $limits[1]) ); |
|
| 19 | + $this->addOperand(new AboveOrEqualRule($field, $limits[0])); |
|
| 20 | + $this->addOperand(new BelowOrEqualRule($field, $limits[1])); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | */ |
| 32 | - public function getOption($name, array $contextual_options=[]) |
|
| 32 | + public function getOption($name, array $contextual_options = []) |
|
| 33 | 33 | { |
| 34 | 34 | $options = $this->getOptions($contextual_options); |
| 35 | 35 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * @param $contextual_options |
| 41 | 41 | */ |
| 42 | - public function getOptions(array $contextual_options=[]) |
|
| 42 | + public function getOptions(array $contextual_options = []) |
|
| 43 | 43 | { |
| 44 | 44 | $default_options = LogicalFilter::getDefaultOptions(); |
| 45 | 45 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @param string $field The field to apply the rule on. |
| 17 | 17 | * @param array $value The value the field can equal to. |
| 18 | 18 | */ |
| 19 | - public function __construct( $field, $value ) |
|
| 19 | + public function __construct($field, $value) |
|
| 20 | 20 | { |
| 21 | 21 | $this->field = $field; |
| 22 | 22 | $this->value = $value; |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return bool |
| 44 | 44 | */ |
| 45 | - public function hasSolution(array $contextual_options=[]) |
|
| 45 | + public function hasSolution(array $contextual_options = []) |
|
| 46 | 46 | { |
| 47 | 47 | return true; |
| 48 | 48 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | else { |
| 172 | 172 | throw new \InvalidArgumentException( |
| 173 | - "'mode' option must belong to ['string', 'export', 'dump'] " |
|
| 173 | + "'mode' option must belong to ['string', 'export', 'dump'] " |
|
| 174 | 174 | ."instead of " . var_export($mode, true) |
| 175 | 175 | ); |
| 176 | 176 | } |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | |
| 252 | 252 | // return hash('crc32b', serialize( $this->toArray() )); |
| 253 | 253 | return hash('md4', serialize( $this->toArray(['semantic' => true]) )) // faster but longer |
| 254 | - .'-' |
|
| 255 | - .hash('md4', serialize( $this->options )) |
|
| 256 | - ; |
|
| 254 | + .'-' |
|
| 255 | + .hash('md4', serialize( $this->options )) |
|
| 256 | + ; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -144,8 +144,7 @@ discard block |
||
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | echo ($this->toString($options)); |
| 147 | - } |
|
| 148 | - elseif ('dump' == $mode) { |
|
| 147 | + } elseif ('dump' == $mode) { |
|
| 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 ('xdebug' == $mode) { |
|
| 157 | + } elseif ('xdebug' == $mode) { |
|
| 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 ('export' == $mode) { |
|
| 174 | + } elseif ('export' == $mode) { |
|
| 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 |
@@ -42,6 +42,8 @@ |
||
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | + * @param string $symbolic_operator |
|
| 46 | + * @return string |
|
| 45 | 47 | */ |
| 46 | 48 | public static function findEnglishOperator($symbolic_operator) |
| 47 | 49 | { |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public static function findSymbolicOperator($english_operator) |
| 35 | 35 | { |
| 36 | - $association = array_flip( self::$ruleAliases ); |
|
| 37 | - if (isset($association[ $english_operator ])) { |
|
| 38 | - return $association[ $english_operator ]; |
|
| 36 | + $association = array_flip(self::$ruleAliases); |
|
| 37 | + if (isset($association[$english_operator])) { |
|
| 38 | + return $association[$english_operator]; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | return $english_operator; |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | public static function findEnglishOperator($symbolic_operator) |
| 47 | 47 | { |
| 48 | 48 | $association = self::$ruleAliases; |
| 49 | - if (isset($association[ $symbolic_operator ])) { |
|
| 50 | - return $association[ $symbolic_operator ]; |
|
| 49 | + if (isset($association[$symbolic_operator])) { |
|
| 50 | + return $association[$symbolic_operator]; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | return $symbolic_operator; |
@@ -66,16 +66,16 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return AbstractRule |
| 68 | 68 | */ |
| 69 | - public static function generateSimpleRule($field, $type, $values, array $options=[]) |
|
| 69 | + public static function generateSimpleRule($field, $type, $values, array $options = []) |
|
| 70 | 70 | { |
| 71 | - $cache_key = hash('md4', serialize( func_get_args()) ); |
|
| 71 | + $cache_key = hash('md4', serialize(func_get_args())); |
|
| 72 | 72 | if (isset(self::$static_cache['rules_generation'][$cache_key])) { |
| 73 | 73 | return self::$static_cache['rules_generation'][$cache_key]->copy(); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $ruleClass = self::getRuleClass($type); |
| 77 | 77 | |
| 78 | - return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass( $field, $values, $options ); |
|
| 78 | + return self::$static_cache['rules_generation'][$cache_key] = new $ruleClass($field, $values, $options); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | . str_replace('_', '', ucwords($english_rule_operator, '_')) |
| 93 | 93 | . 'Rule'; |
| 94 | 94 | |
| 95 | - if ( ! class_exists( $rule_class)) { |
|
| 95 | + if (!class_exists($rule_class)) { |
|
| 96 | 96 | throw new \InvalidArgumentException( |
| 97 | 97 | "The class '$rule_class' corresponding to the operator " |
| 98 | 98 | ."'$rule_operator' / '$english_rule_operator' cannot be found." |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * |
| 122 | 122 | * @return $this |
| 123 | 123 | */ |
| 124 | - final public function dump($exit=false, array $options=[]) |
|
| 124 | + final public function dump($exit = false, array $options = []) |
|
| 125 | 125 | { |
| 126 | 126 | $default_options = [ |
| 127 | 127 | 'callstack_depth' => 2, |
@@ -129,18 +129,18 @@ discard block |
||
| 129 | 129 | // 'show_instance' => false, |
| 130 | 130 | ]; |
| 131 | 131 | foreach ($default_options as $default_option => &$default_value) { |
| 132 | - if ( ! isset($options[ $default_option ])) { |
|
| 133 | - $options[ $default_option ] = $default_value; |
|
| 132 | + if (!isset($options[$default_option])) { |
|
| 133 | + $options[$default_option] = $default_value; |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | extract($options); |
| 137 | 137 | |
| 138 | 138 | $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $callstack_depth); |
| 139 | - $caller = $bt[ $callstack_depth - 2 ]; |
|
| 139 | + $caller = $bt[$callstack_depth - 2]; |
|
| 140 | 140 | |
| 141 | - echo "\n" . $caller['file'] . ':' . $caller['line'] . "\n"; |
|
| 141 | + echo "\n".$caller['file'].':'.$caller['line']."\n"; |
|
| 142 | 142 | if ('string' == $mode) { |
| 143 | - if ( ! isset($options['indent_unit'])) { |
|
| 143 | + if (!isset($options['indent_unit'])) { |
|
| 144 | 144 | $options['indent_unit'] = " "; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -158,10 +158,10 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | elseif ('xdebug' == $mode) { |
| 161 | - if ( ! function_exists('xdebug_is_enabled')) { |
|
| 161 | + if (!function_exists('xdebug_is_enabled')) { |
|
| 162 | 162 | throw new \RuntimeException("Xdebug is not installed"); |
| 163 | 163 | } |
| 164 | - if ( ! xdebug_is_enabled()) { |
|
| 164 | + if (!xdebug_is_enabled()) { |
|
| 165 | 165 | throw new \RuntimeException("Xdebug is disabled"); |
| 166 | 166 | } |
| 167 | 167 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | else { |
| 182 | 182 | throw new \InvalidArgumentException( |
| 183 | 183 | "'mode' option must belong to ['string', 'export', 'dump'] " |
| 184 | - ."instead of " . var_export($mode, true) |
|
| 184 | + ."instead of ".var_export($mode, true) |
|
| 185 | 185 | ); |
| 186 | 186 | } |
| 187 | 187 | echo "\n\n"; |
@@ -236,12 +236,12 @@ discard block |
||
| 236 | 236 | /** |
| 237 | 237 | * @return string |
| 238 | 238 | */ |
| 239 | - abstract public function toString(array $options=[]); |
|
| 239 | + abstract public function toString(array $options = []); |
|
| 240 | 240 | |
| 241 | 241 | /** |
| 242 | 242 | * @return array |
| 243 | 243 | */ |
| 244 | - abstract public function toArray(array $options=[]); |
|
| 244 | + abstract public function toArray(array $options = []); |
|
| 245 | 245 | |
| 246 | 246 | protected $instance_id; |
| 247 | 247 | |
@@ -273,9 +273,9 @@ discard block |
||
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // return hash('crc32b', serialize( $this->toArray() )); |
| 276 | - return hash('md4', serialize( $this->toArray(['semantic' => true]) )) // faster but longer |
|
| 276 | + return hash('md4', serialize($this->toArray(['semantic' => true]))) // faster but longer |
|
| 277 | 277 | .'-' |
| 278 | - .hash('md4', serialize( $this->options )) |
|
| 278 | + .hash('md4', serialize($this->options)) |
|
| 279 | 279 | ; |
| 280 | 280 | } |
| 281 | 281 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | } |
| 308 | 308 | elseif ($this instanceof OrRule) { |
| 309 | 309 | foreach ($this->operands as $i => $operand) { |
| 310 | - if ( ! $operand instanceof AndRule) { |
|
| 310 | + if (!$operand instanceof AndRule) { |
|
| 311 | 311 | $this->operands[$i] = new AndRule([$operand]); |
| 312 | 312 | } |
| 313 | 313 | } |
@@ -50,13 +50,11 @@ |
||
| 50 | 50 | { |
| 51 | 51 | if (is_callable($renamings)) { |
| 52 | 52 | $this->setField( call_user_func($renamings, $this->field) ); |
| 53 | - } |
|
| 54 | - elseif (is_array($renamings)) { |
|
| 53 | + } elseif (is_array($renamings)) { |
|
| 55 | 54 | if (isset($renamings[$this->field])) { |
| 56 | 55 | $this->setField( $renamings[$this->field] ); |
| 57 | 56 | } |
| 58 | - } |
|
| 59 | - else { |
|
| 57 | + } else { |
|
| 60 | 58 | throw new \InvalidArgumentException( |
| 61 | 59 | "\$renamings MUST be a callable or an associative array " |
| 62 | 60 | ."instead of: " . var_export($renamings, true) |
@@ -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 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | - * @return string $field |
|
| 24 | + * @return Trait_RuleWithField $field |
|
| 25 | 25 | */ |
| 26 | 26 | final public function setField( $field ) |
| 27 | 27 | { |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param array|callable Associative array of renamings or callable |
| 45 | 45 | * that would rename the fields. |
| 46 | 46 | * |
| 47 | - * @return AbstractAtomicRule $this |
|
| 47 | + * @return Trait_RuleWithField $this |
|
| 48 | 48 | */ |
| 49 | 49 | final public function renameField($renamings) |
| 50 | 50 | { |