@@ -20,15 +20,15 @@ |
||
20 | 20 | |
21 | 21 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
22 | 22 | { |
23 | - if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) { |
|
23 | + if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE){ |
|
24 | 24 | return null; |
25 | 25 | } |
26 | 26 | |
27 | - if ($node->value instanceof Nil) { |
|
27 | + if ($node->value instanceof Nil){ |
|
28 | 28 | return new Aggregate($node->getContext()); |
29 | 29 | } |
30 | 30 | |
31 | - if (!\is_string($node->value)) { |
|
31 | + if (!\is_string($node->value)){ |
|
32 | 32 | return null; |
33 | 33 | } |
34 | 34 |
@@ -20,15 +20,18 @@ |
||
20 | 20 | |
21 | 21 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
22 | 22 | { |
23 | - if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) { |
|
23 | + if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) |
|
24 | + { |
|
24 | 25 | return null; |
25 | 26 | } |
26 | 27 | |
27 | - if ($node->value instanceof Nil) { |
|
28 | + if ($node->value instanceof Nil) |
|
29 | + { |
|
28 | 30 | return new Aggregate($node->getContext()); |
29 | 31 | } |
30 | 32 | |
31 | - if (!\is_string($node->value)) { |
|
33 | + if (!\is_string($node->value)) |
|
34 | + { |
|
32 | 35 | return null; |
33 | 36 | } |
34 | 37 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
21 | 21 | { |
22 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)) { |
|
22 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)){ |
|
23 | 23 | return $this->registerAggregate(StackContext::on($ctx), $node); |
24 | 24 | } |
25 | 25 | |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | return null; |
32 | 32 | } |
33 | 33 | |
34 | - private function registerAggregate(StackContext $ctx, Tag $node): Aggregate|Tag |
|
34 | + private function registerAggregate(StackContext $ctx, Tag $node): Aggregate | Tag |
|
35 | 35 | { |
36 | 36 | $name = $this->stackName($node); |
37 | - if ($name === null) { |
|
37 | + if ($name === null){ |
|
38 | 38 | return $node; |
39 | 39 | } |
40 | 40 | |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | private function stackName(Tag $tag): ?string |
51 | 51 | { |
52 | 52 | $options = []; |
53 | - foreach ($tag->attrs as $attr) { |
|
54 | - if (\is_string($attr->value)) { |
|
53 | + foreach ($tag->attrs as $attr){ |
|
54 | + if (\is_string($attr->value)){ |
|
55 | 55 | $options[$attr->name] = \trim($attr->value, '\'"'); |
56 | 56 | } |
57 | 57 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | private function stackLevel(Tag $tag): int |
63 | 63 | { |
64 | 64 | $options = []; |
65 | - foreach ($tag->attrs as $attr) { |
|
66 | - if (\is_string($attr->value)) { |
|
65 | + foreach ($tag->attrs as $attr){ |
|
66 | + if (\is_string($attr->value)){ |
|
67 | 67 | $options[$attr->name] = \trim($attr->value, '\'"'); |
68 | 68 | } |
69 | 69 | } |
@@ -19,7 +19,8 @@ discard block |
||
19 | 19 | |
20 | 20 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
21 | 21 | { |
22 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)) { |
|
22 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)) |
|
23 | + { |
|
23 | 24 | return $this->registerAggregate(StackContext::on($ctx), $node); |
24 | 25 | } |
25 | 26 | |
@@ -34,7 +35,8 @@ discard block |
||
34 | 35 | private function registerAggregate(StackContext $ctx, Tag $node): Aggregate|Tag |
35 | 36 | { |
36 | 37 | $name = $this->stackName($node); |
37 | - if ($name === null) { |
|
38 | + if ($name === null) |
|
39 | + { |
|
38 | 40 | return $node; |
39 | 41 | } |
40 | 42 | |
@@ -50,8 +52,10 @@ discard block |
||
50 | 52 | private function stackName(Tag $tag): ?string |
51 | 53 | { |
52 | 54 | $options = []; |
53 | - foreach ($tag->attrs as $attr) { |
|
54 | - if (\is_string($attr->value)) { |
|
55 | + foreach ($tag->attrs as $attr) |
|
56 | + { |
|
57 | + if (\is_string($attr->value)) |
|
58 | + { |
|
55 | 59 | $options[$attr->name] = \trim($attr->value, '\'"'); |
56 | 60 | } |
57 | 61 | } |
@@ -62,8 +66,10 @@ discard block |
||
62 | 66 | private function stackLevel(Tag $tag): int |
63 | 67 | { |
64 | 68 | $options = []; |
65 | - foreach ($tag->attrs as $attr) { |
|
66 | - if (\is_string($attr->value)) { |
|
69 | + foreach ($tag->attrs as $attr) |
|
70 | + { |
|
71 | + if (\is_string($attr->value)) |
|
72 | + { |
|
67 | 73 | $options[$attr->name] = \trim($attr->value, '\'"'); |
68 | 74 | } |
69 | 75 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | |
22 | 22 | public function leaveNode(mixed $node, VisitorContext $ctx): ?Hidden |
23 | 23 | { |
24 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->hiddenKeyword)) { |
|
24 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->hiddenKeyword)){ |
|
25 | 25 | return new Hidden([$node]); |
26 | 26 | } |
27 | 27 |
@@ -21,7 +21,8 @@ |
||
21 | 21 | |
22 | 22 | public function leaveNode(mixed $node, VisitorContext $ctx): ?Hidden |
23 | 23 | { |
24 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->hiddenKeyword)) { |
|
24 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->hiddenKeyword)) |
|
25 | + { |
|
25 | 26 | return new Hidden([$node]); |
26 | 27 | } |
27 | 28 |
@@ -26,7 +26,8 @@ |
||
26 | 26 | |
27 | 27 | public function resolve(Builder $builder, string $name): ?Template |
28 | 28 | { |
29 | - if ($name !== $this->name) { |
|
29 | + if ($name !== $this->name) |
|
30 | + { |
|
30 | 31 | return null; |
31 | 32 | } |
32 | 33 |
@@ -20,13 +20,13 @@ |
||
20 | 20 | private readonly string $name, |
21 | 21 | private readonly array $nodes, |
22 | 22 | ?Context $context = null |
23 | - ) { |
|
23 | + ){ |
|
24 | 24 | $this->context = $context; |
25 | 25 | } |
26 | 26 | |
27 | 27 | public function resolve(Builder $builder, string $name): ?Template |
28 | 28 | { |
29 | - if ($name !== $this->name) { |
|
29 | + if ($name !== $this->name){ |
|
30 | 30 | return null; |
31 | 31 | } |
32 | 32 |
@@ -25,7 +25,8 @@ discard block |
||
25 | 25 | ) { |
26 | 26 | $this->alias = $alias ?? $path; |
27 | 27 | |
28 | - if ($alias === null && \strrpos($this->alias, '/') !== false) { |
|
28 | + if ($alias === null && \strrpos($this->alias, '/') !== false) |
|
29 | + { |
|
29 | 30 | $this->alias = \substr($this->alias, \strrpos($this->alias, '/') + 1); |
30 | 31 | } |
31 | 32 | |
@@ -44,7 +45,8 @@ discard block |
||
44 | 45 | |
45 | 46 | public function resolve(Builder $builder, string $name): ?Template |
46 | 47 | { |
47 | - if ($this->alias !== $name) { |
|
48 | + if ($this->alias !== $name) |
|
49 | + { |
|
48 | 50 | return null; |
49 | 51 | } |
50 | 52 |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | private string $path, |
23 | 23 | ?string $alias = null, |
24 | 24 | ?Context $context = null |
25 | - ) { |
|
25 | + ){ |
|
26 | 26 | $this->alias = $alias ?? $path; |
27 | 27 | |
28 | - if ($alias === null && \strrpos($this->alias, '/') !== false) { |
|
28 | + if ($alias === null && \strrpos($this->alias, '/') !== false){ |
|
29 | 29 | $this->alias = \substr($this->alias, \strrpos($this->alias, '/') + 1); |
30 | 30 | } |
31 | 31 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | public function resolve(Builder $builder, string $name): ?Template |
46 | 46 | { |
47 | - if ($this->alias !== $name) { |
|
47 | + if ($this->alias !== $name){ |
|
48 | 48 | return null; |
49 | 49 | } |
50 | 50 |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $parser->path = $path; |
44 | 44 | $parser->lexer = clone $this->lexer; |
45 | 45 | |
46 | - foreach ($parser->syntax as $grammar => $stx) { |
|
46 | + foreach ($parser->syntax as $grammar => $stx){ |
|
47 | 47 | $parser->syntax[$grammar] = clone $stx; |
48 | 48 | } |
49 | 49 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | { |
72 | 72 | $template = new Template(); |
73 | 73 | |
74 | - try { |
|
74 | + try{ |
|
75 | 75 | /** |
76 | 76 | * TODO issue #767 |
77 | 77 | * @link https://github.com/spiral/framework/issues/767 |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | new Assembler($template, 'nodes'), |
82 | 82 | $this->lexer->parse($stream) |
83 | 83 | ); |
84 | - } catch (SyntaxException $e) { |
|
84 | + }catch (SyntaxException $e){ |
|
85 | 85 | throw new ParserException( |
86 | 86 | $e->getMessage(), |
87 | 87 | new Context($e->getToken(), $this->getPath()), |
@@ -100,21 +100,21 @@ discard block |
||
100 | 100 | $node = $asm->getNode(); |
101 | 101 | |
102 | 102 | $syntax = []; |
103 | - foreach ($this->syntax as $grammar => $stx) { |
|
103 | + foreach ($this->syntax as $grammar => $stx){ |
|
104 | 104 | $syntax[$grammar] = clone $stx; |
105 | 105 | } |
106 | 106 | |
107 | - foreach ($tokens as $token) { |
|
108 | - if (!isset($syntax[$token->grammar])) { |
|
107 | + foreach ($tokens as $token){ |
|
108 | + if (!isset($syntax[$token->grammar])){ |
|
109 | 109 | throw new SyntaxException('Undefined token', $token); |
110 | 110 | } |
111 | 111 | |
112 | 112 | $syntax[$token->grammar]->handle($this, $asm, $token); |
113 | 113 | } |
114 | 114 | |
115 | - if ($asm->getNode() !== $node) { |
|
115 | + if ($asm->getNode() !== $node){ |
|
116 | 116 | throw new SyntaxException( |
117 | - 'Invalid node hierarchy, unclosed ' . $asm->getStackPath(), |
|
117 | + 'Invalid node hierarchy, unclosed '.$asm->getStackPath(), |
|
118 | 118 | $asm->getNode()->getContext()->getToken() |
119 | 119 | ); |
120 | 120 | } |
@@ -43,7 +43,8 @@ discard block |
||
43 | 43 | $parser->path = $path; |
44 | 44 | $parser->lexer = clone $this->lexer; |
45 | 45 | |
46 | - foreach ($parser->syntax as $grammar => $stx) { |
|
46 | + foreach ($parser->syntax as $grammar => $stx) |
|
47 | + { |
|
47 | 48 | $parser->syntax[$grammar] = clone $stx; |
48 | 49 | } |
49 | 50 | |
@@ -71,7 +72,8 @@ discard block |
||
71 | 72 | { |
72 | 73 | $template = new Template(); |
73 | 74 | |
74 | - try { |
|
75 | + try |
|
76 | + { |
|
75 | 77 | /** |
76 | 78 | * TODO issue #767 |
77 | 79 | * @link https://github.com/spiral/framework/issues/767 |
@@ -81,7 +83,9 @@ discard block |
||
81 | 83 | new Assembler($template, 'nodes'), |
82 | 84 | $this->lexer->parse($stream) |
83 | 85 | ); |
84 | - } catch (SyntaxException $e) { |
|
86 | + } |
|
87 | + catch (SyntaxException $e) |
|
88 | + { |
|
85 | 89 | throw new ParserException( |
86 | 90 | $e->getMessage(), |
87 | 91 | new Context($e->getToken(), $this->getPath()), |
@@ -100,19 +104,23 @@ discard block |
||
100 | 104 | $node = $asm->getNode(); |
101 | 105 | |
102 | 106 | $syntax = []; |
103 | - foreach ($this->syntax as $grammar => $stx) { |
|
107 | + foreach ($this->syntax as $grammar => $stx) |
|
108 | + { |
|
104 | 109 | $syntax[$grammar] = clone $stx; |
105 | 110 | } |
106 | 111 | |
107 | - foreach ($tokens as $token) { |
|
108 | - if (!isset($syntax[$token->grammar])) { |
|
112 | + foreach ($tokens as $token) |
|
113 | + { |
|
114 | + if (!isset($syntax[$token->grammar])) |
|
115 | + { |
|
109 | 116 | throw new SyntaxException('Undefined token', $token); |
110 | 117 | } |
111 | 118 | |
112 | 119 | $syntax[$token->grammar]->handle($this, $asm, $token); |
113 | 120 | } |
114 | 121 | |
115 | - if ($asm->getNode() !== $node) { |
|
122 | + if ($asm->getNode() !== $node) |
|
123 | + { |
|
116 | 124 | throw new SyntaxException( |
117 | 125 | 'Invalid node hierarchy, unclosed ' . $asm->getStackPath(), |
118 | 126 | $asm->getNode()->getContext()->getToken() |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | public function renderCase(Directive $directive): string |
74 | 74 | { |
75 | - if ($this->firstSwitchCase) { |
|
75 | + if ($this->firstSwitchCase){ |
|
76 | 76 | $this->firstSwitchCase = false; |
77 | 77 | |
78 | 78 | return \sprintf('case (%s): ?>', $directive->body); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | public function renderDefault(Directive $directive): string |
85 | 85 | { |
86 | - if ($this->firstSwitchCase) { |
|
86 | + if ($this->firstSwitchCase){ |
|
87 | 87 | $this->firstSwitchCase = false; |
88 | 88 | |
89 | 89 | return 'default: ?>'; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | public function renderBreak(Directive $directive): string |
101 | 101 | { |
102 | - if (isset($directive->values[0])) { |
|
102 | + if (isset($directive->values[0])){ |
|
103 | 103 | return \sprintf('<?php break %s; ?>', $directive->values[0]); |
104 | 104 | } |
105 | 105 |
@@ -72,7 +72,8 @@ discard block |
||
72 | 72 | |
73 | 73 | public function renderCase(Directive $directive): string |
74 | 74 | { |
75 | - if ($this->firstSwitchCase) { |
|
75 | + if ($this->firstSwitchCase) |
|
76 | + { |
|
76 | 77 | $this->firstSwitchCase = false; |
77 | 78 | |
78 | 79 | return \sprintf('case (%s): ?>', $directive->body); |
@@ -83,7 +84,8 @@ discard block |
||
83 | 84 | |
84 | 85 | public function renderDefault(Directive $directive): string |
85 | 86 | { |
86 | - if ($this->firstSwitchCase) { |
|
87 | + if ($this->firstSwitchCase) |
|
88 | + { |
|
87 | 89 | $this->firstSwitchCase = false; |
88 | 90 | |
89 | 91 | return 'default: ?>'; |
@@ -99,7 +101,8 @@ discard block |
||
99 | 101 | |
100 | 102 | public function renderBreak(Directive $directive): string |
101 | 103 | { |
102 | - if (isset($directive->values[0])) { |
|
104 | + if (isset($directive->values[0])) |
|
105 | + { |
|
103 | 106 | return \sprintf('<?php break %s; ?>', $directive->values[0]); |
104 | 107 | } |
105 | 108 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | public function renderBreak(Directive $directive): string |
35 | 35 | { |
36 | - if (isset($directive->values[0])) { |
|
36 | + if (isset($directive->values[0])){ |
|
37 | 37 | return \sprintf('<?php break %s; ?>', $directive->values[0]); |
38 | 38 | } |
39 | 39 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | public function renderContinue(Directive $directive): string |
44 | 44 | { |
45 | - if (isset($directive->values[0])) { |
|
45 | + if (isset($directive->values[0])){ |
|
46 | 46 | return \sprintf('<?php continue %s; ?>', $directive->values[0]); |
47 | 47 | } |
48 | 48 |
@@ -33,7 +33,8 @@ discard block |
||
33 | 33 | |
34 | 34 | public function renderBreak(Directive $directive): string |
35 | 35 | { |
36 | - if (isset($directive->values[0])) { |
|
36 | + if (isset($directive->values[0])) |
|
37 | + { |
|
37 | 38 | return \sprintf('<?php break %s; ?>', $directive->values[0]); |
38 | 39 | } |
39 | 40 | |
@@ -42,7 +43,8 @@ discard block |
||
42 | 43 | |
43 | 44 | public function renderContinue(Directive $directive): string |
44 | 45 | { |
45 | - if (isset($directive->values[0])) { |
|
46 | + if (isset($directive->values[0])) |
|
47 | + { |
|
46 | 48 | return \sprintf('<?php continue %s; ?>', $directive->values[0]); |
47 | 49 | } |
48 | 50 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | public ?int $offset, |
17 | 17 | public string $content, |
18 | 18 | public ?string $grammar = null |
19 | - ) { |
|
19 | + ){ |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | 'content' => $this->content, |
33 | 33 | ]; |
34 | 34 | |
35 | - if ($this->grammar !== null) { |
|
35 | + if ($this->grammar !== null){ |
|
36 | 36 | $token['type'] = \call_user_func([$this->grammar, 'tokenName'], $this->type); |
37 | 37 | } |
38 | 38 | |
39 | - if ($this->tokens !== []) { |
|
39 | + if ($this->tokens !== []){ |
|
40 | 40 | $token['tokens'] = $this->tokens; |
41 | 41 | } |
42 | 42 |
@@ -32,11 +32,13 @@ |
||
32 | 32 | 'content' => $this->content, |
33 | 33 | ]; |
34 | 34 | |
35 | - if ($this->grammar !== null) { |
|
35 | + if ($this->grammar !== null) |
|
36 | + { |
|
36 | 37 | $token['type'] = \call_user_func([$this->grammar, 'tokenName'], $this->type); |
37 | 38 | } |
38 | 39 | |
39 | - if ($this->tokens !== []) { |
|
40 | + if ($this->tokens !== []) |
|
41 | + { |
|
40 | 42 | $token['tokens'] = $this->tokens; |
41 | 43 | } |
42 | 44 |