@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function accepts(string $name): ?string |
51 | 51 | { |
52 | - if ($this->pattern === '' || $this->pattern === '*') { |
|
52 | + if ($this->pattern === '' || $this->pattern === '*'){ |
|
53 | 53 | // accept everything |
54 | 54 | return $name; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $conditions = []; |
58 | - foreach (explode(';', $this->pattern) as $condition) { |
|
59 | - if (strpos($condition, ':') === false) { |
|
58 | + foreach (explode(';', $this->pattern) as $condition){ |
|
59 | + if (strpos($condition, ':') === false){ |
|
60 | 60 | //Invalid |
61 | 61 | continue; |
62 | 62 | } |
@@ -65,27 +65,27 @@ discard block |
||
65 | 65 | $conditions[$option] = $value; |
66 | 66 | } |
67 | 67 | |
68 | - if (isset($conditions['include'])) { |
|
68 | + if (isset($conditions['include'])){ |
|
69 | 69 | $include = explode(',', $conditions['include']); |
70 | - if (in_array($name, $include)) { |
|
70 | + if (in_array($name, $include)){ |
|
71 | 71 | return $name; |
72 | 72 | } |
73 | 73 | |
74 | 74 | return null; |
75 | 75 | } |
76 | 76 | |
77 | - if (isset($conditions['exclude'])) { |
|
77 | + if (isset($conditions['exclude'])){ |
|
78 | 78 | $exclude = explode(',', $conditions['exclude']); |
79 | - if (in_array($name, $exclude)) { |
|
79 | + if (in_array($name, $exclude)){ |
|
80 | 80 | return null; |
81 | 81 | } |
82 | 82 | |
83 | 83 | return $name; |
84 | 84 | } |
85 | 85 | |
86 | - if (isset($conditions['prefix'])) { |
|
86 | + if (isset($conditions['prefix'])){ |
|
87 | 87 | $conditions['prefix'] = rtrim($conditions['prefix'], ' *'); |
88 | - if (strpos($name, $conditions['prefix']) === 0) { |
|
88 | + if (strpos($name, $conditions['prefix']) === 0){ |
|
89 | 89 | return substr($name, strlen($conditions['prefix'])); |
90 | 90 | } |
91 | 91 |
@@ -49,14 +49,17 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function accepts(string $name): ?string |
51 | 51 | { |
52 | - if ($this->pattern === '' || $this->pattern === '*') { |
|
52 | + if ($this->pattern === '' || $this->pattern === '*') |
|
53 | + { |
|
53 | 54 | // accept everything |
54 | 55 | return $name; |
55 | 56 | } |
56 | 57 | |
57 | 58 | $conditions = []; |
58 | - foreach (explode(';', $this->pattern) as $condition) { |
|
59 | - if (strpos($condition, ':') === false) { |
|
59 | + foreach (explode(';', $this->pattern) as $condition) |
|
60 | + { |
|
61 | + if (strpos($condition, ':') === false) |
|
62 | + { |
|
60 | 63 | //Invalid |
61 | 64 | continue; |
62 | 65 | } |
@@ -65,27 +68,33 @@ discard block |
||
65 | 68 | $conditions[$option] = $value; |
66 | 69 | } |
67 | 70 | |
68 | - if (isset($conditions['include'])) { |
|
71 | + if (isset($conditions['include'])) |
|
72 | + { |
|
69 | 73 | $include = explode(',', $conditions['include']); |
70 | - if (in_array($name, $include)) { |
|
74 | + if (in_array($name, $include)) |
|
75 | + { |
|
71 | 76 | return $name; |
72 | 77 | } |
73 | 78 | |
74 | 79 | return null; |
75 | 80 | } |
76 | 81 | |
77 | - if (isset($conditions['exclude'])) { |
|
82 | + if (isset($conditions['exclude'])) |
|
83 | + { |
|
78 | 84 | $exclude = explode(',', $conditions['exclude']); |
79 | - if (in_array($name, $exclude)) { |
|
85 | + if (in_array($name, $exclude)) |
|
86 | + { |
|
80 | 87 | return null; |
81 | 88 | } |
82 | 89 | |
83 | 90 | return $name; |
84 | 91 | } |
85 | 92 | |
86 | - if (isset($conditions['prefix'])) { |
|
93 | + if (isset($conditions['prefix'])) |
|
94 | + { |
|
87 | 95 | $conditions['prefix'] = rtrim($conditions['prefix'], ' *'); |
88 | - if (strpos($name, $conditions['prefix']) === 0) { |
|
96 | + if (strpos($name, $conditions['prefix']) === 0) |
|
97 | + { |
|
89 | 98 | return substr($name, strlen($conditions['prefix'])); |
90 | 99 | } |
91 | 100 |
@@ -53,7 +53,7 @@ |
||
53 | 53 | */ |
54 | 54 | public function peak(): ?string |
55 | 55 | { |
56 | - if ($this->offset + 1 > $this->length) { |
|
56 | + if ($this->offset + 1 > $this->length){ |
|
57 | 57 | return null; |
58 | 58 | } |
59 | 59 |
@@ -53,7 +53,8 @@ |
||
53 | 53 | */ |
54 | 54 | public function peak(): ?string |
55 | 55 | { |
56 | - if ($this->offset + 1 > $this->length) { |
|
56 | + if ($this->offset + 1 > $this->length) |
|
57 | + { |
|
57 | 58 | return null; |
58 | 59 | } |
59 | 60 |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | $buffer = null; |
28 | 28 | $bufferOffset = 0; |
29 | 29 | |
30 | - foreach ($src as $n) { |
|
31 | - if ($n instanceof Byte) { |
|
32 | - if ($buffer === null) { |
|
30 | + foreach ($src as $n){ |
|
31 | + if ($n instanceof Byte){ |
|
32 | + if ($buffer === null){ |
|
33 | 33 | $buffer = ''; |
34 | 34 | $bufferOffset = $n->offset; |
35 | 35 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | continue; |
39 | 39 | } |
40 | 40 | |
41 | - if ($buffer !== null) { |
|
41 | + if ($buffer !== null){ |
|
42 | 42 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
43 | 43 | $buffer = null; |
44 | 44 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | yield $n; |
47 | 47 | } |
48 | 48 | |
49 | - if ($buffer !== null) { |
|
49 | + if ($buffer !== null){ |
|
50 | 50 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
51 | 51 | } |
52 | 52 | } |
@@ -27,9 +27,12 @@ discard block |
||
27 | 27 | $buffer = null; |
28 | 28 | $bufferOffset = 0; |
29 | 29 | |
30 | - foreach ($src as $n) { |
|
31 | - if ($n instanceof Byte) { |
|
32 | - if ($buffer === null) { |
|
30 | + foreach ($src as $n) |
|
31 | + { |
|
32 | + if ($n instanceof Byte) |
|
33 | + { |
|
34 | + if ($buffer === null) |
|
35 | + { |
|
33 | 36 | $buffer = ''; |
34 | 37 | $bufferOffset = $n->offset; |
35 | 38 | } |
@@ -38,7 +41,8 @@ discard block |
||
38 | 41 | continue; |
39 | 42 | } |
40 | 43 | |
41 | - if ($buffer !== null) { |
|
44 | + if ($buffer !== null) |
|
45 | + { |
|
42 | 46 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
43 | 47 | $buffer = null; |
44 | 48 | } |
@@ -46,7 +50,8 @@ discard block |
||
46 | 50 | yield $n; |
47 | 51 | } |
48 | 52 | |
49 | - if ($buffer !== null) { |
|
53 | + if ($buffer !== null) |
|
54 | + { |
|
50 | 55 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
51 | 56 | } |
52 | 57 | } |
@@ -26,8 +26,8 @@ |
||
26 | 26 | */ |
27 | 27 | private function parseToken(Parser $parser, Token $token) |
28 | 28 | { |
29 | - if ($token->tokens === []) { |
|
30 | - if ($token->type === Token::TYPE_RAW) { |
|
29 | + if ($token->tokens === []){ |
|
30 | + if ($token->type === Token::TYPE_RAW){ |
|
31 | 31 | return new Raw($token->content); |
32 | 32 | } |
33 | 33 |
@@ -26,8 +26,10 @@ |
||
26 | 26 | */ |
27 | 27 | private function parseToken(Parser $parser, Token $token) |
28 | 28 | { |
29 | - if ($token->tokens === []) { |
|
30 | - if ($token->type === Token::TYPE_RAW) { |
|
29 | + if ($token->tokens === []) |
|
30 | + { |
|
31 | + if ($token->type === Token::TYPE_RAW) |
|
32 | + { |
|
31 | 33 | return new Raw($token->content); |
32 | 34 | } |
33 | 35 |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $parser->path = $path; |
59 | 59 | $parser->lexer = clone $this->lexer; |
60 | 60 | |
61 | - foreach ($parser->syntax as $grammar => $stx) { |
|
61 | + foreach ($parser->syntax as $grammar => $stx){ |
|
62 | 62 | $parser->syntax[$grammar] = clone $stx; |
63 | 63 | } |
64 | 64 | |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | { |
96 | 96 | $template = new Template(); |
97 | 97 | |
98 | - try { |
|
98 | + try{ |
|
99 | 99 | $this->parseTokens( |
100 | 100 | new Assembler($template, 'nodes'), |
101 | 101 | $this->lexer->parse($stream) |
102 | 102 | ); |
103 | - } catch (SyntaxException $e) { |
|
103 | + }catch (SyntaxException $e){ |
|
104 | 104 | throw new ParserException( |
105 | 105 | $e->getMessage(), |
106 | 106 | new Context($e->getToken(), $this->getPath()), |
@@ -122,21 +122,21 @@ discard block |
||
122 | 122 | $node = $asm->getNode(); |
123 | 123 | |
124 | 124 | $syntax = []; |
125 | - foreach ($this->syntax as $grammar => $stx) { |
|
125 | + foreach ($this->syntax as $grammar => $stx){ |
|
126 | 126 | $syntax[$grammar] = clone $stx; |
127 | 127 | } |
128 | 128 | |
129 | - foreach ($tokens as $token) { |
|
130 | - if (!isset($syntax[$token->grammar])) { |
|
129 | + foreach ($tokens as $token){ |
|
130 | + if (!isset($syntax[$token->grammar])){ |
|
131 | 131 | throw new SyntaxException('Undefined token', $token); |
132 | 132 | } |
133 | 133 | |
134 | 134 | $syntax[$token->grammar]->handle($this, $asm, $token); |
135 | 135 | } |
136 | 136 | |
137 | - if ($asm->getNode() !== $node) { |
|
137 | + if ($asm->getNode() !== $node){ |
|
138 | 138 | throw new SyntaxException( |
139 | - 'Invalid node hierarchy, unclosed ' . $asm->getStackPath(), |
|
139 | + 'Invalid node hierarchy, unclosed '.$asm->getStackPath(), |
|
140 | 140 | $asm->getNode()->getContext()->getToken() |
141 | 141 | ); |
142 | 142 | } |
@@ -58,7 +58,8 @@ discard block |
||
58 | 58 | $parser->path = $path; |
59 | 59 | $parser->lexer = clone $this->lexer; |
60 | 60 | |
61 | - foreach ($parser->syntax as $grammar => $stx) { |
|
61 | + foreach ($parser->syntax as $grammar => $stx) |
|
62 | + { |
|
62 | 63 | $parser->syntax[$grammar] = clone $stx; |
63 | 64 | } |
64 | 65 | |
@@ -95,12 +96,15 @@ discard block |
||
95 | 96 | { |
96 | 97 | $template = new Template(); |
97 | 98 | |
98 | - try { |
|
99 | + try |
|
100 | + { |
|
99 | 101 | $this->parseTokens( |
100 | 102 | new Assembler($template, 'nodes'), |
101 | 103 | $this->lexer->parse($stream) |
102 | 104 | ); |
103 | - } catch (SyntaxException $e) { |
|
105 | + } |
|
106 | + catch (SyntaxException $e) |
|
107 | + { |
|
104 | 108 | throw new ParserException( |
105 | 109 | $e->getMessage(), |
106 | 110 | new Context($e->getToken(), $this->getPath()), |
@@ -122,19 +126,23 @@ discard block |
||
122 | 126 | $node = $asm->getNode(); |
123 | 127 | |
124 | 128 | $syntax = []; |
125 | - foreach ($this->syntax as $grammar => $stx) { |
|
129 | + foreach ($this->syntax as $grammar => $stx) |
|
130 | + { |
|
126 | 131 | $syntax[$grammar] = clone $stx; |
127 | 132 | } |
128 | 133 | |
129 | - foreach ($tokens as $token) { |
|
130 | - if (!isset($syntax[$token->grammar])) { |
|
134 | + foreach ($tokens as $token) |
|
135 | + { |
|
136 | + if (!isset($syntax[$token->grammar])) |
|
137 | + { |
|
131 | 138 | throw new SyntaxException('Undefined token', $token); |
132 | 139 | } |
133 | 140 | |
134 | 141 | $syntax[$token->grammar]->handle($this, $asm, $token); |
135 | 142 | } |
136 | 143 | |
137 | - if ($asm->getNode() !== $node) { |
|
144 | + if ($asm->getNode() !== $node) |
|
145 | + { |
|
138 | 146 | throw new SyntaxException( |
139 | 147 | 'Invalid node hierarchy, unclosed ' . $asm->getStackPath(), |
140 | 148 | $asm->getNode()->getContext()->getToken() |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | { |
35 | 35 | protected function compile(string $source, array $visitors = [], LoaderInterface $loader = null) |
36 | 36 | { |
37 | - if ($loader === null) { |
|
37 | + if ($loader === null){ |
|
38 | 38 | $loader = new StringLoader(); |
39 | 39 | $loader->set('root', $source); |
40 | 40 | } |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | $builder->getCompiler()->addRenderer(new DynamicRenderer(new DirectiveGroup())); |
70 | 70 | $builder->getCompiler()->addRenderer(new HTMLRenderer()); |
71 | 71 | |
72 | - foreach ($this->getVisitors() as $visitor) { |
|
72 | + foreach ($this->getVisitors() as $visitor){ |
|
73 | 73 | $builder->addVisitor($visitor); |
74 | 74 | } |
75 | 75 | |
76 | - foreach ($visitors as $visitor) { |
|
76 | + foreach ($visitors as $visitor){ |
|
77 | 77 | $builder->addVisitor($visitor); |
78 | 78 | } |
79 | 79 | |
@@ -90,6 +90,6 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function getFixtureLoader(): LoaderInterface |
92 | 92 | { |
93 | - return new DirectoryLoader(__DIR__ . '/../fixtures'); |
|
93 | + return new DirectoryLoader(__DIR__.'/../fixtures'); |
|
94 | 94 | } |
95 | 95 | } |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | { |
35 | 35 | protected function compile(string $source, array $visitors = [], LoaderInterface $loader = null) |
36 | 36 | { |
37 | - if ($loader === null) { |
|
37 | + if ($loader === null) |
|
38 | + { |
|
38 | 39 | $loader = new StringLoader(); |
39 | 40 | $loader->set('root', $source); |
40 | 41 | } |
@@ -69,11 +70,13 @@ discard block |
||
69 | 70 | $builder->getCompiler()->addRenderer(new DynamicRenderer(new DirectiveGroup())); |
70 | 71 | $builder->getCompiler()->addRenderer(new HTMLRenderer()); |
71 | 72 | |
72 | - foreach ($this->getVisitors() as $visitor) { |
|
73 | + foreach ($this->getVisitors() as $visitor) |
|
74 | + { |
|
73 | 75 | $builder->addVisitor($visitor); |
74 | 76 | } |
75 | 77 | |
76 | - foreach ($visitors as $visitor) { |
|
78 | + foreach ($visitors as $visitor) |
|
79 | + { |
|
77 | 80 | $builder->addVisitor($visitor); |
78 | 81 | } |
79 | 82 |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | public function testVerbatim4(): void |
105 | 105 | { |
106 | 106 | $this->assertSame( |
107 | - '<script>alert(<?php echo json_encode' . |
|
107 | + '<script>alert(<?php echo json_encode'. |
|
108 | 108 | '("hello\' \'world", JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT, 512); ?>)</script>', |
109 | 109 | $res = $this->compile('<script>alert({{ "hello\' \'world" }})</script>')->getContent() |
110 | 110 | ); |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | { |
128 | 128 | ob_start(); |
129 | 129 | |
130 | - eval('?>' . $body); |
|
130 | + eval('?>'.$body); |
|
131 | 131 | |
132 | 132 | return ob_get_clean(); |
133 | 133 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | ); |
148 | 148 | |
149 | 149 | $loader->set( |
150 | - 'grid' . DIRECTORY_SEPARATOR . 'render', |
|
150 | + 'grid'.DIRECTORY_SEPARATOR.'render', |
|
151 | 151 | ' |
152 | 152 | <table> |
153 | 153 | <thead> |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | ); |
163 | 163 | |
164 | 164 | $loader->set( |
165 | - 'grid' . DIRECTORY_SEPARATOR . 'cell', |
|
165 | + 'grid'.DIRECTORY_SEPARATOR.'cell', |
|
166 | 166 | ' |
167 | 167 | <stack:push name="head"><tr>${title}</tr></stack:push> |
168 | 168 | <stack:push name="body"><td>${context}</td></stack:push> |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | protected function compile(Template $document): string |
35 | 35 | { |
36 | 36 | $compiler = new Compiler(); |
37 | - foreach (static::RENDERS as $renderer) { |
|
37 | + foreach (static::RENDERS as $renderer){ |
|
38 | 38 | $compiler->addRenderer(new $renderer()); |
39 | 39 | } |
40 | 40 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | { |
50 | 50 | $parser = new Parser(); |
51 | 51 | |
52 | - foreach (static::GRAMMARS as $grammar => $syntax) { |
|
52 | + foreach (static::GRAMMARS as $grammar => $syntax){ |
|
53 | 53 | $parser->addSyntax(new $grammar(), new $syntax()); |
54 | 54 | } |
55 | 55 |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | protected function compile(Template $document): string |
35 | 35 | { |
36 | 36 | $compiler = new Compiler(); |
37 | - foreach (static::RENDERS as $renderer) { |
|
37 | + foreach (static::RENDERS as $renderer) |
|
38 | + { |
|
38 | 39 | $compiler->addRenderer(new $renderer()); |
39 | 40 | } |
40 | 41 | |
@@ -49,7 +50,8 @@ discard block |
||
49 | 50 | { |
50 | 51 | $parser = new Parser(); |
51 | 52 | |
52 | - foreach (static::GRAMMARS as $grammar => $syntax) { |
|
53 | + foreach (static::GRAMMARS as $grammar => $syntax) |
|
54 | + { |
|
53 | 55 | $parser->addSyntax(new $grammar(), new $syntax()); |
54 | 56 | } |
55 | 57 |