@@ -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 | } |
@@ -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 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $this->path = $path; |
40 | 40 | $this->alias = $alias ?? $path; |
41 | 41 | |
42 | - if ($alias === null && strrpos($this->alias, '/') !== false) { |
|
42 | + if ($alias === null && strrpos($this->alias, '/') !== false){ |
|
43 | 43 | $this->alias = substr($this->alias, strrpos($this->alias, '/') + 1); |
44 | 44 | } |
45 | 45 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function resolve(Builder $builder, string $name): ?Template |
69 | 69 | { |
70 | - if ($this->alias !== $name) { |
|
70 | + if ($this->alias !== $name){ |
|
71 | 71 | return null; |
72 | 72 | } |
73 | 73 |
@@ -39,7 +39,8 @@ discard block |
||
39 | 39 | $this->path = $path; |
40 | 40 | $this->alias = $alias ?? $path; |
41 | 41 | |
42 | - if ($alias === null && strrpos($this->alias, '/') !== false) { |
|
42 | + if ($alias === null && strrpos($this->alias, '/') !== false) |
|
43 | + { |
|
43 | 44 | $this->alias = substr($this->alias, strrpos($this->alias, '/') + 1); |
44 | 45 | } |
45 | 46 | |
@@ -67,7 +68,8 @@ discard block |
||
67 | 68 | */ |
68 | 69 | public function resolve(Builder $builder, string $name): ?Template |
69 | 70 | { |
70 | - if ($this->alias !== $name) { |
|
71 | + if ($this->alias !== $name) |
|
72 | + { |
|
71 | 73 | return null; |
72 | 74 | } |
73 | 75 |
@@ -46,7 +46,7 @@ |
||
46 | 46 | */ |
47 | 47 | public function resolve(Builder $builder, string $name): ?Template |
48 | 48 | { |
49 | - if ($name !== $this->name) { |
|
49 | + if ($name !== $this->name){ |
|
50 | 50 | return null; |
51 | 51 | } |
52 | 52 |
@@ -46,7 +46,8 @@ |
||
46 | 46 | */ |
47 | 47 | public function resolve(Builder $builder, string $name): ?Template |
48 | 48 | { |
49 | - if ($name !== $this->name) { |
|
49 | + if ($name !== $this->name) |
|
50 | + { |
|
50 | 51 | return null; |
51 | 52 | } |
52 | 53 |
@@ -49,6 +49,6 @@ |
||
49 | 49 | $path = substr($name, strlen($this->prefix) + 1); |
50 | 50 | $path = str_replace('.', DIRECTORY_SEPARATOR, $path); |
51 | 51 | |
52 | - return $builder->load($this->path . DIRECTORY_SEPARATOR . $path); |
|
52 | + return $builder->load($this->path.DIRECTORY_SEPARATOR.$path); |
|
53 | 53 | } |
54 | 54 | } |
@@ -50,19 +50,19 @@ |
||
50 | 50 | */ |
51 | 51 | public function resolve(Builder $builder, string $name): ?Template |
52 | 52 | { |
53 | - if ($this->template === null) { |
|
53 | + if ($this->template === null){ |
|
54 | 54 | $this->template = $builder->load($this->path); |
55 | 55 | } |
56 | 56 | |
57 | 57 | $path = $name; |
58 | - if ($this->prefix !== null) { |
|
58 | + if ($this->prefix !== null){ |
|
59 | 59 | $path = substr($path, strlen($this->prefix) + 1); |
60 | 60 | } |
61 | 61 | |
62 | 62 | /** @var ImportInterface $import */ |
63 | - foreach ($this->template->getAttribute(ImportContext::class, []) as $import) { |
|
63 | + foreach ($this->template->getAttribute(ImportContext::class, []) as $import){ |
|
64 | 64 | $tpl = $import->resolve($builder, $path); |
65 | - if ($tpl !== null) { |
|
65 | + if ($tpl !== null){ |
|
66 | 66 | return $tpl; |
67 | 67 | } |
68 | 68 | } |
@@ -50,19 +50,23 @@ |
||
50 | 50 | */ |
51 | 51 | public function resolve(Builder $builder, string $name): ?Template |
52 | 52 | { |
53 | - if ($this->template === null) { |
|
53 | + if ($this->template === null) |
|
54 | + { |
|
54 | 55 | $this->template = $builder->load($this->path); |
55 | 56 | } |
56 | 57 | |
57 | 58 | $path = $name; |
58 | - if ($this->prefix !== null) { |
|
59 | + if ($this->prefix !== null) |
|
60 | + { |
|
59 | 61 | $path = substr($path, strlen($this->prefix) + 1); |
60 | 62 | } |
61 | 63 | |
62 | 64 | /** @var ImportInterface $import */ |
63 | - foreach ($this->template->getAttribute(ImportContext::class, []) as $import) { |
|
65 | + foreach ($this->template->getAttribute(ImportContext::class, []) as $import) |
|
66 | + { |
|
64 | 67 | $tpl = $import->resolve($builder, $path); |
65 | - if ($tpl !== null) { |
|
68 | + if ($tpl !== null) |
|
69 | + { |
|
66 | 70 | return $tpl; |
67 | 71 | } |
68 | 72 | } |
@@ -43,25 +43,25 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function enterNode($node, VisitorContext $ctx) |
45 | 45 | { |
46 | - if (!$node instanceof Aggregate) { |
|
46 | + if (!$node instanceof Aggregate){ |
|
47 | 47 | return null; |
48 | 48 | } |
49 | 49 | |
50 | - foreach ($this->blocks->getUnclaimed() as $name) { |
|
50 | + foreach ($this->blocks->getUnclaimed() as $name){ |
|
51 | 51 | $alias = $node->accepts($name); |
52 | - if ($alias === null) { |
|
52 | + if ($alias === null){ |
|
53 | 53 | continue; |
54 | 54 | } |
55 | 55 | |
56 | 56 | $value = $this->blocks->claim($name); |
57 | 57 | |
58 | - if ($value instanceof QuotedValue) { |
|
58 | + if ($value instanceof QuotedValue){ |
|
59 | 59 | $node->nodes[] = new Attr($alias, $value->getValue()); |
60 | 60 | continue; |
61 | 61 | } |
62 | 62 | |
63 | 63 | // simple copy attribute copy |
64 | - if ($value instanceof Attr) { |
|
64 | + if ($value instanceof Attr){ |
|
65 | 65 | $node->nodes[] = clone $value; |
66 | 66 | continue; |
67 | 67 | } |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | */ |
84 | 84 | private function wrapValue($value) |
85 | 85 | { |
86 | - if ($value === [] || $value === null || $value instanceof Nil) { |
|
86 | + if ($value === [] || $value === null || $value instanceof Nil){ |
|
87 | 87 | return new Nil(); |
88 | 88 | } |
89 | 89 | |
90 | - if ($value instanceof Verbatim || is_scalar($value)) { |
|
90 | + if ($value instanceof Verbatim || is_scalar($value)){ |
|
91 | 91 | return $value; |
92 | 92 | } |
93 | 93 |
@@ -43,25 +43,30 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function enterNode($node, VisitorContext $ctx) |
45 | 45 | { |
46 | - if (!$node instanceof Aggregate) { |
|
46 | + if (!$node instanceof Aggregate) |
|
47 | + { |
|
47 | 48 | return null; |
48 | 49 | } |
49 | 50 | |
50 | - foreach ($this->blocks->getUnclaimed() as $name) { |
|
51 | + foreach ($this->blocks->getUnclaimed() as $name) |
|
52 | + { |
|
51 | 53 | $alias = $node->accepts($name); |
52 | - if ($alias === null) { |
|
54 | + if ($alias === null) |
|
55 | + { |
|
53 | 56 | continue; |
54 | 57 | } |
55 | 58 | |
56 | 59 | $value = $this->blocks->claim($name); |
57 | 60 | |
58 | - if ($value instanceof QuotedValue) { |
|
61 | + if ($value instanceof QuotedValue) |
|
62 | + { |
|
59 | 63 | $node->nodes[] = new Attr($alias, $value->getValue()); |
60 | 64 | continue; |
61 | 65 | } |
62 | 66 | |
63 | 67 | // simple copy attribute copy |
64 | - if ($value instanceof Attr) { |
|
68 | + if ($value instanceof Attr) |
|
69 | + { |
|
65 | 70 | $node->nodes[] = clone $value; |
66 | 71 | continue; |
67 | 72 | } |
@@ -83,11 +88,13 @@ discard block |
||
83 | 88 | */ |
84 | 89 | private function wrapValue($value) |
85 | 90 | { |
86 | - if ($value === [] || $value === null || $value instanceof Nil) { |
|
91 | + if ($value === [] || $value === null || $value instanceof Nil) |
|
92 | + { |
|
87 | 93 | return new Nil(); |
88 | 94 | } |
89 | 95 | |
90 | - if ($value instanceof Verbatim || is_scalar($value)) { |
|
96 | + if ($value instanceof Verbatim || is_scalar($value)) |
|
97 | + { |
|
91 | 98 | return $value; |
92 | 99 | } |
93 | 100 |
@@ -59,20 +59,20 @@ discard block |
||
59 | 59 | strpos($node->content, self::PHP_MACRO_FUNCTION) === false |
60 | 60 | && strpos($node->content, self::PHP_MARCO_EXISTS_FUNCTION) === false |
61 | 61 | ) |
62 | - ) { |
|
62 | + ){ |
|
63 | 63 | return null; |
64 | 64 | } |
65 | 65 | |
66 | 66 | $php = new PHPMixin($node->tokens, self::PHP_MACRO_FUNCTION); |
67 | - foreach ($this->blocks->getNames() as $name) { |
|
67 | + foreach ($this->blocks->getNames() as $name){ |
|
68 | 68 | $block = $this->blocks->get($name); |
69 | 69 | |
70 | - if ($this->isReference($block)) { |
|
70 | + if ($this->isReference($block)){ |
|
71 | 71 | // resolved on later stage |
72 | 72 | continue; |
73 | 73 | } |
74 | 74 | |
75 | - if ($php->has($name)) { |
|
75 | + if ($php->has($name)){ |
|
76 | 76 | $php->set($name, $this->trimPHP($this->blocks->claim($name))); |
77 | 77 | } |
78 | 78 | } |
@@ -81,15 +81,15 @@ discard block |
||
81 | 81 | $node->tokens = token_get_all($node->content); |
82 | 82 | |
83 | 83 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
84 | - foreach ($this->blocks->getNames() as $name) { |
|
84 | + foreach ($this->blocks->getNames() as $name){ |
|
85 | 85 | $block = $this->blocks->get($name); |
86 | 86 | |
87 | - if ($this->isReference($block)) { |
|
87 | + if ($this->isReference($block)){ |
|
88 | 88 | // resolved on later stage |
89 | 89 | continue; |
90 | 90 | } |
91 | 91 | |
92 | - if ($exists->has($name)) { |
|
92 | + if ($exists->has($name)){ |
|
93 | 93 | $exists->set($name, 'true'); |
94 | 94 | } |
95 | 95 | } |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | */ |
112 | 112 | private function isReference($node): bool |
113 | 113 | { |
114 | - switch (true) { |
|
114 | + switch (true){ |
|
115 | 115 | case is_array($node): |
116 | - foreach ($node as $child) { |
|
117 | - if ($this->isReference($child)) { |
|
116 | + foreach ($node as $child){ |
|
117 | + if ($this->isReference($child)){ |
|
118 | 118 | return true; |
119 | 119 | } |
120 | 120 | } |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | return $this->isReference($node->getValue()); |
126 | 126 | |
127 | 127 | case $node instanceof Mixin: |
128 | - foreach ($node->nodes as $child) { |
|
129 | - if ($this->isReference($child)) { |
|
128 | + foreach ($node->nodes as $child){ |
|
129 | + if ($this->isReference($child)){ |
|
130 | 130 | return true; |
131 | 131 | } |
132 | 132 | } |
@@ -146,10 +146,10 @@ discard block |
||
146 | 146 | */ |
147 | 147 | private function trimPHP($node): string |
148 | 148 | { |
149 | - switch (true) { |
|
149 | + switch (true){ |
|
150 | 150 | case is_array($node): |
151 | 151 | $result = []; |
152 | - foreach ($node as $child) { |
|
152 | + foreach ($node as $child){ |
|
153 | 153 | $result[] = $this->trimPHP($child); |
154 | 154 | } |
155 | 155 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | case $node instanceof Mixin: |
159 | 159 | $result = []; |
160 | - foreach ($node->nodes as $child) { |
|
160 | + foreach ($node->nodes as $child){ |
|
161 | 161 | $result[] = $this->trimPHP($child); |
162 | 162 | } |
163 | 163 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | return trim($node->body); |
171 | 171 | |
172 | 172 | case $node instanceof PHP: |
173 | - if ($node->getContext()->getValue(PHP::ORIGINAL_BODY) !== null) { |
|
173 | + if ($node->getContext()->getValue(PHP::ORIGINAL_BODY) !== null){ |
|
174 | 174 | return $node->getContext()->getValue(PHP::ORIGINAL_BODY); |
175 | 175 | } |
176 | 176 | |
@@ -190,13 +190,13 @@ discard block |
||
190 | 190 | private function exportValue(Raw $node): string |
191 | 191 | { |
192 | 192 | $value = $node->content; |
193 | - switch (true) { |
|
193 | + switch (true){ |
|
194 | 194 | case strtolower($value) === 'true': |
195 | 195 | return 'true'; |
196 | 196 | case strtolower($value) === 'false': |
197 | 197 | return 'false'; |
198 | 198 | case is_float($value) || is_numeric($value): |
199 | - return (string) $value; |
|
199 | + return (string)$value; |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | return var_export($node->content, true); |
@@ -64,15 +64,18 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | $php = new PHPMixin($node->tokens, self::PHP_MACRO_FUNCTION); |
67 | - foreach ($this->blocks->getNames() as $name) { |
|
67 | + foreach ($this->blocks->getNames() as $name) |
|
68 | + { |
|
68 | 69 | $block = $this->blocks->get($name); |
69 | 70 | |
70 | - if ($this->isReference($block)) { |
|
71 | + if ($this->isReference($block)) |
|
72 | + { |
|
71 | 73 | // resolved on later stage |
72 | 74 | continue; |
73 | 75 | } |
74 | 76 | |
75 | - if ($php->has($name)) { |
|
77 | + if ($php->has($name)) |
|
78 | + { |
|
76 | 79 | $php->set($name, $this->trimPHP($this->blocks->claim($name))); |
77 | 80 | } |
78 | 81 | } |
@@ -81,15 +84,18 @@ discard block |
||
81 | 84 | $node->tokens = token_get_all($node->content); |
82 | 85 | |
83 | 86 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
84 | - foreach ($this->blocks->getNames() as $name) { |
|
87 | + foreach ($this->blocks->getNames() as $name) |
|
88 | + { |
|
85 | 89 | $block = $this->blocks->get($name); |
86 | 90 | |
87 | - if ($this->isReference($block)) { |
|
91 | + if ($this->isReference($block)) |
|
92 | + { |
|
88 | 93 | // resolved on later stage |
89 | 94 | continue; |
90 | 95 | } |
91 | 96 | |
92 | - if ($exists->has($name)) { |
|
97 | + if ($exists->has($name)) |
|
98 | + { |
|
93 | 99 | $exists->set($name, 'true'); |
94 | 100 | } |
95 | 101 | } |
@@ -111,10 +117,13 @@ discard block |
||
111 | 117 | */ |
112 | 118 | private function isReference($node): bool |
113 | 119 | { |
114 | - switch (true) { |
|
120 | + switch (true) |
|
121 | + { |
|
115 | 122 | case is_array($node): |
116 | - foreach ($node as $child) { |
|
117 | - if ($this->isReference($child)) { |
|
123 | + foreach ($node as $child) |
|
124 | + { |
|
125 | + if ($this->isReference($child)) |
|
126 | + { |
|
118 | 127 | return true; |
119 | 128 | } |
120 | 129 | } |
@@ -125,8 +134,10 @@ discard block |
||
125 | 134 | return $this->isReference($node->getValue()); |
126 | 135 | |
127 | 136 | case $node instanceof Mixin: |
128 | - foreach ($node->nodes as $child) { |
|
129 | - if ($this->isReference($child)) { |
|
137 | + foreach ($node->nodes as $child) |
|
138 | + { |
|
139 | + if ($this->isReference($child)) |
|
140 | + { |
|
130 | 141 | return true; |
131 | 142 | } |
132 | 143 | } |
@@ -146,10 +157,12 @@ discard block |
||
146 | 157 | */ |
147 | 158 | private function trimPHP($node): string |
148 | 159 | { |
149 | - switch (true) { |
|
160 | + switch (true) |
|
161 | + { |
|
150 | 162 | case is_array($node): |
151 | 163 | $result = []; |
152 | - foreach ($node as $child) { |
|
164 | + foreach ($node as $child) |
|
165 | + { |
|
153 | 166 | $result[] = $this->trimPHP($child); |
154 | 167 | } |
155 | 168 | |
@@ -157,7 +170,8 @@ discard block |
||
157 | 170 | |
158 | 171 | case $node instanceof Mixin: |
159 | 172 | $result = []; |
160 | - foreach ($node->nodes as $child) { |
|
173 | + foreach ($node->nodes as $child) |
|
174 | + { |
|
161 | 175 | $result[] = $this->trimPHP($child); |
162 | 176 | } |
163 | 177 | |
@@ -170,7 +184,8 @@ discard block |
||
170 | 184 | return trim($node->body); |
171 | 185 | |
172 | 186 | case $node instanceof PHP: |
173 | - if ($node->getContext()->getValue(PHP::ORIGINAL_BODY) !== null) { |
|
187 | + if ($node->getContext()->getValue(PHP::ORIGINAL_BODY) !== null) |
|
188 | + { |
|
174 | 189 | return $node->getContext()->getValue(PHP::ORIGINAL_BODY); |
175 | 190 | } |
176 | 191 | |
@@ -190,7 +205,8 @@ discard block |
||
190 | 205 | private function exportValue(Raw $node): string |
191 | 206 | { |
192 | 207 | $value = $node->content; |
193 | - switch (true) { |
|
208 | + switch (true) |
|
209 | + { |
|
194 | 210 | case strtolower($value) === 'true': |
195 | 211 | return 'true'; |
196 | 212 | case strtolower($value) === 'false': |
@@ -30,15 +30,15 @@ |
||
30 | 30 | */ |
31 | 31 | public function enterNode($node, VisitorContext $ctx) |
32 | 32 | { |
33 | - if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) { |
|
33 | + if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE){ |
|
34 | 34 | return null; |
35 | 35 | } |
36 | 36 | |
37 | - if ($node->value instanceof Nil) { |
|
37 | + if ($node->value instanceof Nil){ |
|
38 | 38 | return new Aggregate($node->getContext()); |
39 | 39 | } |
40 | 40 | |
41 | - if (!is_string($node->value)) { |
|
41 | + if (!is_string($node->value)){ |
|
42 | 42 | return null; |
43 | 43 | } |
44 | 44 |
@@ -30,15 +30,18 @@ |
||
30 | 30 | */ |
31 | 31 | public function enterNode($node, VisitorContext $ctx) |
32 | 32 | { |
33 | - if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) { |
|
33 | + if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) |
|
34 | + { |
|
34 | 35 | return null; |
35 | 36 | } |
36 | 37 | |
37 | - if ($node->value instanceof Nil) { |
|
38 | + if ($node->value instanceof Nil) |
|
39 | + { |
|
38 | 40 | return new Aggregate($node->getContext()); |
39 | 41 | } |
40 | 42 | |
41 | - if (!is_string($node->value)) { |
|
43 | + if (!is_string($node->value)) |
|
44 | + { |
|
42 | 45 | return null; |
43 | 46 | } |
44 | 47 |