@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
30 | 30 | { |
31 | - switch (true) { |
|
31 | + switch (true){ |
|
32 | 32 | case $node instanceof Tag: |
33 | 33 | $this->tag($compiler, $result, $node); |
34 | 34 | return true; |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | { |
51 | 51 | $result->push(sprintf('<%s', $node->name), $node->getContext()); |
52 | 52 | |
53 | - foreach ($node->attrs as $attr) { |
|
54 | - if (!$attr instanceof Attribute) { |
|
53 | + foreach ($node->attrs as $attr){ |
|
54 | + if (!$attr instanceof Attribute){ |
|
55 | 55 | $compiler->compile($attr, $result); |
56 | 56 | continue; |
57 | 57 | } |
@@ -61,30 +61,30 @@ discard block |
||
61 | 61 | |
62 | 62 | $result->push(sprintf('%s>', $node->void ? '/' : ''), null); |
63 | 63 | |
64 | - foreach ($node->nodes as $child) { |
|
64 | + foreach ($node->nodes as $child){ |
|
65 | 65 | $compiler->compile($child, $result); |
66 | 66 | } |
67 | 67 | |
68 | - if (!$node->void) { |
|
68 | + if (!$node->void){ |
|
69 | 69 | $result->push(sprintf('</%s>', $node->name), null); |
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
73 | 73 | private function attribute(Compiler $compiler, Result $result, Attr $node): void |
74 | 74 | { |
75 | - if ($node->name instanceof NodeInterface) { |
|
75 | + if ($node->name instanceof NodeInterface){ |
|
76 | 76 | $result->push(' ', null); |
77 | 77 | $compiler->compile($node->name, $result); |
78 | - } else { |
|
78 | + }else{ |
|
79 | 79 | $result->push(sprintf(' %s', $node->name), $node->getContext()); |
80 | 80 | } |
81 | 81 | |
82 | 82 | $value = $node->value; |
83 | - if ($value instanceof Nil) { |
|
83 | + if ($value instanceof Nil){ |
|
84 | 84 | return; |
85 | 85 | } |
86 | 86 | |
87 | - if ($value instanceof NodeInterface) { |
|
87 | + if ($value instanceof NodeInterface){ |
|
88 | 88 | $result->push('=', null); |
89 | 89 | $compiler->compile($value, $result); |
90 | 90 | return; |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | |
96 | 96 | private function verbatim(Compiler $compiler, Result $result, Verbatim $node): void |
97 | 97 | { |
98 | - foreach ($node->nodes as $child) { |
|
99 | - if (is_string($child)) { |
|
98 | + foreach ($node->nodes as $child){ |
|
99 | + if (is_string($child)){ |
|
100 | 100 | $result->push($child, null); |
101 | 101 | continue; |
102 | 102 | } |
@@ -28,7 +28,8 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
30 | 30 | { |
31 | - switch (true) { |
|
31 | + switch (true) |
|
32 | + { |
|
32 | 33 | case $node instanceof Tag: |
33 | 34 | $this->tag($compiler, $result, $node); |
34 | 35 | return true; |
@@ -50,8 +51,10 @@ discard block |
||
50 | 51 | { |
51 | 52 | $result->push(sprintf('<%s', $node->name), $node->getContext()); |
52 | 53 | |
53 | - foreach ($node->attrs as $attr) { |
|
54 | - if (!$attr instanceof Attribute) { |
|
54 | + foreach ($node->attrs as $attr) |
|
55 | + { |
|
56 | + if (!$attr instanceof Attribute) |
|
57 | + { |
|
55 | 58 | $compiler->compile($attr, $result); |
56 | 59 | continue; |
57 | 60 | } |
@@ -61,30 +64,37 @@ discard block |
||
61 | 64 | |
62 | 65 | $result->push(sprintf('%s>', $node->void ? '/' : ''), null); |
63 | 66 | |
64 | - foreach ($node->nodes as $child) { |
|
67 | + foreach ($node->nodes as $child) |
|
68 | + { |
|
65 | 69 | $compiler->compile($child, $result); |
66 | 70 | } |
67 | 71 | |
68 | - if (!$node->void) { |
|
72 | + if (!$node->void) |
|
73 | + { |
|
69 | 74 | $result->push(sprintf('</%s>', $node->name), null); |
70 | 75 | } |
71 | 76 | } |
72 | 77 | |
73 | 78 | private function attribute(Compiler $compiler, Result $result, Attr $node): void |
74 | 79 | { |
75 | - if ($node->name instanceof NodeInterface) { |
|
80 | + if ($node->name instanceof NodeInterface) |
|
81 | + { |
|
76 | 82 | $result->push(' ', null); |
77 | 83 | $compiler->compile($node->name, $result); |
78 | - } else { |
|
84 | + } |
|
85 | + else |
|
86 | + { |
|
79 | 87 | $result->push(sprintf(' %s', $node->name), $node->getContext()); |
80 | 88 | } |
81 | 89 | |
82 | 90 | $value = $node->value; |
83 | - if ($value instanceof Nil) { |
|
91 | + if ($value instanceof Nil) |
|
92 | + { |
|
84 | 93 | return; |
85 | 94 | } |
86 | 95 | |
87 | - if ($value instanceof NodeInterface) { |
|
96 | + if ($value instanceof NodeInterface) |
|
97 | + { |
|
88 | 98 | $result->push('=', null); |
89 | 99 | $compiler->compile($value, $result); |
90 | 100 | return; |
@@ -95,8 +105,10 @@ discard block |
||
95 | 105 | |
96 | 106 | private function verbatim(Compiler $compiler, Result $result, Verbatim $node): void |
97 | 107 | { |
98 | - foreach ($node->nodes as $child) { |
|
99 | - if (is_string($child)) { |
|
108 | + foreach ($node->nodes as $child) |
|
109 | + { |
|
110 | + if (is_string($child)) |
|
111 | + { |
|
100 | 112 | $result->push($child, null); |
101 | 113 | continue; |
102 | 114 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | public function __construct( |
33 | 33 | DirectiveRendererInterface $directiveRenderer = null, |
34 | 34 | string $defaultFilter = self::DEFAULT_FILTER |
35 | - ) { |
|
35 | + ){ |
|
36 | 36 | $this->directiveRenderer = $directiveRenderer; |
37 | 37 | $this->defaultFilter = $defaultFilter; |
38 | 38 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
44 | 44 | { |
45 | - switch (true) { |
|
45 | + switch (true){ |
|
46 | 46 | case $node instanceof Output: |
47 | 47 | $this->output($result, $node); |
48 | 48 | return true; |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | */ |
61 | 61 | private function directive(Result $source, Directive $directive): void |
62 | 62 | { |
63 | - if ($this->directiveRenderer !== null) { |
|
63 | + if ($this->directiveRenderer !== null){ |
|
64 | 64 | $result = $this->directiveRenderer->render($directive); |
65 | - if ($result !== null) { |
|
65 | + if ($result !== null){ |
|
66 | 66 | $source->push($result, $directive->getContext()); |
67 | 67 | return; |
68 | 68 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | private function output(Result $source, Output $output): void |
78 | 78 | { |
79 | - if ($output->rawOutput) { |
|
79 | + if ($output->rawOutput){ |
|
80 | 80 | $source->push(sprintf('<?php echo %s; ?>', trim($output->body)), $output->getContext()); |
81 | 81 | return; |
82 | 82 | } |
@@ -42,7 +42,8 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
44 | 44 | { |
45 | - switch (true) { |
|
45 | + switch (true) |
|
46 | + { |
|
46 | 47 | case $node instanceof Output: |
47 | 48 | $this->output($result, $node); |
48 | 49 | return true; |
@@ -60,9 +61,11 @@ discard block |
||
60 | 61 | */ |
61 | 62 | private function directive(Result $source, Directive $directive): void |
62 | 63 | { |
63 | - if ($this->directiveRenderer !== null) { |
|
64 | + if ($this->directiveRenderer !== null) |
|
65 | + { |
|
64 | 66 | $result = $this->directiveRenderer->render($directive); |
65 | - if ($result !== null) { |
|
67 | + if ($result !== null) |
|
68 | + { |
|
66 | 69 | $source->push($result, $directive->getContext()); |
67 | 70 | return; |
68 | 71 | } |
@@ -76,7 +79,8 @@ discard block |
||
76 | 79 | |
77 | 80 | private function output(Result $source, Output $output): void |
78 | 81 | { |
79 | - if ($output->rawOutput) { |
|
82 | + if ($output->rawOutput) |
|
83 | + { |
|
80 | 84 | $source->push(sprintf('<?php echo %s; ?>', trim($output->body)), $output->getContext()); |
81 | 85 | return; |
82 | 86 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | Result $result, |
33 | 33 | NodeInterface $node |
34 | 34 | ): bool { |
35 | - switch (true) { |
|
35 | + switch (true){ |
|
36 | 36 | case $node instanceof Hidden: |
37 | 37 | return true; |
38 | 38 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $result->withinContext( |
41 | 41 | $node->getContext(), |
42 | 42 | function (Result $source) use ($node, $compiler): void { |
43 | - foreach ($node->nodes as $child) { |
|
43 | + foreach ($node->nodes as $child){ |
|
44 | 44 | $compiler->compile($child, $source); |
45 | 45 | } |
46 | 46 | } |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | $result->withinContext( |
53 | 53 | $node->getContext(), |
54 | 54 | function (Result $source) use ($node, $compiler): void { |
55 | - foreach ($node->nodes as $child) { |
|
56 | - if (is_string($child)) { |
|
55 | + foreach ($node->nodes as $child){ |
|
56 | + if (is_string($child)){ |
|
57 | 57 | $source->push($child, null); |
58 | 58 | continue; |
59 | 59 | } |
@@ -32,7 +32,8 @@ discard block |
||
32 | 32 | Result $result, |
33 | 33 | NodeInterface $node |
34 | 34 | ): bool { |
35 | - switch (true) { |
|
35 | + switch (true) |
|
36 | + { |
|
36 | 37 | case $node instanceof Hidden: |
37 | 38 | return true; |
38 | 39 | |
@@ -40,7 +41,8 @@ discard block |
||
40 | 41 | $result->withinContext( |
41 | 42 | $node->getContext(), |
42 | 43 | function (Result $source) use ($node, $compiler): void { |
43 | - foreach ($node->nodes as $child) { |
|
44 | + foreach ($node->nodes as $child) |
|
45 | + { |
|
44 | 46 | $compiler->compile($child, $source); |
45 | 47 | } |
46 | 48 | } |
@@ -52,8 +54,10 @@ discard block |
||
52 | 54 | $result->withinContext( |
53 | 55 | $node->getContext(), |
54 | 56 | function (Result $source) use ($node, $compiler): void { |
55 | - foreach ($node->nodes as $child) { |
|
56 | - if (is_string($child)) { |
|
57 | + foreach ($node->nodes as $child) |
|
58 | + { |
|
59 | + if (is_string($child)) |
|
60 | + { |
|
57 | 61 | $source->push($child, null); |
58 | 62 | continue; |
59 | 63 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | */ |
25 | 25 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
26 | 26 | { |
27 | - if ($node instanceof PHP) { |
|
27 | + if ($node instanceof PHP){ |
|
28 | 28 | $result->push($node->content, $node->getContext()); |
29 | 29 | return true; |
30 | 30 | } |
@@ -24,7 +24,8 @@ |
||
24 | 24 | */ |
25 | 25 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
26 | 26 | { |
27 | - if ($node instanceof PHP) { |
|
27 | + if ($node instanceof PHP) |
|
28 | + { |
|
28 | 29 | $result->push($node->content, $node->getContext()); |
29 | 30 | return true; |
30 | 31 | } |
@@ -37,16 +37,16 @@ |
||
37 | 37 | { |
38 | 38 | $result ??= new Result(); |
39 | 39 | |
40 | - if (is_array($node)) { |
|
41 | - foreach ($node as $child) { |
|
40 | + if (is_array($node)){ |
|
41 | + foreach ($node as $child){ |
|
42 | 42 | $this->compile($child, $result); |
43 | 43 | } |
44 | 44 | |
45 | 45 | return $result; |
46 | 46 | } |
47 | 47 | |
48 | - foreach ($this->renders as $renderer) { |
|
49 | - if ($renderer->render($this, $result, $node)) { |
|
48 | + foreach ($this->renders as $renderer){ |
|
49 | + if ($renderer->render($this, $result, $node)){ |
|
50 | 50 | return $result; |
51 | 51 | } |
52 | 52 | } |
@@ -37,16 +37,20 @@ |
||
37 | 37 | { |
38 | 38 | $result ??= new Result(); |
39 | 39 | |
40 | - if (is_array($node)) { |
|
41 | - foreach ($node as $child) { |
|
40 | + if (is_array($node)) |
|
41 | + { |
|
42 | + foreach ($node as $child) |
|
43 | + { |
|
42 | 44 | $this->compile($child, $result); |
43 | 45 | } |
44 | 46 | |
45 | 47 | return $result; |
46 | 48 | } |
47 | 49 | |
48 | - foreach ($this->renders as $renderer) { |
|
49 | - if ($renderer->render($this, $result, $node)) { |
|
50 | + foreach ($this->renders as $renderer) |
|
51 | + { |
|
52 | + if ($renderer->render($this, $result, $node)) |
|
53 | + { |
|
50 | 54 | return $result; |
51 | 55 | } |
52 | 56 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function enterNode($node, VisitorContext $ctx) |
49 | 49 | { |
50 | - if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0) { |
|
50 | + if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0){ |
|
51 | 51 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
52 | 52 | } |
53 | 53 | |
@@ -59,23 +59,23 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function leaveNode($node, VisitorContext $ctx) |
61 | 61 | { |
62 | - if (!$node instanceof Tag) { |
|
62 | + if (!$node instanceof Tag){ |
|
63 | 63 | return null; |
64 | 64 | } |
65 | 65 | |
66 | 66 | $importCtx = ImportContext::on($ctx); |
67 | 67 | |
68 | 68 | // import definition |
69 | - if (\strpos($node->name, $this->useKeyword) === 0) { |
|
69 | + if (\strpos($node->name, $this->useKeyword) === 0){ |
|
70 | 70 | $importCtx->add($this->makeImport($node)); |
71 | 71 | |
72 | 72 | return self::REMOVE_NODE; |
73 | 73 | } |
74 | 74 | |
75 | 75 | // imported tag |
76 | - try { |
|
76 | + try{ |
|
77 | 77 | $import = $importCtx->resolve($this->builder, $node->name); |
78 | - } catch (Throwable $e) { |
|
78 | + }catch (Throwable $e){ |
|
79 | 79 | throw new ImportException( |
80 | 80 | "Unable to resolve import `{$node->name}`", |
81 | 81 | $node->getContext(), |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | ); |
84 | 84 | } |
85 | 85 | |
86 | - if ($import !== null) { |
|
86 | + if ($import !== null){ |
|
87 | 87 | $node = $this->merger->merge($import, $node); |
88 | 88 | |
89 | 89 | return $this->merger->isolateNodes($node, $import->getContext()->getPath()); |
@@ -100,14 +100,14 @@ discard block |
||
100 | 100 | private function makeImport(Tag $tag): ImportInterface |
101 | 101 | { |
102 | 102 | $options = []; |
103 | - foreach ($tag->attrs as $attr) { |
|
104 | - if (!\is_string($attr->value) || !\is_string($attr->name)) { |
|
103 | + foreach ($tag->attrs as $attr){ |
|
104 | + if (!\is_string($attr->value) || !\is_string($attr->name)){ |
|
105 | 105 | continue; |
106 | 106 | } |
107 | 107 | $options[$attr->name] = trim($attr->value, '\'"'); |
108 | 108 | } |
109 | 109 | |
110 | - switch (\strtolower($tag->name)) { |
|
110 | + switch (\strtolower($tag->name)){ |
|
111 | 111 | case 'use': |
112 | 112 | case 'use:element': |
113 | 113 | $this->assertHasOption('path', $options, $tag); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | private function assertHasOption(string $option, array $options, Tag $tag): void |
155 | 155 | { |
156 | - if (!isset($options[$option])) { |
|
156 | + if (!isset($options[$option])){ |
|
157 | 157 | throw new ImportException("Missing `{$option}` option", $tag->getContext()); |
158 | 158 | } |
159 | 159 | } |
@@ -47,7 +47,8 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function enterNode($node, VisitorContext $ctx) |
49 | 49 | { |
50 | - if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0) { |
|
50 | + if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0) |
|
51 | + { |
|
51 | 52 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
52 | 53 | } |
53 | 54 | |
@@ -59,23 +60,28 @@ discard block |
||
59 | 60 | */ |
60 | 61 | public function leaveNode($node, VisitorContext $ctx) |
61 | 62 | { |
62 | - if (!$node instanceof Tag) { |
|
63 | + if (!$node instanceof Tag) |
|
64 | + { |
|
63 | 65 | return null; |
64 | 66 | } |
65 | 67 | |
66 | 68 | $importCtx = ImportContext::on($ctx); |
67 | 69 | |
68 | 70 | // import definition |
69 | - if (\strpos($node->name, $this->useKeyword) === 0) { |
|
71 | + if (\strpos($node->name, $this->useKeyword) === 0) |
|
72 | + { |
|
70 | 73 | $importCtx->add($this->makeImport($node)); |
71 | 74 | |
72 | 75 | return self::REMOVE_NODE; |
73 | 76 | } |
74 | 77 | |
75 | 78 | // imported tag |
76 | - try { |
|
79 | + try |
|
80 | + { |
|
77 | 81 | $import = $importCtx->resolve($this->builder, $node->name); |
78 | - } catch (Throwable $e) { |
|
82 | + } |
|
83 | + catch (Throwable $e) |
|
84 | + { |
|
79 | 85 | throw new ImportException( |
80 | 86 | "Unable to resolve import `{$node->name}`", |
81 | 87 | $node->getContext(), |
@@ -83,7 +89,8 @@ discard block |
||
83 | 89 | ); |
84 | 90 | } |
85 | 91 | |
86 | - if ($import !== null) { |
|
92 | + if ($import !== null) |
|
93 | + { |
|
87 | 94 | $node = $this->merger->merge($import, $node); |
88 | 95 | |
89 | 96 | return $this->merger->isolateNodes($node, $import->getContext()->getPath()); |
@@ -100,14 +107,17 @@ discard block |
||
100 | 107 | private function makeImport(Tag $tag): ImportInterface |
101 | 108 | { |
102 | 109 | $options = []; |
103 | - foreach ($tag->attrs as $attr) { |
|
104 | - if (!\is_string($attr->value) || !\is_string($attr->name)) { |
|
110 | + foreach ($tag->attrs as $attr) |
|
111 | + { |
|
112 | + if (!\is_string($attr->value) || !\is_string($attr->name)) |
|
113 | + { |
|
105 | 114 | continue; |
106 | 115 | } |
107 | 116 | $options[$attr->name] = trim($attr->value, '\'"'); |
108 | 117 | } |
109 | 118 | |
110 | - switch (\strtolower($tag->name)) { |
|
119 | + switch (\strtolower($tag->name)) |
|
120 | + { |
|
111 | 121 | case 'use': |
112 | 122 | case 'use:element': |
113 | 123 | $this->assertHasOption('path', $options, $tag); |
@@ -153,7 +163,8 @@ discard block |
||
153 | 163 | |
154 | 164 | private function assertHasOption(string $option, array $options, Tag $tag): void |
155 | 165 | { |
156 | - if (!isset($options[$option])) { |
|
166 | + if (!isset($options[$option])) |
|
167 | + { |
|
157 | 168 | throw new ImportException("Missing `{$option}` option", $tag->getContext()); |
158 | 169 | } |
159 | 170 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function enterNode($node, VisitorContext $ctx) |
47 | 47 | { |
48 | - if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0) { |
|
48 | + if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0){ |
|
49 | 49 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
50 | 50 | } |
51 | 51 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function leaveNode($node, VisitorContext $ctx) |
59 | 59 | { |
60 | - if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0) { |
|
60 | + if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0){ |
|
61 | 61 | $parent = $ctx->getParentNode(); |
62 | - if (!$parent instanceof AttributedInterface) { |
|
62 | + if (!$parent instanceof AttributedInterface){ |
|
63 | 63 | throw new LogicException(sprintf( |
64 | 64 | 'Unable to extend non attributable node (%s)', |
65 | 65 | is_object($node) ? get_class($node) : gettype($node) |
@@ -72,20 +72,20 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | // extend current node |
75 | - if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null) { |
|
75 | + if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null){ |
|
76 | 76 | /** @var Tag $extends */ |
77 | 77 | $extends = $node->getAttribute(self::class); |
78 | 78 | |
79 | - foreach ($node->nodes as $child) { |
|
79 | + foreach ($node->nodes as $child){ |
|
80 | 80 | $extends->nodes[] = $child; |
81 | 81 | } |
82 | 82 | |
83 | 83 | $path = 'undefined'; |
84 | - try { |
|
84 | + try{ |
|
85 | 85 | $path = $this->getPath($extends); |
86 | 86 | |
87 | 87 | return $this->merger->merge($this->builder->load($path), $extends); |
88 | - } catch (Throwable $e) { |
|
88 | + }catch (Throwable $e){ |
|
89 | 89 | throw new ExtendsException( |
90 | 90 | "Unable to extend parent `{$path}`", |
91 | 91 | $extends->getContext(), |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | |
100 | 100 | private function getPath(Tag $tag): string |
101 | 101 | { |
102 | - if (strpos($tag->name, $this->extendsKeyword . ':') === 0) { |
|
102 | + if (strpos($tag->name, $this->extendsKeyword.':') === 0){ |
|
103 | 103 | $name = substr($tag->name, strlen($this->extendsKeyword) + 1); |
104 | 104 | |
105 | 105 | return str_replace(['.'], DIRECTORY_SEPARATOR, $name); |
106 | 106 | } |
107 | 107 | |
108 | - foreach ($tag->attrs as $attr) { |
|
109 | - if ($attr->name === 'path' && is_string($attr->value)) { |
|
108 | + foreach ($tag->attrs as $attr){ |
|
109 | + if ($attr->name === 'path' && is_string($attr->value)){ |
|
110 | 110 | return trim($attr->value, '\'"'); |
111 | 111 | } |
112 | 112 | } |
@@ -45,7 +45,8 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function enterNode($node, VisitorContext $ctx) |
47 | 47 | { |
48 | - if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0) { |
|
48 | + if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0) |
|
49 | + { |
|
49 | 50 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
50 | 51 | } |
51 | 52 | |
@@ -57,9 +58,11 @@ discard block |
||
57 | 58 | */ |
58 | 59 | public function leaveNode($node, VisitorContext $ctx) |
59 | 60 | { |
60 | - if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0) { |
|
61 | + if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0) |
|
62 | + { |
|
61 | 63 | $parent = $ctx->getParentNode(); |
62 | - if (!$parent instanceof AttributedInterface) { |
|
64 | + if (!$parent instanceof AttributedInterface) |
|
65 | + { |
|
63 | 66 | throw new LogicException(sprintf( |
64 | 67 | 'Unable to extend non attributable node (%s)', |
65 | 68 | is_object($node) ? get_class($node) : gettype($node) |
@@ -72,20 +75,25 @@ discard block |
||
72 | 75 | } |
73 | 76 | |
74 | 77 | // extend current node |
75 | - if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null) { |
|
78 | + if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null) |
|
79 | + { |
|
76 | 80 | /** @var Tag $extends */ |
77 | 81 | $extends = $node->getAttribute(self::class); |
78 | 82 | |
79 | - foreach ($node->nodes as $child) { |
|
83 | + foreach ($node->nodes as $child) |
|
84 | + { |
|
80 | 85 | $extends->nodes[] = $child; |
81 | 86 | } |
82 | 87 | |
83 | 88 | $path = 'undefined'; |
84 | - try { |
|
89 | + try |
|
90 | + { |
|
85 | 91 | $path = $this->getPath($extends); |
86 | 92 | |
87 | 93 | return $this->merger->merge($this->builder->load($path), $extends); |
88 | - } catch (Throwable $e) { |
|
94 | + } |
|
95 | + catch (Throwable $e) |
|
96 | + { |
|
89 | 97 | throw new ExtendsException( |
90 | 98 | "Unable to extend parent `{$path}`", |
91 | 99 | $extends->getContext(), |
@@ -99,14 +107,17 @@ discard block |
||
99 | 107 | |
100 | 108 | private function getPath(Tag $tag): string |
101 | 109 | { |
102 | - if (strpos($tag->name, $this->extendsKeyword . ':') === 0) { |
|
110 | + if (strpos($tag->name, $this->extendsKeyword . ':') === 0) |
|
111 | + { |
|
103 | 112 | $name = substr($tag->name, strlen($this->extendsKeyword) + 1); |
104 | 113 | |
105 | 114 | return str_replace(['.'], DIRECTORY_SEPARATOR, $name); |
106 | 115 | } |
107 | 116 | |
108 | - foreach ($tag->attrs as $attr) { |
|
109 | - if ($attr->name === 'path' && is_string($attr->value)) { |
|
117 | + foreach ($tag->attrs as $attr) |
|
118 | + { |
|
119 | + if ($attr->name === 'path' && is_string($attr->value)) |
|
120 | + { |
|
110 | 121 | return trim($attr->value, '\'"'); |
111 | 122 | } |
112 | 123 | } |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function enterNode($node, VisitorContext $ctx) |
34 | 34 | { |
35 | - if ($node instanceof Tag) { |
|
35 | + if ($node instanceof Tag){ |
|
36 | 36 | return $this->makeBlock($node); |
37 | 37 | } |
38 | 38 | |
39 | - if ($node instanceof Inline) { |
|
39 | + if ($node instanceof Inline){ |
|
40 | 40 | $block = new Block($node->name, $node->getContext()); |
41 | - if ($node->value !== null) { |
|
41 | + if ($node->value !== null){ |
|
42 | 42 | $block->nodes[] = new Raw($node->value); |
43 | 43 | } |
44 | 44 | |
@@ -61,14 +61,14 @@ discard block |
||
61 | 61 | private function makeBlock(Tag $node): ?NodeInterface |
62 | 62 | { |
63 | 63 | $name = null; |
64 | - foreach ($this->prefix as $prefix) { |
|
65 | - if (strpos($node->name, (string) $prefix) === 0) { |
|
64 | + foreach ($this->prefix as $prefix){ |
|
65 | + if (strpos($node->name, (string)$prefix) === 0){ |
|
66 | 66 | $name = substr($node->name, strlen($prefix)); |
67 | 67 | break; |
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | - if ($name === null) { |
|
71 | + if ($name === null){ |
|
72 | 72 | return null; |
73 | 73 | } |
74 | 74 |
@@ -32,13 +32,16 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function enterNode($node, VisitorContext $ctx) |
34 | 34 | { |
35 | - if ($node instanceof Tag) { |
|
35 | + if ($node instanceof Tag) |
|
36 | + { |
|
36 | 37 | return $this->makeBlock($node); |
37 | 38 | } |
38 | 39 | |
39 | - if ($node instanceof Inline) { |
|
40 | + if ($node instanceof Inline) |
|
41 | + { |
|
40 | 42 | $block = new Block($node->name, $node->getContext()); |
41 | - if ($node->value !== null) { |
|
43 | + if ($node->value !== null) |
|
44 | + { |
|
42 | 45 | $block->nodes[] = new Raw($node->value); |
43 | 46 | } |
44 | 47 | |
@@ -61,14 +64,17 @@ discard block |
||
61 | 64 | private function makeBlock(Tag $node): ?NodeInterface |
62 | 65 | { |
63 | 66 | $name = null; |
64 | - foreach ($this->prefix as $prefix) { |
|
65 | - if (strpos($node->name, (string) $prefix) === 0) { |
|
67 | + foreach ($this->prefix as $prefix) |
|
68 | + { |
|
69 | + if (strpos($node->name, (string) $prefix) === 0) |
|
70 | + { |
|
66 | 71 | $name = substr($node->name, strlen($prefix)); |
67 | 72 | break; |
68 | 73 | } |
69 | 74 | } |
70 | 75 | |
71 | - if ($name === null) { |
|
76 | + if ($name === null) |
|
77 | + { |
|
72 | 78 | return null; |
73 | 79 | } |
74 | 80 |
@@ -41,17 +41,17 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function push(string $name, Tag $child, string $uniqueID = null): bool |
43 | 43 | { |
44 | - foreach ($this->getStacks() as $stack) { |
|
45 | - if ($stack->accepts($name) !== $name) { |
|
44 | + foreach ($this->getStacks() as $stack){ |
|
45 | + if ($stack->accepts($name) !== $name){ |
|
46 | 46 | continue; |
47 | 47 | } |
48 | 48 | |
49 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
49 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){ |
|
50 | 50 | return true; |
51 | 51 | } |
52 | 52 | $stack->uniqueIDs[$uniqueID] = true; |
53 | 53 | |
54 | - foreach ($child->nodes as $child) { |
|
54 | + foreach ($child->nodes as $child){ |
|
55 | 55 | $stack->nodes[] = $child; |
56 | 56 | } |
57 | 57 | |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function prepend(string $name, Tag $child, string $uniqueID = null): bool |
68 | 68 | { |
69 | - foreach ($this->getStacks() as $stack) { |
|
70 | - if ($stack->accepts($name) !== $name) { |
|
69 | + foreach ($this->getStacks() as $stack){ |
|
70 | + if ($stack->accepts($name) !== $name){ |
|
71 | 71 | continue; |
72 | 72 | } |
73 | 73 | |
74 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
74 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){ |
|
75 | 75 | return true; |
76 | 76 | } |
77 | 77 | $stack->uniqueIDs[$uniqueID] = true; |
78 | 78 | |
79 | - foreach ($child->nodes as $child) { |
|
79 | + foreach ($child->nodes as $child){ |
|
80 | 80 | array_unshift($stack->nodes, $child); |
81 | 81 | } |
82 | 82 | |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | public function getStacks(): array |
95 | 95 | { |
96 | 96 | $stacks = []; |
97 | - foreach (array_reverse($this->ctx->getScope()) as $node) { |
|
98 | - if ($node instanceof AttributedInterface) { |
|
99 | - foreach ($node->getAttribute(self::class, []) as $stack) { |
|
97 | + foreach (array_reverse($this->ctx->getScope()) as $node){ |
|
98 | + if ($node instanceof AttributedInterface){ |
|
99 | + foreach ($node->getAttribute(self::class, []) as $stack){ |
|
100 | 100 | $stacks[] = $stack; |
101 | 101 | } |
102 | 102 | } |
@@ -112,16 +112,16 @@ discard block |
||
112 | 112 | |
113 | 113 | private function getStackRootNode(int $level): AttributedInterface |
114 | 114 | { |
115 | - if ($level === 0) { |
|
115 | + if ($level === 0){ |
|
116 | 116 | $node = $this->ctx->getParentNode(); |
117 | - } else { |
|
117 | + }else{ |
|
118 | 118 | $scope = $this->ctx->getScope(); |
119 | 119 | |
120 | 120 | // looking for the parent node via given nesting level |
121 | 121 | $node = $scope[count($scope) - 2 - $level] ?? $this->ctx->getFirstNode(); |
122 | 122 | } |
123 | 123 | |
124 | - if (!$node instanceof AttributedInterface) { |
|
124 | + if (!$node instanceof AttributedInterface){ |
|
125 | 125 | throw new LogicException( |
126 | 126 | sprintf( |
127 | 127 | 'Unable to create import on node without attribute storage (%s)', |
@@ -41,17 +41,21 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function push(string $name, Tag $child, string $uniqueID = null): bool |
43 | 43 | { |
44 | - foreach ($this->getStacks() as $stack) { |
|
45 | - if ($stack->accepts($name) !== $name) { |
|
44 | + foreach ($this->getStacks() as $stack) |
|
45 | + { |
|
46 | + if ($stack->accepts($name) !== $name) |
|
47 | + { |
|
46 | 48 | continue; |
47 | 49 | } |
48 | 50 | |
49 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
51 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) |
|
52 | + { |
|
50 | 53 | return true; |
51 | 54 | } |
52 | 55 | $stack->uniqueIDs[$uniqueID] = true; |
53 | 56 | |
54 | - foreach ($child->nodes as $child) { |
|
57 | + foreach ($child->nodes as $child) |
|
58 | + { |
|
55 | 59 | $stack->nodes[] = $child; |
56 | 60 | } |
57 | 61 | |
@@ -66,17 +70,21 @@ discard block |
||
66 | 70 | */ |
67 | 71 | public function prepend(string $name, Tag $child, string $uniqueID = null): bool |
68 | 72 | { |
69 | - foreach ($this->getStacks() as $stack) { |
|
70 | - if ($stack->accepts($name) !== $name) { |
|
73 | + foreach ($this->getStacks() as $stack) |
|
74 | + { |
|
75 | + if ($stack->accepts($name) !== $name) |
|
76 | + { |
|
71 | 77 | continue; |
72 | 78 | } |
73 | 79 | |
74 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
80 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) |
|
81 | + { |
|
75 | 82 | return true; |
76 | 83 | } |
77 | 84 | $stack->uniqueIDs[$uniqueID] = true; |
78 | 85 | |
79 | - foreach ($child->nodes as $child) { |
|
86 | + foreach ($child->nodes as $child) |
|
87 | + { |
|
80 | 88 | array_unshift($stack->nodes, $child); |
81 | 89 | } |
82 | 90 | |
@@ -94,9 +102,12 @@ discard block |
||
94 | 102 | public function getStacks(): array |
95 | 103 | { |
96 | 104 | $stacks = []; |
97 | - foreach (array_reverse($this->ctx->getScope()) as $node) { |
|
98 | - if ($node instanceof AttributedInterface) { |
|
99 | - foreach ($node->getAttribute(self::class, []) as $stack) { |
|
105 | + foreach (array_reverse($this->ctx->getScope()) as $node) |
|
106 | + { |
|
107 | + if ($node instanceof AttributedInterface) |
|
108 | + { |
|
109 | + foreach ($node->getAttribute(self::class, []) as $stack) |
|
110 | + { |
|
100 | 111 | $stacks[] = $stack; |
101 | 112 | } |
102 | 113 | } |
@@ -112,16 +123,20 @@ discard block |
||
112 | 123 | |
113 | 124 | private function getStackRootNode(int $level): AttributedInterface |
114 | 125 | { |
115 | - if ($level === 0) { |
|
126 | + if ($level === 0) |
|
127 | + { |
|
116 | 128 | $node = $this->ctx->getParentNode(); |
117 | - } else { |
|
129 | + } |
|
130 | + else |
|
131 | + { |
|
118 | 132 | $scope = $this->ctx->getScope(); |
119 | 133 | |
120 | 134 | // looking for the parent node via given nesting level |
121 | 135 | $node = $scope[count($scope) - 2 - $level] ?? $this->ctx->getFirstNode(); |
122 | 136 | } |
123 | 137 | |
124 | - if (!$node instanceof AttributedInterface) { |
|
138 | + if (!$node instanceof AttributedInterface) |
|
139 | + { |
|
125 | 140 | throw new LogicException( |
126 | 141 | sprintf( |
127 | 142 | 'Unable to create import on node without attribute storage (%s)', |