@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * TODO add return type |
| 85 | 85 | */ |
| 86 | - public function remove(string|array $name): void |
|
| 86 | + public function remove(string | array $name): void |
|
| 87 | 87 | { |
| 88 | - foreach ((array) $name as $n) { |
|
| 88 | + foreach ((array)$name as $n){ |
|
| 89 | 89 | unset($this->routes[$n]); |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function addCollection(self $collection): void |
| 99 | 99 | { |
| 100 | - foreach ($collection->all() as $name => $route) { |
|
| 100 | + foreach ($collection->all() as $name => $route){ |
|
| 101 | 101 | $this->routes[$name] = $route; |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -113,14 +113,14 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function group(string $group): void |
| 115 | 115 | { |
| 116 | - foreach ($this->routes as $route) { |
|
| 116 | + foreach ($this->routes as $route){ |
|
| 117 | 117 | $route->group($group); |
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | public function __clone() |
| 122 | 122 | { |
| 123 | - foreach ($this->routes as $name => $route) { |
|
| 123 | + foreach ($this->routes as $name => $route){ |
|
| 124 | 124 | $this->routes[$name] = clone $route; |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -85,7 +85,8 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function remove(string|array $name): void |
| 87 | 87 | { |
| 88 | - foreach ((array) $name as $n) { |
|
| 88 | + foreach ((array) $name as $n) |
|
| 89 | + { |
|
| 89 | 90 | unset($this->routes[$n]); |
| 90 | 91 | } |
| 91 | 92 | } |
@@ -97,7 +98,8 @@ discard block |
||
| 97 | 98 | */ |
| 98 | 99 | public function addCollection(self $collection): void |
| 99 | 100 | { |
| 100 | - foreach ($collection->all() as $name => $route) { |
|
| 101 | + foreach ($collection->all() as $name => $route) |
|
| 102 | + { |
|
| 101 | 103 | $this->routes[$name] = $route; |
| 102 | 104 | } |
| 103 | 105 | } |
@@ -113,14 +115,16 @@ discard block |
||
| 113 | 115 | */ |
| 114 | 116 | public function group(string $group): void |
| 115 | 117 | { |
| 116 | - foreach ($this->routes as $route) { |
|
| 118 | + foreach ($this->routes as $route) |
|
| 119 | + { |
|
| 117 | 120 | $route->group($group); |
| 118 | 121 | } |
| 119 | 122 | } |
| 120 | 123 | |
| 121 | 124 | public function __clone() |
| 122 | 125 | { |
| 123 | - foreach ($this->routes as $name => $route) { |
|
| 126 | + foreach ($this->routes as $name => $route) |
|
| 127 | + { |
|
| 124 | 128 | $this->routes[$name] = clone $route; |
| 125 | 129 | } |
| 126 | 130 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | public function __construct( |
| 18 | 18 | private readonly ContainerInterface $container, |
| 19 | 19 | private readonly FactoryInterface $factory, |
| 20 | - ) {} |
|
| 20 | + ){} |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * @throws RouteException |
@@ -25,27 +25,27 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function createWithMiddleware(array $middleware): Pipeline |
| 27 | 27 | { |
| 28 | - if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline) { |
|
| 28 | + if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline){ |
|
| 29 | 29 | return $middleware[0]; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $pipeline = $this->factory->make(Pipeline::class); |
| 33 | 33 | \assert($pipeline instanceof Pipeline); |
| 34 | 34 | |
| 35 | - foreach ($middleware as $item) { |
|
| 36 | - if ($item instanceof MiddlewareInterface) { |
|
| 35 | + foreach ($middleware as $item){ |
|
| 36 | + if ($item instanceof MiddlewareInterface){ |
|
| 37 | 37 | $pipeline->pushMiddleware($item); |
| 38 | - } elseif (\is_string($item)) { |
|
| 38 | + } elseif (\is_string($item)){ |
|
| 39 | 39 | $item = $this->container->get($item); |
| 40 | 40 | \assert($item instanceof MiddlewareInterface); |
| 41 | 41 | |
| 42 | 42 | $pipeline->pushMiddleware($item); |
| 43 | - } elseif ($item instanceof Autowire) { |
|
| 43 | + } elseif ($item instanceof Autowire){ |
|
| 44 | 44 | $item = $item->resolve($this->factory); |
| 45 | 45 | \assert($item instanceof MiddlewareInterface); |
| 46 | 46 | |
| 47 | 47 | $pipeline->pushMiddleware($item); |
| 48 | - } else { |
|
| 48 | + }else{ |
|
| 49 | 49 | $name = \get_debug_type($item); |
| 50 | 50 | throw new RouteException(\sprintf('Invalid middleware `%s`', $name)); |
| 51 | 51 | } |
@@ -17,7 +17,8 @@ discard block |
||
| 17 | 17 | public function __construct( |
| 18 | 18 | private readonly ContainerInterface $container, |
| 19 | 19 | private readonly FactoryInterface $factory, |
| 20 | - ) {} |
|
| 20 | + ) { |
|
| 21 | +} |
|
| 21 | 22 | |
| 22 | 23 | /** |
| 23 | 24 | * @throws RouteException |
@@ -25,27 +26,36 @@ discard block |
||
| 25 | 26 | */ |
| 26 | 27 | public function createWithMiddleware(array $middleware): Pipeline |
| 27 | 28 | { |
| 28 | - if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline) { |
|
| 29 | + if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline) |
|
| 30 | + { |
|
| 29 | 31 | return $middleware[0]; |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | 34 | $pipeline = $this->factory->make(Pipeline::class); |
| 33 | 35 | \assert($pipeline instanceof Pipeline); |
| 34 | 36 | |
| 35 | - foreach ($middleware as $item) { |
|
| 36 | - if ($item instanceof MiddlewareInterface) { |
|
| 37 | + foreach ($middleware as $item) |
|
| 38 | + { |
|
| 39 | + if ($item instanceof MiddlewareInterface) |
|
| 40 | + { |
|
| 37 | 41 | $pipeline->pushMiddleware($item); |
| 38 | - } elseif (\is_string($item)) { |
|
| 42 | + } |
|
| 43 | + elseif (\is_string($item)) |
|
| 44 | + { |
|
| 39 | 45 | $item = $this->container->get($item); |
| 40 | 46 | \assert($item instanceof MiddlewareInterface); |
| 41 | 47 | |
| 42 | 48 | $pipeline->pushMiddleware($item); |
| 43 | - } elseif ($item instanceof Autowire) { |
|
| 49 | + } |
|
| 50 | + elseif ($item instanceof Autowire) |
|
| 51 | + { |
|
| 44 | 52 | $item = $item->resolve($this->factory); |
| 45 | 53 | \assert($item instanceof MiddlewareInterface); |
| 46 | 54 | |
| 47 | 55 | $pipeline->pushMiddleware($item); |
| 48 | - } else { |
|
| 56 | + } |
|
| 57 | + else |
|
| 58 | + { |
|
| 49 | 59 | $name = \get_debug_type($item); |
| 50 | 60 | throw new RouteException(\sprintf('Invalid middleware `%s`', $name)); |
| 51 | 61 | } |
@@ -26,11 +26,11 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | $parsed = $this->tokens($source); |
| 28 | 28 | |
| 29 | - if (\count($tokens) !== \count($parsed)) { |
|
| 29 | + if (\count($tokens) !== \count($parsed)){ |
|
| 30 | 30 | $this->fail('Token count mismatch'); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - foreach ($tokens as $index => $token) { |
|
| 33 | + foreach ($tokens as $index => $token){ |
|
| 34 | 34 | self::assertSame($token->type, $parsed[$index]->type, 'Token type mismatch'); |
| 35 | 35 | self::assertSame($token->offset, $parsed[$index]->offset, 'Token offset mismatch'); |
| 36 | 36 | self::assertSame($token->content, $parsed[$index]->content, 'Token content mismatch'); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | $lexer = new Lexer(); |
| 43 | 43 | |
| 44 | 44 | $tokens = []; |
| 45 | - foreach ($lexer->parse(new StringStream($source)) as $t) { |
|
| 45 | + foreach ($lexer->parse(new StringStream($source)) as $t){ |
|
| 46 | 46 | $tokens[] = $t; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -26,11 +26,13 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | $parsed = $this->tokens($source); |
| 28 | 28 | |
| 29 | - if (\count($tokens) !== \count($parsed)) { |
|
| 29 | + if (\count($tokens) !== \count($parsed)) |
|
| 30 | + { |
|
| 30 | 31 | $this->fail('Token count mismatch'); |
| 31 | 32 | } |
| 32 | 33 | |
| 33 | - foreach ($tokens as $index => $token) { |
|
| 34 | + foreach ($tokens as $index => $token) |
|
| 35 | + { |
|
| 34 | 36 | self::assertSame($token->type, $parsed[$index]->type, 'Token type mismatch'); |
| 35 | 37 | self::assertSame($token->offset, $parsed[$index]->offset, 'Token offset mismatch'); |
| 36 | 38 | self::assertSame($token->content, $parsed[$index]->content, 'Token content mismatch'); |
@@ -42,7 +44,8 @@ discard block |
||
| 42 | 44 | $lexer = new Lexer(); |
| 43 | 45 | |
| 44 | 46 | $tokens = []; |
| 45 | - foreach ($lexer->parse(new StringStream($source)) as $t) { |
|
| 47 | + foreach ($lexer->parse(new StringStream($source)) as $t) |
|
| 48 | + { |
|
| 46 | 49 | $tokens[] = $t; |
| 47 | 50 | } |
| 48 | 51 | |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | $parsed = $this->tokens($source); |
| 18 | 18 | |
| 19 | - if (\count($tokens) !== \count($parsed)) { |
|
| 19 | + if (\count($tokens) !== \count($parsed)){ |
|
| 20 | 20 | $this->fail('Token count mismatch'); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - foreach ($tokens as $index => $token) { |
|
| 23 | + foreach ($tokens as $index => $token){ |
|
| 24 | 24 | self::assertSame($token->type, $parsed[$index]->type, 'Token type mismatch'); |
| 25 | 25 | self::assertSame($token->offset, $parsed[$index]->offset, 'Token offset mismatch'); |
| 26 | 26 | self::assertSame($token->content, $parsed[$index]->content, 'Token content mismatch'); |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | protected function tokens(string $source): array |
| 31 | 31 | { |
| 32 | 32 | $lexer = new Lexer(); |
| 33 | - foreach (static::GRAMMARS as $grammar) { |
|
| 33 | + foreach (static::GRAMMARS as $grammar){ |
|
| 34 | 34 | $lexer->addGrammar(new $grammar()); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $tokens = []; |
| 38 | - foreach ($lexer->parse(new StringStream($source)) as $t) { |
|
| 38 | + foreach ($lexer->parse(new StringStream($source)) as $t){ |
|
| 39 | 39 | $tokens[] = $t; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -16,11 +16,13 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | $parsed = $this->tokens($source); |
| 18 | 18 | |
| 19 | - if (\count($tokens) !== \count($parsed)) { |
|
| 19 | + if (\count($tokens) !== \count($parsed)) |
|
| 20 | + { |
|
| 20 | 21 | $this->fail('Token count mismatch'); |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | - foreach ($tokens as $index => $token) { |
|
| 24 | + foreach ($tokens as $index => $token) |
|
| 25 | + { |
|
| 24 | 26 | self::assertSame($token->type, $parsed[$index]->type, 'Token type mismatch'); |
| 25 | 27 | self::assertSame($token->offset, $parsed[$index]->offset, 'Token offset mismatch'); |
| 26 | 28 | self::assertSame($token->content, $parsed[$index]->content, 'Token content mismatch'); |
@@ -30,12 +32,14 @@ discard block |
||
| 30 | 32 | protected function tokens(string $source): array |
| 31 | 33 | { |
| 32 | 34 | $lexer = new Lexer(); |
| 33 | - foreach (static::GRAMMARS as $grammar) { |
|
| 35 | + foreach (static::GRAMMARS as $grammar) |
|
| 36 | + { |
|
| 34 | 37 | $lexer->addGrammar(new $grammar()); |
| 35 | 38 | } |
| 36 | 39 | |
| 37 | 40 | $tokens = []; |
| 38 | - foreach ($lexer->parse(new StringStream($source)) as $t) { |
|
| 41 | + foreach ($lexer->parse(new StringStream($source)) as $t) |
|
| 42 | + { |
|
| 39 | 43 | $tokens[] = $t; |
| 40 | 44 | } |
| 41 | 45 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | public function testVerbatim4(): void |
| 84 | 84 | { |
| 85 | - self::assertSame('<script>alert(<?php echo json_encode' . |
|
| 85 | + self::assertSame('<script>alert(<?php echo json_encode'. |
|
| 86 | 86 | '("hello\' \'world", JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT, 512); ?>)</script>', $res = $this->compile('<script>alert({{ "hello\' \'world" }})</script>')->getContent()); |
| 87 | 87 | |
| 88 | 88 | self::assertSame('<script>alert("hello\u0027 \u0027world")</script>', $this->eval($res)); |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | \ob_start(); |
| 102 | 102 | |
| 103 | - eval('?>' . $body); |
|
| 103 | + eval('?>'.$body); |
|
| 104 | 104 | |
| 105 | 105 | return \ob_get_clean(); |
| 106 | 106 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | public function __construct(array $visitors = []) |
| 22 | 22 | { |
| 23 | - foreach ($visitors as $visitor) { |
|
| 23 | + foreach ($visitors as $visitor){ |
|
| 24 | 24 | $this->addVisitor($visitor); |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function removeVisitor(VisitorInterface $visitor): void |
| 37 | 37 | { |
| 38 | - foreach ($this->visitors as $index => $added) { |
|
| 39 | - if ($added === $visitor) { |
|
| 38 | + foreach ($this->visitors as $index => $added){ |
|
| 39 | + if ($added === $visitor){ |
|
| 40 | 40 | unset($this->visitors[$index]); |
| 41 | 41 | break; |
| 42 | 42 | } |
@@ -57,22 +57,22 @@ discard block |
||
| 57 | 57 | $context ??= new VisitorContext(); |
| 58 | 58 | |
| 59 | 59 | $ctx = clone $context; |
| 60 | - foreach ($nodes as $index => $node) { |
|
| 61 | - if ($this->stopTraversal) { |
|
| 60 | + foreach ($nodes as $index => $node){ |
|
| 61 | + if ($this->stopTraversal){ |
|
| 62 | 62 | break; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $traverseChildren = true; |
| 66 | 66 | $breakVisitorID = null; |
| 67 | 67 | |
| 68 | - if ($node instanceof NodeInterface) { |
|
| 68 | + if ($node instanceof NodeInterface){ |
|
| 69 | 69 | $ctx = $context->withNode($node); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 72 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 73 | 73 | $result = $visitor->enterNode($node, $ctx); |
| 74 | 74 | |
| 75 | - switch (true) { |
|
| 75 | + switch (true){ |
|
| 76 | 76 | case $result === null: |
| 77 | 77 | break; |
| 78 | 78 | |
@@ -96,23 +96,23 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | default: |
| 98 | 98 | throw new \LogicException( |
| 99 | - 'enterNode() returned invalid value of type ' . \gettype($result), |
|
| 99 | + 'enterNode() returned invalid value of type '.\gettype($result), |
|
| 100 | 100 | ); |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // sub nodes |
| 105 | - if ($traverseChildren && $node instanceof NodeInterface) { |
|
| 105 | + if ($traverseChildren && $node instanceof NodeInterface){ |
|
| 106 | 106 | $nodes[$index] = $this->traverseNode($node, $ctx); |
| 107 | - if ($this->stopTraversal) { |
|
| 107 | + if ($this->stopTraversal){ |
|
| 108 | 108 | break; |
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 112 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 113 | 113 | $result = $visitor->leaveNode($node, $ctx); |
| 114 | 114 | |
| 115 | - switch (true) { |
|
| 115 | + switch (true){ |
|
| 116 | 116 | case $result === null: |
| 117 | 117 | break; |
| 118 | 118 | |
@@ -130,11 +130,11 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | default: |
| 132 | 132 | throw new \LogicException( |
| 133 | - 'leaveNode() returned invalid value of type ' . \gettype($result), |
|
| 133 | + 'leaveNode() returned invalid value of type '.\gettype($result), |
|
| 134 | 134 | ); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ($breakVisitorID === $visitorID) { |
|
| 137 | + if ($breakVisitorID === $visitorID){ |
|
| 138 | 138 | break; |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -149,18 +149,18 @@ discard block |
||
| 149 | 149 | private function traverseNode(NodeInterface $node, VisitorContext $context): NodeInterface |
| 150 | 150 | { |
| 151 | 151 | $ctx = clone $context; |
| 152 | - foreach ($node as $name => $_) { |
|
| 152 | + foreach ($node as $name => $_){ |
|
| 153 | 153 | $_child = &$node->$name; |
| 154 | - if (\is_array($_child)) { |
|
| 154 | + if (\is_array($_child)){ |
|
| 155 | 155 | $_child = $this->traverse($_child, $ctx); |
| 156 | - if ($this->stopTraversal) { |
|
| 156 | + if ($this->stopTraversal){ |
|
| 157 | 157 | break; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | continue; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if (!$_child instanceof NodeInterface) { |
|
| 163 | + if (!$_child instanceof NodeInterface){ |
|
| 164 | 164 | continue; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | $traverseChildren = true; |
| 170 | 170 | $breakVisitorID = null; |
| 171 | 171 | |
| 172 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 172 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 173 | 173 | $result = $visitor->enterNode($_child, $ctx); |
| 174 | - switch (true) { |
|
| 174 | + switch (true){ |
|
| 175 | 175 | case $result === null: |
| 176 | 176 | break; |
| 177 | 177 | |
@@ -194,22 +194,22 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | default: |
| 196 | 196 | throw new \LogicException( |
| 197 | - 'enterNode() returned invalid value of type ' . \gettype($result), |
|
| 197 | + 'enterNode() returned invalid value of type '.\gettype($result), |
|
| 198 | 198 | ); |
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - if ($traverseChildren) { |
|
| 202 | + if ($traverseChildren){ |
|
| 203 | 203 | $_child = $this->traverseNode($_child, $ctx); |
| 204 | - if ($this->stopTraversal) { |
|
| 204 | + if ($this->stopTraversal){ |
|
| 205 | 205 | break; |
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 209 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 210 | 210 | $result = $visitor->leaveNode($_child, $ctx); |
| 211 | 211 | |
| 212 | - switch (true) { |
|
| 212 | + switch (true){ |
|
| 213 | 213 | case $result === null: |
| 214 | 214 | break; |
| 215 | 215 | |
@@ -223,11 +223,11 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | default: |
| 225 | 225 | throw new \LogicException( |
| 226 | - 'leaveNode() returned invalid value of type ' . \gettype($result), |
|
| 226 | + 'leaveNode() returned invalid value of type '.\gettype($result), |
|
| 227 | 227 | ); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ($breakVisitorID === $visitorID) { |
|
| 230 | + if ($breakVisitorID === $visitorID){ |
|
| 231 | 231 | break; |
| 232 | 232 | } |
| 233 | 233 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | Compiler\Result $result, |
| 22 | 22 | NodeInterface $node, |
| 23 | 23 | ): bool { |
| 24 | - switch (true) { |
|
| 24 | + switch (true){ |
|
| 25 | 25 | case $node instanceof Hidden: |
| 26 | 26 | return true; |
| 27 | 27 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $result->withinContext( |
| 30 | 30 | $node->getContext(), |
| 31 | 31 | static function (Compiler\Result $source) use ($node, $compiler): void { |
| 32 | - foreach ($node->nodes as $child) { |
|
| 32 | + foreach ($node->nodes as $child){ |
|
| 33 | 33 | $compiler->compile($child, $source); |
| 34 | 34 | } |
| 35 | 35 | }, |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | $result->withinContext( |
| 42 | 42 | $node->getContext(), |
| 43 | 43 | static function (Compiler\Result $source) use ($node, $compiler): void { |
| 44 | - foreach ($node->nodes as $child) { |
|
| 45 | - if (\is_string($child)) { |
|
| 44 | + foreach ($node->nodes as $child){ |
|
| 45 | + if (\is_string($child)){ |
|
| 46 | 46 | $source->push($child, null); |
| 47 | 47 | continue; |
| 48 | 48 | } |
@@ -21,7 +21,8 @@ discard block |
||
| 21 | 21 | Compiler\Result $result, |
| 22 | 22 | NodeInterface $node, |
| 23 | 23 | ): bool { |
| 24 | - switch (true) { |
|
| 24 | + switch (true) |
|
| 25 | + { |
|
| 25 | 26 | case $node instanceof Hidden: |
| 26 | 27 | return true; |
| 27 | 28 | |
@@ -29,7 +30,8 @@ discard block |
||
| 29 | 30 | $result->withinContext( |
| 30 | 31 | $node->getContext(), |
| 31 | 32 | static function (Compiler\Result $source) use ($node, $compiler): void { |
| 32 | - foreach ($node->nodes as $child) { |
|
| 33 | + foreach ($node->nodes as $child) |
|
| 34 | + { |
|
| 33 | 35 | $compiler->compile($child, $source); |
| 34 | 36 | } |
| 35 | 37 | }, |
@@ -41,8 +43,10 @@ discard block |
||
| 41 | 43 | $result->withinContext( |
| 42 | 44 | $node->getContext(), |
| 43 | 45 | static function (Compiler\Result $source) use ($node, $compiler): void { |
| 44 | - foreach ($node->nodes as $child) { |
|
| 45 | - if (\is_string($child)) { |
|
| 46 | + foreach ($node->nodes as $child) |
|
| 47 | + { |
|
| 48 | + if (\is_string($child)) |
|
| 49 | + { |
|
| 46 | 50 | $source->push($child, null); |
| 47 | 51 | continue; |
| 48 | 52 | } |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | public function __construct( |
| 15 | 15 | private readonly array $tokens, |
| 16 | 16 | string $func, |
| 17 | - ) { |
|
| 17 | + ){ |
|
| 18 | 18 | $this->parse($func); |
| 19 | 19 | } |
| 20 | 20 | |
@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | $replace = []; |
| 24 | 24 | |
| 25 | - foreach ($this->blocks as $block) { |
|
| 26 | - for ($i = $block['start']; $i <= $block['end']; $i++) { |
|
| 25 | + foreach ($this->blocks as $block){ |
|
| 26 | + for ($i = $block['start']; $i <= $block['end']; $i++){ |
|
| 27 | 27 | $replace[$i] = ''; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -31,13 +31,13 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | $result = ''; |
| 34 | - foreach ($this->tokens as $position => $token) { |
|
| 35 | - if (\array_key_exists($position, $replace)) { |
|
| 34 | + foreach ($this->tokens as $position => $token){ |
|
| 35 | + if (\array_key_exists($position, $replace)){ |
|
| 36 | 36 | $result .= $replace[$position]; |
| 37 | 37 | continue; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - if (\is_string($token)) { |
|
| 40 | + if (\is_string($token)){ |
|
| 41 | 41 | $result .= $token; |
| 42 | 42 | continue; |
| 43 | 43 | } |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | { |
| 56 | 56 | $replace = []; |
| 57 | 57 | |
| 58 | - foreach ($this->blocks as $block) { |
|
| 59 | - for ($i = $block['start']; $i <= $block['end']; ++$i) { |
|
| 58 | + foreach ($this->blocks as $block){ |
|
| 59 | + for ($i = $block['start']; $i <= $block['end']; ++$i){ |
|
| 60 | 60 | $replace[$i] = ''; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -64,18 +64,18 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | $result = ''; |
| 67 | - foreach ($this->tokens as $position => $token) { |
|
| 68 | - if (\array_key_exists($position, $replace)) { |
|
| 67 | + foreach ($this->tokens as $position => $token){ |
|
| 68 | + if (\array_key_exists($position, $replace)){ |
|
| 69 | 69 | $result .= $replace[$position]; |
| 70 | 70 | continue; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if (\is_string($token)) { |
|
| 73 | + if (\is_string($token)){ |
|
| 74 | 74 | $result .= $token; |
| 75 | 75 | continue; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if (\in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO])) { |
|
| 78 | + if (\in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO])){ |
|
| 79 | 79 | continue; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | public function getBlocks(): array |
| 92 | 92 | { |
| 93 | 93 | $result = []; |
| 94 | - foreach ($this->blocks as $name => $macro) { |
|
| 94 | + foreach ($this->blocks as $name => $macro){ |
|
| 95 | 95 | $result[$name] = $macro['value']; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | public function set(string $block, string $value): void |
| 107 | 107 | { |
| 108 | - if (!isset($this->blocks[$block])) { |
|
| 108 | + if (!isset($this->blocks[$block])){ |
|
| 109 | 109 | return; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -116,26 +116,26 @@ discard block |
||
| 116 | 116 | { |
| 117 | 117 | $level = 0; |
| 118 | 118 | $start = $name = $value = null; |
| 119 | - foreach ($this->tokens as $position => $token) { |
|
| 120 | - if (!\is_array($token)) { |
|
| 119 | + foreach ($this->tokens as $position => $token){ |
|
| 120 | + if (!\is_array($token)){ |
|
| 121 | 121 | $token = [$token, $token, 0]; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - switch ($token[0]) { |
|
| 124 | + switch ($token[0]){ |
|
| 125 | 125 | case '(': |
| 126 | - if ($start !== null) { |
|
| 126 | + if ($start !== null){ |
|
| 127 | 127 | $level++; |
| 128 | 128 | $value .= $token[1]; |
| 129 | 129 | } |
| 130 | 130 | break; |
| 131 | 131 | case ')': |
| 132 | - if ($start === null) { |
|
| 132 | + if ($start === null){ |
|
| 133 | 133 | break; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | $level--; |
| 137 | 137 | $value .= $token[1]; |
| 138 | - if ($level === 0) { |
|
| 138 | + if ($level === 0){ |
|
| 139 | 139 | $this->blocks[$name] = [ |
| 140 | 140 | 'start' => $start, |
| 141 | 141 | 'value' => \trim($value), |
@@ -147,23 +147,23 @@ discard block |
||
| 147 | 147 | } |
| 148 | 148 | break; |
| 149 | 149 | case T_STRING: |
| 150 | - if ($token[1] === $func) { |
|
| 150 | + if ($token[1] === $func){ |
|
| 151 | 151 | $start = $position; |
| 152 | 152 | $value = $token[1]; |
| 153 | 153 | break; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if ($start !== null) { |
|
| 156 | + if ($start !== null){ |
|
| 157 | 157 | $value .= $token[1]; |
| 158 | 158 | } |
| 159 | 159 | break; |
| 160 | 160 | case T_CONSTANT_ENCAPSED_STRING: |
| 161 | - if ($start === null) { |
|
| 161 | + if ($start === null){ |
|
| 162 | 162 | break; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - if ($name === null) { |
|
| 166 | - $name = \stripcslashes(\substr((string) $token[1], 1, -1)); |
|
| 165 | + if ($name === null){ |
|
| 166 | + $name = \stripcslashes(\substr((string)$token[1], 1, -1)); |
|
| 167 | 167 | } |
| 168 | 168 | $value .= $token[1]; |
| 169 | 169 | break; |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $value .= $token[1]; |
| 172 | 172 | break; |
| 173 | 173 | default: |
| 174 | - if ($start !== null) { |
|
| 174 | + if ($start !== null){ |
|
| 175 | 175 | $value .= $token[1]; |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -22,8 +22,10 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | $replace = []; |
| 24 | 24 | |
| 25 | - foreach ($this->blocks as $block) { |
|
| 26 | - for ($i = $block['start']; $i <= $block['end']; $i++) { |
|
| 25 | + foreach ($this->blocks as $block) |
|
| 26 | + { |
|
| 27 | + for ($i = $block['start']; $i <= $block['end']; $i++) |
|
| 28 | + { |
|
| 27 | 29 | $replace[$i] = ''; |
| 28 | 30 | } |
| 29 | 31 | |
@@ -31,13 +33,16 @@ discard block |
||
| 31 | 33 | } |
| 32 | 34 | |
| 33 | 35 | $result = ''; |
| 34 | - foreach ($this->tokens as $position => $token) { |
|
| 35 | - if (\array_key_exists($position, $replace)) { |
|
| 36 | + foreach ($this->tokens as $position => $token) |
|
| 37 | + { |
|
| 38 | + if (\array_key_exists($position, $replace)) |
|
| 39 | + { |
|
| 36 | 40 | $result .= $replace[$position]; |
| 37 | 41 | continue; |
| 38 | 42 | } |
| 39 | 43 | |
| 40 | - if (\is_string($token)) { |
|
| 44 | + if (\is_string($token)) |
|
| 45 | + { |
|
| 41 | 46 | $result .= $token; |
| 42 | 47 | continue; |
| 43 | 48 | } |
@@ -55,8 +60,10 @@ discard block |
||
| 55 | 60 | { |
| 56 | 61 | $replace = []; |
| 57 | 62 | |
| 58 | - foreach ($this->blocks as $block) { |
|
| 59 | - for ($i = $block['start']; $i <= $block['end']; ++$i) { |
|
| 63 | + foreach ($this->blocks as $block) |
|
| 64 | + { |
|
| 65 | + for ($i = $block['start']; $i <= $block['end']; ++$i) |
|
| 66 | + { |
|
| 60 | 67 | $replace[$i] = ''; |
| 61 | 68 | } |
| 62 | 69 | |
@@ -64,18 +71,22 @@ discard block |
||
| 64 | 71 | } |
| 65 | 72 | |
| 66 | 73 | $result = ''; |
| 67 | - foreach ($this->tokens as $position => $token) { |
|
| 68 | - if (\array_key_exists($position, $replace)) { |
|
| 74 | + foreach ($this->tokens as $position => $token) |
|
| 75 | + { |
|
| 76 | + if (\array_key_exists($position, $replace)) |
|
| 77 | + { |
|
| 69 | 78 | $result .= $replace[$position]; |
| 70 | 79 | continue; |
| 71 | 80 | } |
| 72 | 81 | |
| 73 | - if (\is_string($token)) { |
|
| 82 | + if (\is_string($token)) |
|
| 83 | + { |
|
| 74 | 84 | $result .= $token; |
| 75 | 85 | continue; |
| 76 | 86 | } |
| 77 | 87 | |
| 78 | - if (\in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO])) { |
|
| 88 | + if (\in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO])) |
|
| 89 | + { |
|
| 79 | 90 | continue; |
| 80 | 91 | } |
| 81 | 92 | |
@@ -91,7 +102,8 @@ discard block |
||
| 91 | 102 | public function getBlocks(): array |
| 92 | 103 | { |
| 93 | 104 | $result = []; |
| 94 | - foreach ($this->blocks as $name => $macro) { |
|
| 105 | + foreach ($this->blocks as $name => $macro) |
|
| 106 | + { |
|
| 95 | 107 | $result[$name] = $macro['value']; |
| 96 | 108 | } |
| 97 | 109 | |
@@ -105,7 +117,8 @@ discard block |
||
| 105 | 117 | |
| 106 | 118 | public function set(string $block, string $value): void |
| 107 | 119 | { |
| 108 | - if (!isset($this->blocks[$block])) { |
|
| 120 | + if (!isset($this->blocks[$block])) |
|
| 121 | + { |
|
| 109 | 122 | return; |
| 110 | 123 | } |
| 111 | 124 | |
@@ -116,26 +129,32 @@ discard block |
||
| 116 | 129 | { |
| 117 | 130 | $level = 0; |
| 118 | 131 | $start = $name = $value = null; |
| 119 | - foreach ($this->tokens as $position => $token) { |
|
| 120 | - if (!\is_array($token)) { |
|
| 132 | + foreach ($this->tokens as $position => $token) |
|
| 133 | + { |
|
| 134 | + if (!\is_array($token)) |
|
| 135 | + { |
|
| 121 | 136 | $token = [$token, $token, 0]; |
| 122 | 137 | } |
| 123 | 138 | |
| 124 | - switch ($token[0]) { |
|
| 139 | + switch ($token[0]) |
|
| 140 | + { |
|
| 125 | 141 | case '(': |
| 126 | - if ($start !== null) { |
|
| 142 | + if ($start !== null) |
|
| 143 | + { |
|
| 127 | 144 | $level++; |
| 128 | 145 | $value .= $token[1]; |
| 129 | 146 | } |
| 130 | 147 | break; |
| 131 | 148 | case ')': |
| 132 | - if ($start === null) { |
|
| 149 | + if ($start === null) |
|
| 150 | + { |
|
| 133 | 151 | break; |
| 134 | 152 | } |
| 135 | 153 | |
| 136 | 154 | $level--; |
| 137 | 155 | $value .= $token[1]; |
| 138 | - if ($level === 0) { |
|
| 156 | + if ($level === 0) |
|
| 157 | + { |
|
| 139 | 158 | $this->blocks[$name] = [ |
| 140 | 159 | 'start' => $start, |
| 141 | 160 | 'value' => \trim($value), |
@@ -147,22 +166,26 @@ discard block |
||
| 147 | 166 | } |
| 148 | 167 | break; |
| 149 | 168 | case T_STRING: |
| 150 | - if ($token[1] === $func) { |
|
| 169 | + if ($token[1] === $func) |
|
| 170 | + { |
|
| 151 | 171 | $start = $position; |
| 152 | 172 | $value = $token[1]; |
| 153 | 173 | break; |
| 154 | 174 | } |
| 155 | 175 | |
| 156 | - if ($start !== null) { |
|
| 176 | + if ($start !== null) |
|
| 177 | + { |
|
| 157 | 178 | $value .= $token[1]; |
| 158 | 179 | } |
| 159 | 180 | break; |
| 160 | 181 | case T_CONSTANT_ENCAPSED_STRING: |
| 161 | - if ($start === null) { |
|
| 182 | + if ($start === null) |
|
| 183 | + { |
|
| 162 | 184 | break; |
| 163 | 185 | } |
| 164 | 186 | |
| 165 | - if ($name === null) { |
|
| 187 | + if ($name === null) |
|
| 188 | + { |
|
| 166 | 189 | $name = \stripcslashes(\substr((string) $token[1], 1, -1)); |
| 167 | 190 | } |
| 168 | 191 | $value .= $token[1]; |
@@ -171,7 +194,8 @@ discard block |
||
| 171 | 194 | $value .= $token[1]; |
| 172 | 195 | break; |
| 173 | 196 | default: |
| 174 | - if ($start !== null) { |
|
| 197 | + if ($start !== null) |
|
| 198 | + { |
|
| 175 | 199 | $value .= $token[1]; |
| 176 | 200 | } |
| 177 | 201 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | public function __construct( |
| 26 | 26 | ?Context $context = null, |
| 27 | 27 | public string $pattern = '*', |
| 28 | - ) { |
|
| 28 | + ){ |
|
| 29 | 29 | $this->context = $context; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -35,14 +35,14 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function accepts(string $name): ?string |
| 37 | 37 | { |
| 38 | - if ($this->pattern === '' || $this->pattern === '*') { |
|
| 38 | + if ($this->pattern === '' || $this->pattern === '*'){ |
|
| 39 | 39 | // accept everything |
| 40 | 40 | return $name; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | $conditions = []; |
| 44 | - foreach (\explode(';', $this->pattern) as $condition) { |
|
| 45 | - if (!\str_contains($condition, ':')) { |
|
| 44 | + foreach (\explode(';', $this->pattern) as $condition){ |
|
| 45 | + if (!\str_contains($condition, ':')){ |
|
| 46 | 46 | //Invalid |
| 47 | 47 | continue; |
| 48 | 48 | } |
@@ -51,27 +51,27 @@ discard block |
||
| 51 | 51 | $conditions[$option] = $value; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if (isset($conditions['include'])) { |
|
| 54 | + if (isset($conditions['include'])){ |
|
| 55 | 55 | $include = \explode(',', $conditions['include']); |
| 56 | - if (\in_array($name, $include)) { |
|
| 56 | + if (\in_array($name, $include)){ |
|
| 57 | 57 | return $name; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return null; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - if (isset($conditions['exclude'])) { |
|
| 63 | + if (isset($conditions['exclude'])){ |
|
| 64 | 64 | $exclude = \explode(',', $conditions['exclude']); |
| 65 | - if (\in_array($name, $exclude)) { |
|
| 65 | + if (\in_array($name, $exclude)){ |
|
| 66 | 66 | return null; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | return $name; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if (isset($conditions['prefix'])) { |
|
| 72 | + if (isset($conditions['prefix'])){ |
|
| 73 | 73 | $conditions['prefix'] = \rtrim($conditions['prefix'], ' *'); |
| 74 | - if (\str_starts_with($name, $conditions['prefix'])) { |
|
| 74 | + if (\str_starts_with($name, $conditions['prefix'])){ |
|
| 75 | 75 | return \substr($name, \strlen($conditions['prefix'])); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -35,14 +35,17 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function accepts(string $name): ?string |
| 37 | 37 | { |
| 38 | - if ($this->pattern === '' || $this->pattern === '*') { |
|
| 38 | + if ($this->pattern === '' || $this->pattern === '*') |
|
| 39 | + { |
|
| 39 | 40 | // accept everything |
| 40 | 41 | return $name; |
| 41 | 42 | } |
| 42 | 43 | |
| 43 | 44 | $conditions = []; |
| 44 | - foreach (\explode(';', $this->pattern) as $condition) { |
|
| 45 | - if (!\str_contains($condition, ':')) { |
|
| 45 | + foreach (\explode(';', $this->pattern) as $condition) |
|
| 46 | + { |
|
| 47 | + if (!\str_contains($condition, ':')) |
|
| 48 | + { |
|
| 46 | 49 | //Invalid |
| 47 | 50 | continue; |
| 48 | 51 | } |
@@ -51,27 +54,33 @@ discard block |
||
| 51 | 54 | $conditions[$option] = $value; |
| 52 | 55 | } |
| 53 | 56 | |
| 54 | - if (isset($conditions['include'])) { |
|
| 57 | + if (isset($conditions['include'])) |
|
| 58 | + { |
|
| 55 | 59 | $include = \explode(',', $conditions['include']); |
| 56 | - if (\in_array($name, $include)) { |
|
| 60 | + if (\in_array($name, $include)) |
|
| 61 | + { |
|
| 57 | 62 | return $name; |
| 58 | 63 | } |
| 59 | 64 | |
| 60 | 65 | return null; |
| 61 | 66 | } |
| 62 | 67 | |
| 63 | - if (isset($conditions['exclude'])) { |
|
| 68 | + if (isset($conditions['exclude'])) |
|
| 69 | + { |
|
| 64 | 70 | $exclude = \explode(',', $conditions['exclude']); |
| 65 | - if (\in_array($name, $exclude)) { |
|
| 71 | + if (\in_array($name, $exclude)) |
|
| 72 | + { |
|
| 66 | 73 | return null; |
| 67 | 74 | } |
| 68 | 75 | |
| 69 | 76 | return $name; |
| 70 | 77 | } |
| 71 | 78 | |
| 72 | - if (isset($conditions['prefix'])) { |
|
| 79 | + if (isset($conditions['prefix'])) |
|
| 80 | + { |
|
| 73 | 81 | $conditions['prefix'] = \rtrim($conditions['prefix'], ' *'); |
| 74 | - if (\str_starts_with($name, $conditions['prefix'])) { |
|
| 82 | + if (\str_starts_with($name, $conditions['prefix'])) |
|
| 83 | + { |
|
| 75 | 84 | return \substr($name, \strlen($conditions['prefix'])); |
| 76 | 85 | } |
| 77 | 86 | |