@@ -70,18 +70,18 @@ discard block |
||
| 70 | 70 | protected function buildMap(ReflectionEntity $filter): array |
| 71 | 71 | { |
| 72 | 72 | $schema = $filter->getProperty('schema', true); |
| 73 | - if (empty($schema)) { |
|
| 73 | + if (empty($schema)){ |
|
| 74 | 74 | throw new SchemaException("Filter `{$filter->getName()}` does not define any schema"); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $result = []; |
| 78 | - foreach ($schema as $field => $definition) { |
|
| 78 | + foreach ($schema as $field => $definition){ |
|
| 79 | 79 | $optional = false; |
| 80 | 80 | |
| 81 | 81 | // short definition |
| 82 | - if (is_string($definition)) { |
|
| 82 | + if (is_string($definition)){ |
|
| 83 | 83 | // simple scalar field definition |
| 84 | - if (!class_exists($definition)) { |
|
| 84 | + if (!class_exists($definition)){ |
|
| 85 | 85 | [$source, $origin] = $this->parseDefinition($field, $definition); |
| 86 | 86 | $result[$field] = [ |
| 87 | 87 | FilterProvider::SOURCE => $source, |
@@ -102,25 +102,25 @@ discard block |
||
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if (!is_array($definition) || count($definition) === 0) { |
|
| 105 | + if (!is_array($definition) || count($definition) === 0){ |
|
| 106 | 106 | throw new SchemaException( |
| 107 | 107 | "Invalid schema definition at `{$filter->getName()}`->`{$field}`" |
| 108 | 108 | ); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // complex definition |
| 112 | - if (!empty($definition[self::ORIGIN])) { |
|
| 112 | + if (!empty($definition[self::ORIGIN])){ |
|
| 113 | 113 | $origin = $definition[self::ORIGIN]; |
| 114 | 114 | |
| 115 | 115 | // [class, 'data:something.*'] vs [class, 'data:something'] |
| 116 | 116 | $iterate = strpos($origin, '.*') !== false || !empty($definition[self::ITERATE]); |
| 117 | 117 | $origin = rtrim($origin, '.*'); |
| 118 | - } else { |
|
| 118 | + }else{ |
|
| 119 | 119 | $origin = $field; |
| 120 | 120 | $iterate = true; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if (!empty($definition[self::OPTIONAL]) && $definition[self::OPTIONAL]) { |
|
| 123 | + if (!empty($definition[self::OPTIONAL]) && $definition[self::OPTIONAL]){ |
|
| 124 | 124 | $optional = true; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | FilterProvider::OPTIONAL => $optional, |
| 134 | 134 | ]; |
| 135 | 135 | |
| 136 | - if ($iterate) { |
|
| 136 | + if ($iterate){ |
|
| 137 | 137 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
| 138 | 138 | |
| 139 | 139 | $map[FilterProvider::ITERATE_SOURCE] = $source; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | private function parseDefinition(string $field, string $definition): array |
| 161 | 161 | { |
| 162 | - if (strpos($definition, ':') === false) { |
|
| 162 | + if (strpos($definition, ':') === false){ |
|
| 163 | 163 | return ['data', $definition ?? $field]; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | array $schema, |
| 90 | 90 | ValidatorInterface $validator, |
| 91 | 91 | ErrorMapper $errorMapper |
| 92 | - ) { |
|
| 92 | + ){ |
|
| 93 | 93 | parent::__construct($data, $schema); |
| 94 | 94 | |
| 95 | 95 | $this->mappings = $schema[FilterProvider::MAPPING] ?? []; |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | public function getErrors(): array |
| 162 | 162 | { |
| 163 | - if ($this->errors === null) { |
|
| 163 | + if ($this->errors === null){ |
|
| 164 | 164 | $this->errors = []; |
| 165 | - foreach ($this->validator->withData($this)->getErrors() as $field => $error) { |
|
| 166 | - if (is_string($error) && Translator::isMessage($error)) { |
|
| 165 | + foreach ($this->validator->withData($this)->getErrors() as $field => $error){ |
|
| 166 | + if (is_string($error) && Translator::isMessage($error)){ |
|
| 167 | 167 | // translate error message |
| 168 | 168 | $error = $this->say($error); |
| 169 | 169 | } |
@@ -195,36 +195,36 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | protected function validateNested(array $errors): array |
| 197 | 197 | { |
| 198 | - foreach ($this->getFields(false) as $index => $value) { |
|
| 199 | - if (isset($errors[$index])) { |
|
| 198 | + foreach ($this->getFields(false) as $index => $value){ |
|
| 199 | + if (isset($errors[$index])){ |
|
| 200 | 200 | //Invalid on parent level |
| 201 | 201 | continue; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - if ($value instanceof FilterInterface) { |
|
| 204 | + if ($value instanceof FilterInterface){ |
|
| 205 | 205 | $isOptional = $this->mappings[$index][FilterProvider::OPTIONAL] ?? false; |
| 206 | 206 | |
| 207 | - if ($isOptional && $this->getField($index) !== []) { |
|
| 207 | + if ($isOptional && $this->getField($index) !== []){ |
|
| 208 | 208 | continue; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if (!$value->isValid()) { |
|
| 211 | + if (!$value->isValid()){ |
|
| 212 | 212 | $errors[$index] = $value->getErrors(); |
| 213 | 213 | continue; |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | //Array of nested entities for validation |
| 218 | - if (is_iterable($value)) { |
|
| 219 | - foreach ($value as $nIndex => $nValue) { |
|
| 220 | - if ($nValue instanceof FilterInterface) { |
|
| 218 | + if (is_iterable($value)){ |
|
| 219 | + foreach ($value as $nIndex => $nValue){ |
|
| 220 | + if ($nValue instanceof FilterInterface){ |
|
| 221 | 221 | $isOptional = $this->mappings[$index][FilterProvider::OPTIONAL] ?? false; |
| 222 | 222 | |
| 223 | - if ($isOptional && $this->getField($nIndex) !== []) { |
|
| 223 | + if ($isOptional && $this->getField($nIndex) !== []){ |
|
| 224 | 224 | continue; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - if (!$nValue->isValid()) { |
|
| 227 | + if (!$nValue->isValid()){ |
|
| 228 | 228 | $errors[$index][$nIndex] = $nValue->getErrors(); |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -63,8 +63,8 @@ |
||
| 63 | 63 | #[\ReturnTypeWillChange] |
| 64 | 64 | public function gc($maxlifetime) |
| 65 | 65 | { |
| 66 | - foreach ($this->files->getFiles($this->directory) as $filename) { |
|
| 67 | - if ($this->files->time($filename) < time() - $maxlifetime) { |
|
| 66 | + foreach ($this->files->getFiles($this->directory) as $filename){ |
|
| 67 | + if ($this->files->time($filename) < time() - $maxlifetime){ |
|
| 68 | 68 | $this->files->delete($filename); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -72,7 +72,7 @@ |
||
| 72 | 72 | #[\ReturnTypeWillChange] |
| 73 | 73 | public function offsetGet($offset) |
| 74 | 74 | { |
| 75 | - if (!$this->offsetExists($offset)) { |
|
| 75 | + if (!$this->offsetExists($offset)){ |
|
| 76 | 76 | throw new ConfigException("Undefined configuration key '{$offset}'"); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function getIterator(): \Traversable |
| 48 | 48 | { |
| 49 | - while ($n = $this->next()) { |
|
| 49 | + while ($n = $this->next()){ |
|
| 50 | 50 | yield $n; |
| 51 | 51 | } |
| 52 | 52 | } |
@@ -64,18 +64,18 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function next() |
| 66 | 66 | { |
| 67 | - if ($this->replay !== []) { |
|
| 67 | + if ($this->replay !== []){ |
|
| 68 | 68 | $n = array_shift($this->replay); |
| 69 | - } else { |
|
| 69 | + }else{ |
|
| 70 | 70 | $n = $this->generator->current(); |
| 71 | - if ($n === null) { |
|
| 71 | + if ($n === null){ |
|
| 72 | 72 | return null; |
| 73 | 73 | } |
| 74 | 74 | $this->generator->next(); |
| 75 | 75 | $this->buffer[] = $n; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if ($n !== null) { |
|
| 78 | + if ($n !== null){ |
|
| 79 | 79 | $this->offset = $n->offset; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | public function nextBytes(): string |
| 91 | 91 | { |
| 92 | 92 | $result = ''; |
| 93 | - while ($n = $this->next()) { |
|
| 94 | - if ($n instanceof Byte) { |
|
| 93 | + while ($n = $this->next()){ |
|
| 94 | + if ($n instanceof Byte){ |
|
| 95 | 95 | $result .= $n->char; |
| 96 | - } else { |
|
| 96 | + }else{ |
|
| 97 | 97 | break; |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public function lookahead() |
| 108 | 108 | { |
| 109 | - if ($this->replay !== []) { |
|
| 109 | + if ($this->replay !== []){ |
|
| 110 | 110 | return $this->replay[0]; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $n = $this->next(); |
| 114 | - if ($n !== null) { |
|
| 114 | + if ($n !== null){ |
|
| 115 | 115 | array_unshift($this->replay, $n); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -128,20 +128,20 @@ discard block |
||
| 128 | 128 | { |
| 129 | 129 | $result = ''; |
| 130 | 130 | $replay = []; |
| 131 | - for ($i = 0; $i < $size; $i++) { |
|
| 131 | + for ($i = 0; $i < $size; $i++){ |
|
| 132 | 132 | $n = $this->next(); |
| 133 | - if ($n !== null) { |
|
| 133 | + if ($n !== null){ |
|
| 134 | 134 | $replay[] = $n; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if (!$n instanceof Byte) { |
|
| 137 | + if (!$n instanceof Byte){ |
|
| 138 | 138 | break; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $result .= $n->char; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - foreach (array_reverse($replay) as $n) { |
|
| 144 | + foreach (array_reverse($replay) as $n){ |
|
| 145 | 145 | array_unshift($this->replay, $n); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -155,8 +155,8 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | public function replay(int $offset): void |
| 157 | 157 | { |
| 158 | - foreach ($this->buffer as $n) { |
|
| 159 | - if ($n->offset > $offset) { |
|
| 158 | + foreach ($this->buffer as $n){ |
|
| 159 | + if ($n->offset > $offset){ |
|
| 160 | 160 | $this->replay[] = $n; |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -51,39 +51,39 @@ discard block |
||
| 51 | 51 | $this->body = null; |
| 52 | 52 | $hasWhitespace = false; |
| 53 | 53 | |
| 54 | - while ($n = $src->next()) { |
|
| 55 | - if (!$n instanceof Byte) { |
|
| 54 | + while ($n = $src->next()){ |
|
| 55 | + if (!$n instanceof Byte){ |
|
| 56 | 56 | // no other grammars are allowed |
| 57 | 57 | break; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - switch ($n->char) { |
|
| 60 | + switch ($n->char){ |
|
| 61 | 61 | case '(': |
| 62 | 62 | $this->flushName(); |
| 63 | 63 | $this->tokens[] = new Token(DynamicGrammar::TYPE_BODY_OPEN, $n->offset, $n->char); |
| 64 | 64 | |
| 65 | 65 | return $this->parseBody($src); |
| 66 | 66 | default: |
| 67 | - if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
| 67 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)){ |
|
| 68 | 68 | $hasWhitespace = true; |
| 69 | - if ($this->name !== []) { |
|
| 69 | + if ($this->name !== []){ |
|
| 70 | 70 | $this->flushName(); |
| 71 | 71 | $this->tokens[] = new Token(DynamicGrammar::TYPE_WHITESPACE, $n->offset, $n->char); |
| 72 | 72 | break; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) { |
|
| 75 | + if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE){ |
|
| 76 | 76 | $this->getLastToken()->content .= $n->char; |
| 77 | 77 | break; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // invalid directive |
| 81 | 81 | return false; |
| 82 | - } elseif ($hasWhitespace) { |
|
| 82 | + } elseif ($hasWhitespace){ |
|
| 83 | 83 | return $this->finalize(); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if (!preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
| 86 | + if (!preg_match(self::REGEXP_KEYWORD, $n->char)){ |
|
| 87 | 87 | $this->flushName(); |
| 88 | 88 | |
| 89 | 89 | return $this->finalize(); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function getIterator(): \Traversable |
| 107 | 107 | { |
| 108 | - if ($this->tokens === []) { |
|
| 108 | + if ($this->tokens === []){ |
|
| 109 | 109 | throw new \LogicException('Directive not parsed'); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function getKeyword(): string |
| 131 | 131 | { |
| 132 | - foreach ($this->tokens as $token) { |
|
| 133 | - if ($token->type === DynamicGrammar::TYPE_KEYWORD) { |
|
| 132 | + foreach ($this->tokens as $token){ |
|
| 133 | + if ($token->type === DynamicGrammar::TYPE_KEYWORD){ |
|
| 134 | 134 | return $token->content; |
| 135 | 135 | } |
| 136 | 136 | } |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | public function getBody(): ?string |
| 147 | 147 | { |
| 148 | - foreach ($this->tokens as $token) { |
|
| 149 | - if ($token->type === DynamicGrammar::TYPE_BODY) { |
|
| 148 | + foreach ($this->tokens as $token){ |
|
| 149 | + if ($token->type === DynamicGrammar::TYPE_BODY){ |
|
| 150 | 150 | return $token->content; |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | private function flushName(): void |
| 161 | 161 | { |
| 162 | - if ($this->name === []) { |
|
| 162 | + if ($this->name === []){ |
|
| 163 | 163 | return; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -176,17 +176,17 @@ discard block |
||
| 176 | 176 | $this->body = []; |
| 177 | 177 | $level = 1; |
| 178 | 178 | |
| 179 | - while ($nn = $src->next()) { |
|
| 180 | - if (!$nn instanceof Byte) { |
|
| 179 | + while ($nn = $src->next()){ |
|
| 180 | + if (!$nn instanceof Byte){ |
|
| 181 | 181 | $this->flushBody(); |
| 182 | 182 | return $this->finalize(); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if (in_array($nn->char, ['"', '"'])) { |
|
| 185 | + if (in_array($nn->char, ['"', '"'])){ |
|
| 186 | 186 | $this->body[] = $nn; |
| 187 | - while ($nnn = $src->next()) { |
|
| 187 | + while ($nnn = $src->next()){ |
|
| 188 | 188 | $this->body[] = $nnn; |
| 189 | - if ($nnn instanceof Byte && $nnn->char === $nn->char) { |
|
| 189 | + if ($nnn instanceof Byte && $nnn->char === $nn->char){ |
|
| 190 | 190 | break; |
| 191 | 191 | } |
| 192 | 192 | } |
@@ -195,15 +195,15 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | $this->body[] = $nn; |
| 197 | 197 | |
| 198 | - if ($nn->char === '(') { |
|
| 198 | + if ($nn->char === '('){ |
|
| 199 | 199 | $level++; |
| 200 | 200 | continue; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if ($nn->char === ')') { |
|
| 203 | + if ($nn->char === ')'){ |
|
| 204 | 204 | $level--; |
| 205 | 205 | |
| 206 | - if ($level === 0) { |
|
| 206 | + if ($level === 0){ |
|
| 207 | 207 | $n = array_pop($this->body); |
| 208 | 208 | |
| 209 | 209 | $this->flushBody(); |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | private function flushBody(): void |
| 226 | 226 | { |
| 227 | - if ($this->body === []) { |
|
| 227 | + if ($this->body === []){ |
|
| 228 | 228 | return; |
| 229 | 229 | } |
| 230 | 230 | |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | private function getLastToken(): Token |
| 239 | 239 | { |
| 240 | - if ($this->tokens === []) { |
|
| 240 | + if ($this->tokens === []){ |
|
| 241 | 241 | throw new \LogicException('Directive not parsed'); |
| 242 | 242 | } |
| 243 | 243 | |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | { |
| 254 | 254 | $tokens = $this->tokens; |
| 255 | 255 | |
| 256 | - foreach (array_reverse($tokens, true) as $i => $t) { |
|
| 257 | - if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) { |
|
| 256 | + foreach (array_reverse($tokens, true) as $i => $t){ |
|
| 257 | + if ($t->type !== DynamicGrammar::TYPE_WHITESPACE){ |
|
| 258 | 258 | break; |
| 259 | 259 | } |
| 260 | 260 | |
@@ -262,19 +262,19 @@ discard block |
||
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | $body = null; |
| 265 | - foreach ($tokens as $t) { |
|
| 266 | - if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) { |
|
| 265 | + foreach ($tokens as $t){ |
|
| 266 | + if ($t->type === DynamicGrammar::TYPE_BODY_OPEN){ |
|
| 267 | 267 | $body = false; |
| 268 | 268 | continue; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) { |
|
| 271 | + if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE){ |
|
| 272 | 272 | $body = null; |
| 273 | 273 | continue; |
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - if ($body !== null) { |
|
| 277 | + if ($body !== null){ |
|
| 278 | 278 | return false; |
| 279 | 279 | } |
| 280 | 280 | |