| @@ -63,8 +63,10 @@ | ||
| 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 | +        { | |
| 68 | + if ($this->files->time($filename) < time() - $maxlifetime) | |
| 69 | +            { | |
| 68 | 70 | $this->files->delete($filename); | 
| 69 | 71 | } | 
| 70 | 72 | } | 
| @@ -72,7 +72,8 @@ | ||
| 72 | 72 | #[\ReturnTypeWillChange] | 
| 73 | 73 | public function offsetGet($offset) | 
| 74 | 74 |      { | 
| 75 | -        if (!$this->offsetExists($offset)) { | |
| 75 | + if (!$this->offsetExists($offset)) | |
| 76 | +        { | |
| 76 | 77 |              throw new ConfigException("Undefined configuration key '{$offset}'"); | 
| 77 | 78 | } | 
| 78 | 79 | |
| @@ -46,7 +46,8 @@ discard block | ||
| 46 | 46 | */ | 
| 47 | 47 | public function getIterator(): \Traversable | 
| 48 | 48 |      { | 
| 49 | -        while ($n = $this->next()) { | |
| 49 | + while ($n = $this->next()) | |
| 50 | +        { | |
| 50 | 51 | yield $n; | 
| 51 | 52 | } | 
| 52 | 53 | } | 
| @@ -64,18 +65,23 @@ discard block | ||
| 64 | 65 | */ | 
| 65 | 66 | public function next() | 
| 66 | 67 |      { | 
| 67 | -        if ($this->replay !== []) { | |
| 68 | + if ($this->replay !== []) | |
| 69 | +        { | |
| 68 | 70 | $n = array_shift($this->replay); | 
| 69 | -        } else { | |
| 71 | + } | |
| 72 | + else | |
| 73 | +        { | |
| 70 | 74 | $n = $this->generator->current(); | 
| 71 | -            if ($n === null) { | |
| 75 | + if ($n === null) | |
| 76 | +            { | |
| 72 | 77 | return null; | 
| 73 | 78 | } | 
| 74 | 79 | $this->generator->next(); | 
| 75 | 80 | $this->buffer[] = $n; | 
| 76 | 81 | } | 
| 77 | 82 | |
| 78 | -        if ($n !== null) { | |
| 83 | + if ($n !== null) | |
| 84 | +        { | |
| 79 | 85 | $this->offset = $n->offset; | 
| 80 | 86 | } | 
| 81 | 87 | |
| @@ -90,10 +96,14 @@ discard block | ||
| 90 | 96 | public function nextBytes(): string | 
| 91 | 97 |      { | 
| 92 | 98 | $result = ''; | 
| 93 | -        while ($n = $this->next()) { | |
| 94 | -            if ($n instanceof Byte) { | |
| 99 | + while ($n = $this->next()) | |
| 100 | +        { | |
| 101 | + if ($n instanceof Byte) | |
| 102 | +            { | |
| 95 | 103 | $result .= $n->char; | 
| 96 | -            } else { | |
| 104 | + } | |
| 105 | + else | |
| 106 | +            { | |
| 97 | 107 | break; | 
| 98 | 108 | } | 
| 99 | 109 | } | 
| @@ -106,12 +116,14 @@ discard block | ||
| 106 | 116 | */ | 
| 107 | 117 | public function lookahead() | 
| 108 | 118 |      { | 
| 109 | -        if ($this->replay !== []) { | |
| 119 | + if ($this->replay !== []) | |
| 120 | +        { | |
| 110 | 121 | return $this->replay[0]; | 
| 111 | 122 | } | 
| 112 | 123 | |
| 113 | 124 | $n = $this->next(); | 
| 114 | -        if ($n !== null) { | |
| 125 | + if ($n !== null) | |
| 126 | +        { | |
| 115 | 127 | array_unshift($this->replay, $n); | 
| 116 | 128 | } | 
| 117 | 129 | |
| @@ -128,20 +140,24 @@ discard block | ||
| 128 | 140 |      { | 
| 129 | 141 | $result = ''; | 
| 130 | 142 | $replay = []; | 
| 131 | -        for ($i = 0; $i < $size; $i++) { | |
| 143 | + for ($i = 0; $i < $size; $i++) | |
| 144 | +        { | |
| 132 | 145 | $n = $this->next(); | 
| 133 | -            if ($n !== null) { | |
| 146 | + if ($n !== null) | |
| 147 | +            { | |
| 134 | 148 | $replay[] = $n; | 
| 135 | 149 | } | 
| 136 | 150 | |
| 137 | -            if (!$n instanceof Byte) { | |
| 151 | + if (!$n instanceof Byte) | |
| 152 | +            { | |
| 138 | 153 | break; | 
| 139 | 154 | } | 
| 140 | 155 | |
| 141 | 156 | $result .= $n->char; | 
| 142 | 157 | } | 
| 143 | 158 | |
| 144 | -        foreach (array_reverse($replay) as $n) { | |
| 159 | + foreach (array_reverse($replay) as $n) | |
| 160 | +        { | |
| 145 | 161 | array_unshift($this->replay, $n); | 
| 146 | 162 | } | 
| 147 | 163 | |
| @@ -155,8 +171,10 @@ discard block | ||
| 155 | 171 | */ | 
| 156 | 172 | public function replay(int $offset): void | 
| 157 | 173 |      { | 
| 158 | -        foreach ($this->buffer as $n) { | |
| 159 | -            if ($n->offset > $offset) { | |
| 174 | + foreach ($this->buffer as $n) | |
| 175 | +        { | |
| 176 | + if ($n->offset > $offset) | |
| 177 | +            { | |
| 160 | 178 | $this->replay[] = $n; | 
| 161 | 179 | } | 
| 162 | 180 | } | 
| @@ -51,39 +51,48 @@ 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 | +        { | |
| 56 | + if (!$n instanceof Byte) | |
| 57 | +            { | |
| 56 | 58 | // no other grammars are allowed | 
| 57 | 59 | break; | 
| 58 | 60 | } | 
| 59 | 61 | |
| 60 | -            switch ($n->char) { | |
| 62 | + switch ($n->char) | |
| 63 | +            { | |
| 61 | 64 |                  case '(': | 
| 62 | 65 | $this->flushName(); | 
| 63 | 66 | $this->tokens[] = new Token(DynamicGrammar::TYPE_BODY_OPEN, $n->offset, $n->char); | 
| 64 | 67 | |
| 65 | 68 | return $this->parseBody($src); | 
| 66 | 69 | default: | 
| 67 | -                    if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { | |
| 70 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)) | |
| 71 | +                    { | |
| 68 | 72 | $hasWhitespace = true; | 
| 69 | -                        if ($this->name !== []) { | |
| 73 | + if ($this->name !== []) | |
| 74 | +                        { | |
| 70 | 75 | $this->flushName(); | 
| 71 | 76 | $this->tokens[] = new Token(DynamicGrammar::TYPE_WHITESPACE, $n->offset, $n->char); | 
| 72 | 77 | break; | 
| 73 | 78 | } | 
| 74 | 79 | |
| 75 | -                        if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) { | |
| 80 | + if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) | |
| 81 | +                        { | |
| 76 | 82 | $this->getLastToken()->content .= $n->char; | 
| 77 | 83 | break; | 
| 78 | 84 | } | 
| 79 | 85 | |
| 80 | 86 | // invalid directive | 
| 81 | 87 | return false; | 
| 82 | -                    } elseif ($hasWhitespace) { | |
| 88 | + } | |
| 89 | + elseif ($hasWhitespace) | |
| 90 | +                    { | |
| 83 | 91 | return $this->finalize(); | 
| 84 | 92 | } | 
| 85 | 93 | |
| 86 | -                    if (!preg_match(self::REGEXP_KEYWORD, $n->char)) { | |
| 94 | + if (!preg_match(self::REGEXP_KEYWORD, $n->char)) | |
| 95 | +                    { | |
| 87 | 96 | $this->flushName(); | 
| 88 | 97 | |
| 89 | 98 | return $this->finalize(); | 
| @@ -105,7 +114,8 @@ discard block | ||
| 105 | 114 | */ | 
| 106 | 115 | public function getIterator(): \Traversable | 
| 107 | 116 |      { | 
| 108 | -        if ($this->tokens === []) { | |
| 117 | + if ($this->tokens === []) | |
| 118 | +        { | |
| 109 | 119 |              throw new \LogicException('Directive not parsed'); | 
| 110 | 120 | } | 
| 111 | 121 | |
| @@ -129,8 +139,10 @@ discard block | ||
| 129 | 139 | */ | 
| 130 | 140 | public function getKeyword(): string | 
| 131 | 141 |      { | 
| 132 | -        foreach ($this->tokens as $token) { | |
| 133 | -            if ($token->type === DynamicGrammar::TYPE_KEYWORD) { | |
| 142 | + foreach ($this->tokens as $token) | |
| 143 | +        { | |
| 144 | + if ($token->type === DynamicGrammar::TYPE_KEYWORD) | |
| 145 | +            { | |
| 134 | 146 | return $token->content; | 
| 135 | 147 | } | 
| 136 | 148 | } | 
| @@ -145,8 +157,10 @@ discard block | ||
| 145 | 157 | */ | 
| 146 | 158 | public function getBody(): ?string | 
| 147 | 159 |      { | 
| 148 | -        foreach ($this->tokens as $token) { | |
| 149 | -            if ($token->type === DynamicGrammar::TYPE_BODY) { | |
| 160 | + foreach ($this->tokens as $token) | |
| 161 | +        { | |
| 162 | + if ($token->type === DynamicGrammar::TYPE_BODY) | |
| 163 | +            { | |
| 150 | 164 | return $token->content; | 
| 151 | 165 | } | 
| 152 | 166 | } | 
| @@ -159,7 +173,8 @@ discard block | ||
| 159 | 173 | */ | 
| 160 | 174 | private function flushName(): void | 
| 161 | 175 |      { | 
| 162 | -        if ($this->name === []) { | |
| 176 | + if ($this->name === []) | |
| 177 | +        { | |
| 163 | 178 | return; | 
| 164 | 179 | } | 
| 165 | 180 | |
| @@ -176,17 +191,22 @@ discard block | ||
| 176 | 191 | $this->body = []; | 
| 177 | 192 | $level = 1; | 
| 178 | 193 | |
| 179 | -        while ($nn = $src->next()) { | |
| 180 | -            if (!$nn instanceof Byte) { | |
| 194 | + while ($nn = $src->next()) | |
| 195 | +        { | |
| 196 | + if (!$nn instanceof Byte) | |
| 197 | +            { | |
| 181 | 198 | $this->flushBody(); | 
| 182 | 199 | return $this->finalize(); | 
| 183 | 200 | } | 
| 184 | 201 | |
| 185 | -            if (in_array($nn->char, ['"', '"'])) { | |
| 202 | + if (in_array($nn->char, ['"', '"'])) | |
| 203 | +            { | |
| 186 | 204 | $this->body[] = $nn; | 
| 187 | -                while ($nnn = $src->next()) { | |
| 205 | + while ($nnn = $src->next()) | |
| 206 | +                { | |
| 188 | 207 | $this->body[] = $nnn; | 
| 189 | -                    if ($nnn instanceof Byte && $nnn->char === $nn->char) { | |
| 208 | + if ($nnn instanceof Byte && $nnn->char === $nn->char) | |
| 209 | +                    { | |
| 190 | 210 | break; | 
| 191 | 211 | } | 
| 192 | 212 | } | 
| @@ -195,15 +215,18 @@ discard block | ||
| 195 | 215 | |
| 196 | 216 | $this->body[] = $nn; | 
| 197 | 217 | |
| 198 | -            if ($nn->char === '(') { | |
| 218 | +            if ($nn->char === '(') | |
| 219 | +            { | |
| 199 | 220 | $level++; | 
| 200 | 221 | continue; | 
| 201 | 222 | } | 
| 202 | 223 | |
| 203 | -            if ($nn->char === ')') { | |
| 224 | + if ($nn->char === ')') | |
| 225 | +            { | |
| 204 | 226 | $level--; | 
| 205 | 227 | |
| 206 | -                if ($level === 0) { | |
| 228 | + if ($level === 0) | |
| 229 | +                { | |
| 207 | 230 | $n = array_pop($this->body); | 
| 208 | 231 | |
| 209 | 232 | $this->flushBody(); | 
| @@ -224,7 +247,8 @@ discard block | ||
| 224 | 247 | */ | 
| 225 | 248 | private function flushBody(): void | 
| 226 | 249 |      { | 
| 227 | -        if ($this->body === []) { | |
| 250 | + if ($this->body === []) | |
| 251 | +        { | |
| 228 | 252 | return; | 
| 229 | 253 | } | 
| 230 | 254 | |
| @@ -237,7 +261,8 @@ discard block | ||
| 237 | 261 | */ | 
| 238 | 262 | private function getLastToken(): Token | 
| 239 | 263 |      { | 
| 240 | -        if ($this->tokens === []) { | |
| 264 | + if ($this->tokens === []) | |
| 265 | +        { | |
| 241 | 266 |              throw new \LogicException('Directive not parsed'); | 
| 242 | 267 | } | 
| 243 | 268 | |
| @@ -253,8 +278,10 @@ discard block | ||
| 253 | 278 |      { | 
| 254 | 279 | $tokens = $this->tokens; | 
| 255 | 280 | |
| 256 | -        foreach (array_reverse($tokens, true) as $i => $t) { | |
| 257 | -            if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) { | |
| 281 | + foreach (array_reverse($tokens, true) as $i => $t) | |
| 282 | +        { | |
| 283 | + if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) | |
| 284 | +            { | |
| 258 | 285 | break; | 
| 259 | 286 | } | 
| 260 | 287 | |
| @@ -262,19 +289,23 @@ discard block | ||
| 262 | 289 | } | 
| 263 | 290 | |
| 264 | 291 | $body = null; | 
| 265 | -        foreach ($tokens as $t) { | |
| 266 | -            if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) { | |
| 292 | + foreach ($tokens as $t) | |
| 293 | +        { | |
| 294 | + if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) | |
| 295 | +            { | |
| 267 | 296 | $body = false; | 
| 268 | 297 | continue; | 
| 269 | 298 | } | 
| 270 | 299 | |
| 271 | -            if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) { | |
| 300 | + if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) | |
| 301 | +            { | |
| 272 | 302 | $body = null; | 
| 273 | 303 | continue; | 
| 274 | 304 | } | 
| 275 | 305 | } | 
| 276 | 306 | |
| 277 | -        if ($body !== null) { | |
| 307 | + if ($body !== null) | |
| 308 | +        { | |
| 278 | 309 | return false; | 
| 279 | 310 | } | 
| 280 | 311 | |