@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public function add(ImportInterface $import): void |
42 | 42 | { |
43 | 43 | $node = $this->ctx->getParentNode(); |
44 | - if (!$node instanceof AttributedInterface) { |
|
44 | + if (!$node instanceof AttributedInterface){ |
|
45 | 45 | throw new LogicException(sprintf( |
46 | 46 | 'Unable to create import on node without attribute storage (%s)', |
47 | 47 | is_object($node) ? get_class($node) : gettype($node) |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function resolve(Builder $builder, string $name): ?Template |
66 | 66 | { |
67 | - foreach ($this->getImports() as $import) { |
|
67 | + foreach ($this->getImports() as $import){ |
|
68 | 68 | $tpl = $import->resolve($builder, $name); |
69 | - if ($tpl !== null) { |
|
69 | + if ($tpl !== null){ |
|
70 | 70 | return $tpl; |
71 | 71 | } |
72 | 72 | } |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | public function getImports(): array |
83 | 83 | { |
84 | 84 | $imports = []; |
85 | - foreach (array_reverse($this->ctx->getScope()) as $node) { |
|
86 | - if ($node instanceof AttributedInterface) { |
|
87 | - foreach ($node->getAttribute(self::class, []) as $import) { |
|
85 | + foreach (array_reverse($this->ctx->getScope()) as $node){ |
|
86 | + if ($node instanceof AttributedInterface){ |
|
87 | + foreach ($node->getAttribute(self::class, []) as $import){ |
|
88 | 88 | $imports[] = $import; |
89 | 89 | } |
90 | 90 | } |
@@ -41,7 +41,8 @@ discard block |
||
41 | 41 | public function add(ImportInterface $import): void |
42 | 42 | { |
43 | 43 | $node = $this->ctx->getParentNode(); |
44 | - if (!$node instanceof AttributedInterface) { |
|
44 | + if (!$node instanceof AttributedInterface) |
|
45 | + { |
|
45 | 46 | throw new LogicException(sprintf( |
46 | 47 | 'Unable to create import on node without attribute storage (%s)', |
47 | 48 | is_object($node) ? get_class($node) : gettype($node) |
@@ -64,9 +65,11 @@ discard block |
||
64 | 65 | */ |
65 | 66 | public function resolve(Builder $builder, string $name): ?Template |
66 | 67 | { |
67 | - foreach ($this->getImports() as $import) { |
|
68 | + foreach ($this->getImports() as $import) |
|
69 | + { |
|
68 | 70 | $tpl = $import->resolve($builder, $name); |
69 | - if ($tpl !== null) { |
|
71 | + if ($tpl !== null) |
|
72 | + { |
|
70 | 73 | return $tpl; |
71 | 74 | } |
72 | 75 | } |
@@ -82,9 +85,12 @@ discard block |
||
82 | 85 | public function getImports(): array |
83 | 86 | { |
84 | 87 | $imports = []; |
85 | - foreach (array_reverse($this->ctx->getScope()) as $node) { |
|
86 | - if ($node instanceof AttributedInterface) { |
|
87 | - foreach ($node->getAttribute(self::class, []) as $import) { |
|
88 | + foreach (array_reverse($this->ctx->getScope()) as $node) |
|
89 | + { |
|
90 | + if ($node instanceof AttributedInterface) |
|
91 | + { |
|
92 | + foreach ($node->getAttribute(self::class, []) as $import) |
|
93 | + { |
|
88 | 94 | $imports[] = $import; |
89 | 95 | } |
90 | 96 | } |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | { |
32 | 32 | $blocks = ['context' => []]; |
33 | 33 | |
34 | - foreach ($caller->attrs as $attr) { |
|
35 | - if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) { |
|
34 | + foreach ($caller->attrs as $attr){ |
|
35 | + if (!$attr instanceof Attr || $attr->name instanceof NodeInterface){ |
|
36 | 36 | // ignore name when attribute is dynamic |
37 | 37 | $blocks[sprintf('attr-%s', count($blocks))] = $attr; |
38 | 38 | continue; |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | $blocks[$attr->name] = new QuotedValue($attr->value); |
43 | 43 | } |
44 | 44 | |
45 | - foreach ($caller->nodes as $node) { |
|
46 | - if ($node instanceof Block) { |
|
45 | + foreach ($caller->nodes as $node){ |
|
46 | + if ($node instanceof Block){ |
|
47 | 47 | $blocks[$node->name] = $node->nodes; |
48 | - } else { |
|
48 | + }else{ |
|
49 | 49 | $blocks['context'][] = $node; |
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | - if ($blocks['context'] === []) { |
|
53 | + if ($blocks['context'] === []){ |
|
54 | 54 | unset($blocks['context']); |
55 | 55 | } |
56 | 56 |
@@ -31,8 +31,10 @@ discard block |
||
31 | 31 | { |
32 | 32 | $blocks = ['context' => []]; |
33 | 33 | |
34 | - foreach ($caller->attrs as $attr) { |
|
35 | - if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) { |
|
34 | + foreach ($caller->attrs as $attr) |
|
35 | + { |
|
36 | + if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) |
|
37 | + { |
|
36 | 38 | // ignore name when attribute is dynamic |
37 | 39 | $blocks[sprintf('attr-%s', count($blocks))] = $attr; |
38 | 40 | continue; |
@@ -42,15 +44,20 @@ discard block |
||
42 | 44 | $blocks[$attr->name] = new QuotedValue($attr->value); |
43 | 45 | } |
44 | 46 | |
45 | - foreach ($caller->nodes as $node) { |
|
46 | - if ($node instanceof Block) { |
|
47 | + foreach ($caller->nodes as $node) |
|
48 | + { |
|
49 | + if ($node instanceof Block) |
|
50 | + { |
|
47 | 51 | $blocks[$node->name] = $node->nodes; |
48 | - } else { |
|
52 | + } |
|
53 | + else |
|
54 | + { |
|
49 | 55 | $blocks['context'][] = $node; |
50 | 56 | } |
51 | 57 | } |
52 | 58 | |
53 | - if ($blocks['context'] === []) { |
|
59 | + if ($blocks['context'] === []) |
|
60 | + { |
|
54 | 61 | unset($blocks['context']); |
55 | 62 | } |
56 | 63 |
@@ -96,7 +96,7 @@ |
||
96 | 96 | protected function traverse(array $nodes, VisitorInterface ...$visitors) |
97 | 97 | { |
98 | 98 | $traverser = new Traverser(); |
99 | - foreach ($visitors as $visitor) { |
|
99 | + foreach ($visitors as $visitor){ |
|
100 | 100 | $traverser->addVisitor($visitor); |
101 | 101 | } |
102 | 102 |
@@ -96,7 +96,8 @@ |
||
96 | 96 | protected function traverse(array $nodes, VisitorInterface ...$visitors) |
97 | 97 | { |
98 | 98 | $traverser = new Traverser(); |
99 | - foreach ($visitors as $visitor) { |
|
99 | + foreach ($visitors as $visitor) |
|
100 | + { |
|
100 | 101 | $traverser->addVisitor($visitor); |
101 | 102 | } |
102 | 103 |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | public function trimValue(): array |
47 | 47 | { |
48 | 48 | $value = $this->value; |
49 | - if ($value instanceof Nil) { |
|
49 | + if ($value instanceof Nil){ |
|
50 | 50 | return []; |
51 | 51 | } |
52 | 52 | |
53 | - if (is_string($value)) { |
|
53 | + if (is_string($value)){ |
|
54 | 54 | return [new Raw(trim($value, '\'"'))]; |
55 | 55 | } |
56 | 56 | |
57 | - if (!$value instanceof Mixin) { |
|
57 | + if (!$value instanceof Mixin){ |
|
58 | 58 | return [$value]; |
59 | 59 | } |
60 | 60 | |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | $nodes = $value->nodes; |
63 | 63 | |
64 | 64 | $quote = null; |
65 | - if (count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[count($nodes) - 1] instanceof Raw) { |
|
65 | + if (count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[count($nodes) - 1] instanceof Raw){ |
|
66 | 66 | $quote = $nodes[0]->content[0]; |
67 | - if (!in_array($quote, ['"', '\''])) { |
|
67 | + if (!in_array($quote, ['"', '\''])){ |
|
68 | 68 | return $nodes; |
69 | 69 | } |
70 | 70 | |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | ); |
75 | 75 | } |
76 | 76 | |
77 | - foreach ($nodes as $index => $node) { |
|
78 | - if ($node instanceof Raw && $node->content === '') { |
|
77 | + foreach ($nodes as $index => $node){ |
|
78 | + if ($node instanceof Raw && $node->content === ''){ |
|
79 | 79 | unset($nodes[$index]); |
80 | 80 | } |
81 | 81 | } |
@@ -46,15 +46,18 @@ discard block |
||
46 | 46 | public function trimValue(): array |
47 | 47 | { |
48 | 48 | $value = $this->value; |
49 | - if ($value instanceof Nil) { |
|
49 | + if ($value instanceof Nil) |
|
50 | + { |
|
50 | 51 | return []; |
51 | 52 | } |
52 | 53 | |
53 | - if (is_string($value)) { |
|
54 | + if (is_string($value)) |
|
55 | + { |
|
54 | 56 | return [new Raw(trim($value, '\'"'))]; |
55 | 57 | } |
56 | 58 | |
57 | - if (!$value instanceof Mixin) { |
|
59 | + if (!$value instanceof Mixin) |
|
60 | + { |
|
58 | 61 | return [$value]; |
59 | 62 | } |
60 | 63 | |
@@ -62,9 +65,11 @@ discard block |
||
62 | 65 | $nodes = $value->nodes; |
63 | 66 | |
64 | 67 | $quote = null; |
65 | - if (count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[count($nodes) - 1] instanceof Raw) { |
|
68 | + if (count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[count($nodes) - 1] instanceof Raw) |
|
69 | + { |
|
66 | 70 | $quote = $nodes[0]->content[0]; |
67 | - if (!in_array($quote, ['"', '\''])) { |
|
71 | + if (!in_array($quote, ['"', '\''])) |
|
72 | + { |
|
68 | 73 | return $nodes; |
69 | 74 | } |
70 | 75 | |
@@ -74,8 +79,10 @@ discard block |
||
74 | 79 | ); |
75 | 80 | } |
76 | 81 | |
77 | - foreach ($nodes as $index => $node) { |
|
78 | - if ($node instanceof Raw && $node->content === '') { |
|
82 | + foreach ($nodes as $index => $node) |
|
83 | + { |
|
84 | + if ($node instanceof Raw && $node->content === '') |
|
85 | + { |
|
79 | 86 | unset($nodes[$index]); |
80 | 87 | } |
81 | 88 | } |
@@ -36,7 +36,7 @@ |
||
36 | 36 | */ |
37 | 37 | public function enterNode($node, VisitorContext $ctx): void |
38 | 38 | { |
39 | - if ($node instanceof Block && $node->getContext()->getPath() === $this->path) { |
|
39 | + if ($node instanceof Block && $node->getContext()->getPath() === $this->path){ |
|
40 | 40 | $node->name = null; |
41 | 41 | } |
42 | 42 | } |
@@ -36,7 +36,8 @@ |
||
36 | 36 | */ |
37 | 37 | public function enterNode($node, VisitorContext $ctx): void |
38 | 38 | { |
39 | - if ($node instanceof Block && $node->getContext()->getPath() === $this->path) { |
|
39 | + if ($node instanceof Block && $node->getContext()->getPath() === $this->path) |
|
40 | + { |
|
40 | 41 | $node->name = null; |
41 | 42 | } |
42 | 43 | } |
@@ -78,17 +78,17 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function leaveNode($node, VisitorContext $ctx) |
80 | 80 | { |
81 | - if ($node instanceof Output) { |
|
81 | + if ($node instanceof Output){ |
|
82 | 82 | return $this->output($node, $ctx); |
83 | 83 | } |
84 | 84 | |
85 | - if ($node instanceof Directive) { |
|
85 | + if ($node instanceof Directive){ |
|
86 | 86 | return $this->directive($node, $ctx); |
87 | 87 | } |
88 | 88 | |
89 | - if ($node instanceof Template) { |
|
89 | + if ($node instanceof Template){ |
|
90 | 90 | $extendsTag = $node->getAttribute(ExtendsParent::class); |
91 | - if ($extendsTag instanceof Tag) { |
|
91 | + if ($extendsTag instanceof Tag){ |
|
92 | 92 | $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs); |
93 | 93 | } |
94 | 94 | } |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | */ |
104 | 104 | private function directive(Directive $node, VisitorContext $ctx): PHP |
105 | 105 | { |
106 | - foreach ($this->directives as $renderer) { |
|
106 | + foreach ($this->directives as $renderer){ |
|
107 | 107 | $result = $renderer->render($node); |
108 | - if ($result !== null) { |
|
108 | + if ($result !== null){ |
|
109 | 109 | return new PHP($result, token_get_all($result), $node->getContext()); |
110 | 110 | } |
111 | 111 | } |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * In future this method can support context aware escaping based on tag location. |
128 | 128 | */ |
129 | 129 | |
130 | - if ($node->rawOutput) { |
|
130 | + if ($node->rawOutput){ |
|
131 | 131 | $result = sprintf('<?php echo %s; ?>', trim($node->body)); |
132 | - } else { |
|
132 | + }else{ |
|
133 | 133 | $filter = $node->filter ?? $this->getFilterContext($ctx); |
134 | 134 | |
135 | 135 | $result = sprintf("<?php echo {$filter}; ?>", trim($node->body)); |
@@ -151,22 +151,22 @@ discard block |
||
151 | 151 | // only "interesting" nodes |
152 | 152 | $context = []; |
153 | 153 | |
154 | - foreach (array_reverse($ctx->getScope()) as $node) { |
|
155 | - if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) { |
|
154 | + foreach (array_reverse($ctx->getScope()) as $node){ |
|
155 | + if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim){ |
|
156 | 156 | $context[] = $node; |
157 | 157 | } |
158 | 158 | |
159 | - if (count($context) === 2) { |
|
159 | + if (count($context) === 2){ |
|
160 | 160 | break; |
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | - if (count($context) !== 2) { |
|
164 | + if (count($context) !== 2){ |
|
165 | 165 | return $this->defaultFilter; |
166 | 166 | } |
167 | 167 | |
168 | 168 | // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter |
169 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') { |
|
169 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script'){ |
|
170 | 170 | return sprintf( |
171 | 171 | 'json_encode(%s, %s, %s)', |
172 | 172 | '%s', |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | // in on* and other attributes |
179 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') { |
|
179 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style'){ |
|
180 | 180 | return sprintf("'%s', %s, '%s'", '"', $this->defaultFilter, '"'); |
181 | 181 | } |
182 | 182 |
@@ -78,17 +78,21 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function leaveNode($node, VisitorContext $ctx) |
80 | 80 | { |
81 | - if ($node instanceof Output) { |
|
81 | + if ($node instanceof Output) |
|
82 | + { |
|
82 | 83 | return $this->output($node, $ctx); |
83 | 84 | } |
84 | 85 | |
85 | - if ($node instanceof Directive) { |
|
86 | + if ($node instanceof Directive) |
|
87 | + { |
|
86 | 88 | return $this->directive($node, $ctx); |
87 | 89 | } |
88 | 90 | |
89 | - if ($node instanceof Template) { |
|
91 | + if ($node instanceof Template) |
|
92 | + { |
|
90 | 93 | $extendsTag = $node->getAttribute(ExtendsParent::class); |
91 | - if ($extendsTag instanceof Tag) { |
|
94 | + if ($extendsTag instanceof Tag) |
|
95 | + { |
|
92 | 96 | $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs); |
93 | 97 | } |
94 | 98 | } |
@@ -103,9 +107,11 @@ discard block |
||
103 | 107 | */ |
104 | 108 | private function directive(Directive $node, VisitorContext $ctx): PHP |
105 | 109 | { |
106 | - foreach ($this->directives as $renderer) { |
|
110 | + foreach ($this->directives as $renderer) |
|
111 | + { |
|
107 | 112 | $result = $renderer->render($node); |
108 | - if ($result !== null) { |
|
113 | + if ($result !== null) |
|
114 | + { |
|
109 | 115 | return new PHP($result, token_get_all($result), $node->getContext()); |
110 | 116 | } |
111 | 117 | } |
@@ -127,9 +133,12 @@ discard block |
||
127 | 133 | * In future this method can support context aware escaping based on tag location. |
128 | 134 | */ |
129 | 135 | |
130 | - if ($node->rawOutput) { |
|
136 | + if ($node->rawOutput) |
|
137 | + { |
|
131 | 138 | $result = sprintf('<?php echo %s; ?>', trim($node->body)); |
132 | - } else { |
|
139 | + } |
|
140 | + else |
|
141 | + { |
|
133 | 142 | $filter = $node->filter ?? $this->getFilterContext($ctx); |
134 | 143 | |
135 | 144 | $result = sprintf("<?php echo {$filter}; ?>", trim($node->body)); |
@@ -151,22 +160,27 @@ discard block |
||
151 | 160 | // only "interesting" nodes |
152 | 161 | $context = []; |
153 | 162 | |
154 | - foreach (array_reverse($ctx->getScope()) as $node) { |
|
155 | - if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) { |
|
163 | + foreach (array_reverse($ctx->getScope()) as $node) |
|
164 | + { |
|
165 | + if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) |
|
166 | + { |
|
156 | 167 | $context[] = $node; |
157 | 168 | } |
158 | 169 | |
159 | - if (count($context) === 2) { |
|
170 | + if (count($context) === 2) |
|
171 | + { |
|
160 | 172 | break; |
161 | 173 | } |
162 | 174 | } |
163 | 175 | |
164 | - if (count($context) !== 2) { |
|
176 | + if (count($context) !== 2) |
|
177 | + { |
|
165 | 178 | return $this->defaultFilter; |
166 | 179 | } |
167 | 180 | |
168 | 181 | // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter |
169 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') { |
|
182 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') |
|
183 | + { |
|
170 | 184 | return sprintf( |
171 | 185 | 'json_encode(%s, %s, %s)', |
172 | 186 | '%s', |
@@ -176,7 +190,8 @@ discard block |
||
176 | 190 | } |
177 | 191 | |
178 | 192 | // in on* and other attributes |
179 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') { |
|
193 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') |
|
194 | + { |
|
180 | 195 | return sprintf("'%s', %s, '%s'", '"', $this->defaultFilter, '"'); |
181 | 196 | } |
182 | 197 |
@@ -43,16 +43,16 @@ |
||
43 | 43 | if ( |
44 | 44 | !$node instanceof PHP |
45 | 45 | || strpos($node->content, self::PHP_MARCO_EXISTS_FUNCTION) === false |
46 | - ) { |
|
46 | + ){ |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - if ($node->getContext()->getPath() !== $this->path) { |
|
50 | + if ($node->getContext()->getPath() !== $this->path){ |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
55 | - foreach ($exists->getBlocks() as $name => $block) { |
|
55 | + foreach ($exists->getBlocks() as $name => $block){ |
|
56 | 56 | // do not leak to parent template |
57 | 57 | $exists->set($name, 'false'); |
58 | 58 | } |
@@ -47,12 +47,14 @@ |
||
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - if ($node->getContext()->getPath() !== $this->path) { |
|
50 | + if ($node->getContext()->getPath() !== $this->path) |
|
51 | + { |
|
51 | 52 | return; |
52 | 53 | } |
53 | 54 | |
54 | 55 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
55 | - foreach ($exists->getBlocks() as $name => $block) { |
|
56 | + foreach ($exists->getBlocks() as $name => $block) |
|
57 | + { |
|
56 | 58 | // do not leak to parent template |
57 | 59 | $exists->set($name, 'false'); |
58 | 60 | } |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function leaveNode($node, VisitorContext $ctx) |
42 | 42 | { |
43 | - if ($node instanceof Tag && strpos($node->name, $this->pushKeyword) === 0) { |
|
43 | + if ($node instanceof Tag && strpos($node->name, $this->pushKeyword) === 0){ |
|
44 | 44 | return $this->registerPush(StackContext::on($ctx), $node); |
45 | 45 | } |
46 | 46 | |
47 | - if ($node instanceof Tag && strpos($node->name, $this->prependKeyword) === 0) { |
|
47 | + if ($node instanceof Tag && strpos($node->name, $this->prependKeyword) === 0){ |
|
48 | 48 | return $this->registerPrepend(StackContext::on($ctx), $node); |
49 | 49 | } |
50 | 50 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | { |
61 | 61 | $name = $this->stackName($node); |
62 | 62 | |
63 | - if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node))) { |
|
63 | + if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node))){ |
|
64 | 64 | return null; |
65 | 65 | } |
66 | 66 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | { |
77 | 77 | $name = $this->stackName($node); |
78 | 78 | |
79 | - if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node))) { |
|
79 | + if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node))){ |
|
80 | 80 | return null; |
81 | 81 | } |
82 | 82 | |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | */ |
90 | 90 | private function stackName(Tag $tag): ?string |
91 | 91 | { |
92 | - foreach ($tag->attrs as $attr) { |
|
93 | - if (is_string($attr->value)) { |
|
92 | + foreach ($tag->attrs as $attr){ |
|
93 | + if (is_string($attr->value)){ |
|
94 | 94 | $options[$attr->name] = trim($attr->value, '\'"'); |
95 | 95 | } |
96 | 96 | } |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | */ |
105 | 105 | private function uniqueID(Tag $tag): ?string |
106 | 106 | { |
107 | - foreach ($tag->attrs as $attr) { |
|
108 | - if (is_string($attr->value)) { |
|
107 | + foreach ($tag->attrs as $attr){ |
|
108 | + if (is_string($attr->value)){ |
|
109 | 109 | $options[$attr->name] = trim($attr->value, '\'"'); |
110 | 110 | } |
111 | 111 | } |
@@ -40,11 +40,13 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function leaveNode($node, VisitorContext $ctx) |
42 | 42 | { |
43 | - if ($node instanceof Tag && strpos($node->name, $this->pushKeyword) === 0) { |
|
43 | + if ($node instanceof Tag && strpos($node->name, $this->pushKeyword) === 0) |
|
44 | + { |
|
44 | 45 | return $this->registerPush(StackContext::on($ctx), $node); |
45 | 46 | } |
46 | 47 | |
47 | - if ($node instanceof Tag && strpos($node->name, $this->prependKeyword) === 0) { |
|
48 | + if ($node instanceof Tag && strpos($node->name, $this->prependKeyword) === 0) |
|
49 | + { |
|
48 | 50 | return $this->registerPrepend(StackContext::on($ctx), $node); |
49 | 51 | } |
50 | 52 | |
@@ -60,7 +62,8 @@ discard block |
||
60 | 62 | { |
61 | 63 | $name = $this->stackName($node); |
62 | 64 | |
63 | - if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node))) { |
|
65 | + if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node))) |
|
66 | + { |
|
64 | 67 | return null; |
65 | 68 | } |
66 | 69 | |
@@ -76,7 +79,8 @@ discard block |
||
76 | 79 | { |
77 | 80 | $name = $this->stackName($node); |
78 | 81 | |
79 | - if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node))) { |
|
82 | + if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node))) |
|
83 | + { |
|
80 | 84 | return null; |
81 | 85 | } |
82 | 86 | |
@@ -89,8 +93,10 @@ discard block |
||
89 | 93 | */ |
90 | 94 | private function stackName(Tag $tag): ?string |
91 | 95 | { |
92 | - foreach ($tag->attrs as $attr) { |
|
93 | - if (is_string($attr->value)) { |
|
96 | + foreach ($tag->attrs as $attr) |
|
97 | + { |
|
98 | + if (is_string($attr->value)) |
|
99 | + { |
|
94 | 100 | $options[$attr->name] = trim($attr->value, '\'"'); |
95 | 101 | } |
96 | 102 | } |
@@ -104,8 +110,10 @@ discard block |
||
104 | 110 | */ |
105 | 111 | private function uniqueID(Tag $tag): ?string |
106 | 112 | { |
107 | - foreach ($tag->attrs as $attr) { |
|
108 | - if (is_string($attr->value)) { |
|
113 | + foreach ($tag->attrs as $attr) |
|
114 | + { |
|
115 | + if (is_string($attr->value)) |
|
116 | + { |
|
109 | 117 | $options[$attr->name] = trim($attr->value, '\'"'); |
110 | 118 | } |
111 | 119 | } |
@@ -44,9 +44,9 @@ |
||
44 | 44 | */ |
45 | 45 | public function leaveNode($node, VisitorContext $ctx) |
46 | 46 | { |
47 | - if ($node instanceof Raw && trim($node->content, $this->trim) === '') { |
|
48 | - foreach ($ctx->getScope() as $scope) { |
|
49 | - if ($scope instanceof Attr) { |
|
47 | + if ($node instanceof Raw && trim($node->content, $this->trim) === ''){ |
|
48 | + foreach ($ctx->getScope() as $scope){ |
|
49 | + if ($scope instanceof Attr){ |
|
50 | 50 | // do not trim attribute values |
51 | 51 | return null; |
52 | 52 | } |
@@ -44,9 +44,12 @@ |
||
44 | 44 | */ |
45 | 45 | public function leaveNode($node, VisitorContext $ctx) |
46 | 46 | { |
47 | - if ($node instanceof Raw && trim($node->content, $this->trim) === '') { |
|
48 | - foreach ($ctx->getScope() as $scope) { |
|
49 | - if ($scope instanceof Attr) { |
|
47 | + if ($node instanceof Raw && trim($node->content, $this->trim) === '') |
|
48 | + { |
|
49 | + foreach ($ctx->getScope() as $scope) |
|
50 | + { |
|
51 | + if ($scope instanceof Attr) |
|
52 | + { |
|
50 | 53 | // do not trim attribute values |
51 | 54 | return null; |
52 | 55 | } |