@@ -69,7 +69,7 @@ |
||
69 | 69 | protected function traverse(array $nodes, VisitorInterface ...$visitors): array |
70 | 70 | { |
71 | 71 | $traverser = new Traverser(); |
72 | - foreach ($visitors as $visitor) { |
|
72 | + foreach ($visitors as $visitor){ |
|
73 | 73 | $traverser->addVisitor($visitor); |
74 | 74 | } |
75 | 75 |
@@ -69,7 +69,8 @@ |
||
69 | 69 | protected function traverse(array $nodes, VisitorInterface ...$visitors): array |
70 | 70 | { |
71 | 71 | $traverser = new Traverser(); |
72 | - foreach ($visitors as $visitor) { |
|
72 | + foreach ($visitors as $visitor) |
|
73 | + { |
|
73 | 74 | $traverser->addVisitor($visitor); |
74 | 75 | } |
75 | 76 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | { |
14 | 14 | private function __construct( |
15 | 15 | private readonly VisitorContext $ctx |
16 | - ) { |
|
16 | + ){ |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function register(Aggregate $aggregate, int $level = 0): void |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | |
29 | 29 | public function push(string $name, Tag $child, string $uniqueID = null): bool |
30 | 30 | { |
31 | - foreach ($this->getStacks() as $stack) { |
|
32 | - if ($stack->accepts($name) !== $name) { |
|
31 | + foreach ($this->getStacks() as $stack){ |
|
32 | + if ($stack->accepts($name) !== $name){ |
|
33 | 33 | continue; |
34 | 34 | } |
35 | 35 | |
36 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
36 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){ |
|
37 | 37 | return true; |
38 | 38 | } |
39 | 39 | $stack->uniqueIDs[$uniqueID] = true; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @link https://github.com/spiral/framework/issues/767 |
44 | 44 | * @psalm-suppress NoInterfaceProperties |
45 | 45 | */ |
46 | - foreach ($child->nodes as $child) { |
|
46 | + foreach ($child->nodes as $child){ |
|
47 | 47 | $stack->nodes[] = $child; |
48 | 48 | } |
49 | 49 | |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | |
56 | 56 | public function prepend(string $name, Tag $child, string $uniqueID = null): bool |
57 | 57 | { |
58 | - foreach ($this->getStacks() as $stack) { |
|
59 | - if ($stack->accepts($name) !== $name) { |
|
58 | + foreach ($this->getStacks() as $stack){ |
|
59 | + if ($stack->accepts($name) !== $name){ |
|
60 | 60 | continue; |
61 | 61 | } |
62 | 62 | |
63 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
63 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){ |
|
64 | 64 | return true; |
65 | 65 | } |
66 | 66 | $stack->uniqueIDs[$uniqueID] = true; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @link https://github.com/spiral/framework/issues/767 |
70 | 70 | * @psalm-suppress NoInterfaceProperties |
71 | 71 | */ |
72 | - foreach ($child->nodes as $child) { |
|
72 | + foreach ($child->nodes as $child){ |
|
73 | 73 | \array_unshift($stack->nodes, $child); |
74 | 74 | } |
75 | 75 | |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | public function getStacks(): array |
88 | 88 | { |
89 | 89 | $stacks = []; |
90 | - foreach (\array_reverse($this->ctx->getScope()) as $node) { |
|
91 | - if ($node instanceof AttributedInterface) { |
|
92 | - foreach ($node->getAttribute(self::class, []) as $stack) { |
|
90 | + foreach (\array_reverse($this->ctx->getScope()) as $node){ |
|
91 | + if ($node instanceof AttributedInterface){ |
|
92 | + foreach ($node->getAttribute(self::class, []) as $stack){ |
|
93 | 93 | $stacks[] = $stack; |
94 | 94 | } |
95 | 95 | } |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | |
106 | 106 | private function getStackRootNode(int $level): AttributedInterface |
107 | 107 | { |
108 | - if ($level === 0) { |
|
108 | + if ($level === 0){ |
|
109 | 109 | $node = $this->ctx->getParentNode(); |
110 | - } else { |
|
110 | + }else{ |
|
111 | 111 | $scope = $this->ctx->getScope(); |
112 | 112 | |
113 | 113 | // looking for the parent node via given nesting level |
114 | 114 | $node = $scope[\count($scope) - 2 - $level] ?? $this->ctx->getFirstNode(); |
115 | 115 | } |
116 | 116 | |
117 | - if (!$node instanceof AttributedInterface) { |
|
117 | + if (!$node instanceof AttributedInterface){ |
|
118 | 118 | throw new \LogicException( |
119 | 119 | \sprintf( |
120 | 120 | 'Unable to create import on node without attribute storage (%s)', |
@@ -28,12 +28,15 @@ discard block |
||
28 | 28 | |
29 | 29 | public function push(string $name, Tag $child, string $uniqueID = null): bool |
30 | 30 | { |
31 | - foreach ($this->getStacks() as $stack) { |
|
32 | - if ($stack->accepts($name) !== $name) { |
|
31 | + foreach ($this->getStacks() as $stack) |
|
32 | + { |
|
33 | + if ($stack->accepts($name) !== $name) |
|
34 | + { |
|
33 | 35 | continue; |
34 | 36 | } |
35 | 37 | |
36 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
38 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) |
|
39 | + { |
|
37 | 40 | return true; |
38 | 41 | } |
39 | 42 | $stack->uniqueIDs[$uniqueID] = true; |
@@ -43,7 +46,8 @@ discard block |
||
43 | 46 | * @link https://github.com/spiral/framework/issues/767 |
44 | 47 | * @psalm-suppress NoInterfaceProperties |
45 | 48 | */ |
46 | - foreach ($child->nodes as $child) { |
|
49 | + foreach ($child->nodes as $child) |
|
50 | + { |
|
47 | 51 | $stack->nodes[] = $child; |
48 | 52 | } |
49 | 53 | |
@@ -55,12 +59,15 @@ discard block |
||
55 | 59 | |
56 | 60 | public function prepend(string $name, Tag $child, string $uniqueID = null): bool |
57 | 61 | { |
58 | - foreach ($this->getStacks() as $stack) { |
|
59 | - if ($stack->accepts($name) !== $name) { |
|
62 | + foreach ($this->getStacks() as $stack) |
|
63 | + { |
|
64 | + if ($stack->accepts($name) !== $name) |
|
65 | + { |
|
60 | 66 | continue; |
61 | 67 | } |
62 | 68 | |
63 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
69 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) |
|
70 | + { |
|
64 | 71 | return true; |
65 | 72 | } |
66 | 73 | $stack->uniqueIDs[$uniqueID] = true; |
@@ -69,7 +76,8 @@ discard block |
||
69 | 76 | * @link https://github.com/spiral/framework/issues/767 |
70 | 77 | * @psalm-suppress NoInterfaceProperties |
71 | 78 | */ |
72 | - foreach ($child->nodes as $child) { |
|
79 | + foreach ($child->nodes as $child) |
|
80 | + { |
|
73 | 81 | \array_unshift($stack->nodes, $child); |
74 | 82 | } |
75 | 83 | |
@@ -87,9 +95,12 @@ discard block |
||
87 | 95 | public function getStacks(): array |
88 | 96 | { |
89 | 97 | $stacks = []; |
90 | - foreach (\array_reverse($this->ctx->getScope()) as $node) { |
|
91 | - if ($node instanceof AttributedInterface) { |
|
92 | - foreach ($node->getAttribute(self::class, []) as $stack) { |
|
98 | + foreach (\array_reverse($this->ctx->getScope()) as $node) |
|
99 | + { |
|
100 | + if ($node instanceof AttributedInterface) |
|
101 | + { |
|
102 | + foreach ($node->getAttribute(self::class, []) as $stack) |
|
103 | + { |
|
93 | 104 | $stacks[] = $stack; |
94 | 105 | } |
95 | 106 | } |
@@ -105,16 +116,20 @@ discard block |
||
105 | 116 | |
106 | 117 | private function getStackRootNode(int $level): AttributedInterface |
107 | 118 | { |
108 | - if ($level === 0) { |
|
119 | + if ($level === 0) |
|
120 | + { |
|
109 | 121 | $node = $this->ctx->getParentNode(); |
110 | - } else { |
|
122 | + } |
|
123 | + else |
|
124 | + { |
|
111 | 125 | $scope = $this->ctx->getScope(); |
112 | 126 | |
113 | 127 | // looking for the parent node via given nesting level |
114 | 128 | $node = $scope[\count($scope) - 2 - $level] ?? $this->ctx->getFirstNode(); |
115 | 129 | } |
116 | 130 | |
117 | - if (!$node instanceof AttributedInterface) { |
|
131 | + if (!$node instanceof AttributedInterface) |
|
132 | + { |
|
118 | 133 | throw new \LogicException( |
119 | 134 | \sprintf( |
120 | 135 | 'Unable to create import on node without attribute storage (%s)', |
@@ -18,13 +18,13 @@ discard block |
||
18 | 18 | { |
19 | 19 | private function __construct( |
20 | 20 | private readonly VisitorContext $ctx |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function add(ImportInterface $import): void |
25 | 25 | { |
26 | 26 | $node = $this->ctx->getParentNode(); |
27 | - if (!$node instanceof AttributedInterface) { |
|
27 | + if (!$node instanceof AttributedInterface){ |
|
28 | 28 | throw new LogicException(\sprintf( |
29 | 29 | 'Unable to create import on node without attribute storage (%s)', |
30 | 30 | \get_debug_type($node) |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function resolve(Builder $builder, string $name): ?Template |
43 | 43 | { |
44 | - foreach ($this->getImports() as $import) { |
|
44 | + foreach ($this->getImports() as $import){ |
|
45 | 45 | $tpl = $import->resolve($builder, $name); |
46 | - if ($tpl !== null) { |
|
46 | + if ($tpl !== null){ |
|
47 | 47 | return $tpl; |
48 | 48 | } |
49 | 49 | } |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | public function getImports(): array |
60 | 60 | { |
61 | 61 | $imports = []; |
62 | - foreach (\array_reverse($this->ctx->getScope()) as $node) { |
|
63 | - if ($node instanceof AttributedInterface) { |
|
64 | - foreach ($node->getAttribute(self::class, []) as $import) { |
|
62 | + foreach (\array_reverse($this->ctx->getScope()) as $node){ |
|
63 | + if ($node instanceof AttributedInterface){ |
|
64 | + foreach ($node->getAttribute(self::class, []) as $import){ |
|
65 | 65 | $imports[] = $import; |
66 | 66 | } |
67 | 67 | } |
@@ -24,7 +24,8 @@ discard block |
||
24 | 24 | public function add(ImportInterface $import): void |
25 | 25 | { |
26 | 26 | $node = $this->ctx->getParentNode(); |
27 | - if (!$node instanceof AttributedInterface) { |
|
27 | + if (!$node instanceof AttributedInterface) |
|
28 | + { |
|
28 | 29 | throw new LogicException(\sprintf( |
29 | 30 | 'Unable to create import on node without attribute storage (%s)', |
30 | 31 | \get_debug_type($node) |
@@ -41,9 +42,11 @@ discard block |
||
41 | 42 | */ |
42 | 43 | public function resolve(Builder $builder, string $name): ?Template |
43 | 44 | { |
44 | - foreach ($this->getImports() as $import) { |
|
45 | + foreach ($this->getImports() as $import) |
|
46 | + { |
|
45 | 47 | $tpl = $import->resolve($builder, $name); |
46 | - if ($tpl !== null) { |
|
48 | + if ($tpl !== null) |
|
49 | + { |
|
47 | 50 | return $tpl; |
48 | 51 | } |
49 | 52 | } |
@@ -59,9 +62,12 @@ discard block |
||
59 | 62 | public function getImports(): array |
60 | 63 | { |
61 | 64 | $imports = []; |
62 | - foreach (\array_reverse($this->ctx->getScope()) as $node) { |
|
63 | - if ($node instanceof AttributedInterface) { |
|
64 | - foreach ($node->getAttribute(self::class, []) as $import) { |
|
65 | + foreach (\array_reverse($this->ctx->getScope()) as $node) |
|
66 | + { |
|
67 | + if ($node instanceof AttributedInterface) |
|
68 | + { |
|
69 | + foreach ($node->getAttribute(self::class, []) as $import) |
|
70 | + { |
|
65 | 71 | $imports[] = $import; |
66 | 72 | } |
67 | 73 | } |
@@ -15,12 +15,12 @@ |
||
15 | 15 | { |
16 | 16 | public function __construct( |
17 | 17 | private readonly string $path |
18 | - ) { |
|
18 | + ){ |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
22 | 22 | { |
23 | - if ($node instanceof Block && $node->getContext()->getPath() === $this->path) { |
|
23 | + if ($node instanceof Block && $node->getContext()->getPath() === $this->path){ |
|
24 | 24 | $node->name = null; |
25 | 25 | } |
26 | 26 |
@@ -20,7 +20,8 @@ |
||
20 | 20 | |
21 | 21 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
22 | 22 | { |
23 | - if ($node instanceof Block && $node->getContext()->getPath() === $this->path) { |
|
23 | + if ($node instanceof Block && $node->getContext()->getPath() === $this->path) |
|
24 | + { |
|
24 | 25 | $node->name = null; |
25 | 26 | } |
26 | 27 |
@@ -19,21 +19,21 @@ |
||
19 | 19 | |
20 | 20 | public function __construct( |
21 | 21 | private readonly string $path |
22 | - ) { |
|
22 | + ){ |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
26 | 26 | { |
27 | - if (!$node instanceof PHP || !\str_contains($node->content, self::PHP_MARCO_EXISTS_FUNCTION)) { |
|
27 | + if (!$node instanceof PHP || !\str_contains($node->content, self::PHP_MARCO_EXISTS_FUNCTION)){ |
|
28 | 28 | return null; |
29 | 29 | } |
30 | 30 | |
31 | - if ($node->getContext()->getPath() !== $this->path) { |
|
31 | + if ($node->getContext()->getPath() !== $this->path){ |
|
32 | 32 | return null; |
33 | 33 | } |
34 | 34 | |
35 | 35 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
36 | - foreach (\array_keys($exists->getBlocks()) as $name) { |
|
36 | + foreach (\array_keys($exists->getBlocks()) as $name){ |
|
37 | 37 | // do not leak to parent template |
38 | 38 | $exists->set($name, 'false'); |
39 | 39 | } |
@@ -24,16 +24,19 @@ |
||
24 | 24 | |
25 | 25 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
26 | 26 | { |
27 | - if (!$node instanceof PHP || !\str_contains($node->content, self::PHP_MARCO_EXISTS_FUNCTION)) { |
|
27 | + if (!$node instanceof PHP || !\str_contains($node->content, self::PHP_MARCO_EXISTS_FUNCTION)) |
|
28 | + { |
|
28 | 29 | return null; |
29 | 30 | } |
30 | 31 | |
31 | - if ($node->getContext()->getPath() !== $this->path) { |
|
32 | + if ($node->getContext()->getPath() !== $this->path) |
|
33 | + { |
|
32 | 34 | return null; |
33 | 35 | } |
34 | 36 | |
35 | 37 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
36 | - foreach (\array_keys($exists->getBlocks()) as $name) { |
|
38 | + foreach (\array_keys($exists->getBlocks()) as $name) |
|
39 | + { |
|
37 | 40 | // do not leak to parent template |
38 | 41 | $exists->set($name, 'false'); |
39 | 42 | } |
@@ -25,33 +25,33 @@ discard block |
||
25 | 25 | |
26 | 26 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
27 | 27 | { |
28 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->pushKeyword)) { |
|
28 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->pushKeyword)){ |
|
29 | 29 | return $this->registerPush(StackContext::on($ctx), $node); |
30 | 30 | } |
31 | 31 | |
32 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->prependKeyword)) { |
|
32 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->prependKeyword)){ |
|
33 | 33 | return $this->registerPrepend(StackContext::on($ctx), $node); |
34 | 34 | } |
35 | 35 | |
36 | 36 | return null; |
37 | 37 | } |
38 | 38 | |
39 | - private function registerPush(StackContext $ctx, Tag $node): int|Tag|null |
|
39 | + private function registerPush(StackContext $ctx, Tag $node): int | Tag | null |
|
40 | 40 | { |
41 | 41 | $name = $this->stackName($node); |
42 | 42 | |
43 | - if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node))) { |
|
43 | + if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node))){ |
|
44 | 44 | return null; |
45 | 45 | } |
46 | 46 | |
47 | 47 | return self::REMOVE_NODE; |
48 | 48 | } |
49 | 49 | |
50 | - private function registerPrepend(StackContext $ctx, Tag $node): int|Tag|null |
|
50 | + private function registerPrepend(StackContext $ctx, Tag $node): int | Tag | null |
|
51 | 51 | { |
52 | 52 | $name = $this->stackName($node); |
53 | 53 | |
54 | - if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node))) { |
|
54 | + if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node))){ |
|
55 | 55 | return null; |
56 | 56 | } |
57 | 57 | |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | |
61 | 61 | private function stackName(Tag $tag): ?string |
62 | 62 | { |
63 | - foreach ($tag->attrs as $attr) { |
|
64 | - if (\is_string($attr->value) && $attr->name === 'name') { |
|
63 | + foreach ($tag->attrs as $attr){ |
|
64 | + if (\is_string($attr->value) && $attr->name === 'name'){ |
|
65 | 65 | return \trim($attr->value, '\'"'); |
66 | 66 | } |
67 | 67 | } |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | |
72 | 72 | private function uniqueID(Tag $tag): ?string |
73 | 73 | { |
74 | - foreach ($tag->attrs as $attr) { |
|
75 | - if (\is_string($attr->value) && $attr->name === 'unique-id') { |
|
74 | + foreach ($tag->attrs as $attr){ |
|
75 | + if (\is_string($attr->value) && $attr->name === 'unique-id'){ |
|
76 | 76 | return \trim($attr->value, '\'"'); |
77 | 77 | } |
78 | 78 | } |
@@ -25,11 +25,13 @@ discard block |
||
25 | 25 | |
26 | 26 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
27 | 27 | { |
28 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->pushKeyword)) { |
|
28 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->pushKeyword)) |
|
29 | + { |
|
29 | 30 | return $this->registerPush(StackContext::on($ctx), $node); |
30 | 31 | } |
31 | 32 | |
32 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->prependKeyword)) { |
|
33 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->prependKeyword)) |
|
34 | + { |
|
33 | 35 | return $this->registerPrepend(StackContext::on($ctx), $node); |
34 | 36 | } |
35 | 37 | |
@@ -40,7 +42,8 @@ discard block |
||
40 | 42 | { |
41 | 43 | $name = $this->stackName($node); |
42 | 44 | |
43 | - if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node))) { |
|
45 | + if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node))) |
|
46 | + { |
|
44 | 47 | return null; |
45 | 48 | } |
46 | 49 | |
@@ -51,7 +54,8 @@ discard block |
||
51 | 54 | { |
52 | 55 | $name = $this->stackName($node); |
53 | 56 | |
54 | - if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node))) { |
|
57 | + if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node))) |
|
58 | + { |
|
55 | 59 | return null; |
56 | 60 | } |
57 | 61 | |
@@ -60,8 +64,10 @@ discard block |
||
60 | 64 | |
61 | 65 | private function stackName(Tag $tag): ?string |
62 | 66 | { |
63 | - foreach ($tag->attrs as $attr) { |
|
64 | - if (\is_string($attr->value) && $attr->name === 'name') { |
|
67 | + foreach ($tag->attrs as $attr) |
|
68 | + { |
|
69 | + if (\is_string($attr->value) && $attr->name === 'name') |
|
70 | + { |
|
65 | 71 | return \trim($attr->value, '\'"'); |
66 | 72 | } |
67 | 73 | } |
@@ -71,8 +77,10 @@ discard block |
||
71 | 77 | |
72 | 78 | private function uniqueID(Tag $tag): ?string |
73 | 79 | { |
74 | - foreach ($tag->attrs as $attr) { |
|
75 | - if (\is_string($attr->value) && $attr->name === 'unique-id') { |
|
80 | + foreach ($tag->attrs as $attr) |
|
81 | + { |
|
82 | + if (\is_string($attr->value) && $attr->name === 'unique-id') |
|
83 | + { |
|
76 | 84 | return \trim($attr->value, '\'"'); |
77 | 85 | } |
78 | 86 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public function __construct( |
36 | 36 | private readonly string $defaultFilter = self::DEFAULT_FILTER, |
37 | 37 | private array $directives = [] |
38 | - ) { |
|
38 | + ){ |
|
39 | 39 | $this->traverser = new Traverser(); |
40 | 40 | $this->traverser->addVisitor($this); |
41 | 41 | } |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | |
56 | 56 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
57 | 57 | { |
58 | - if ($node instanceof Output) { |
|
58 | + if ($node instanceof Output){ |
|
59 | 59 | return $this->output($node, $ctx); |
60 | 60 | } |
61 | 61 | |
62 | - if ($node instanceof Directive) { |
|
62 | + if ($node instanceof Directive){ |
|
63 | 63 | return $this->directive($node); |
64 | 64 | } |
65 | 65 | |
66 | - if ($node instanceof Template) { |
|
66 | + if ($node instanceof Template){ |
|
67 | 67 | $extendsTag = $node->getAttribute(ExtendsParent::class); |
68 | - if ($extendsTag instanceof Tag) { |
|
68 | + if ($extendsTag instanceof Tag){ |
|
69 | 69 | $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs); |
70 | 70 | } |
71 | 71 | } |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | |
76 | 76 | private function directive(Directive $node): PHP |
77 | 77 | { |
78 | - foreach ($this->directives as $renderer) { |
|
78 | + foreach ($this->directives as $renderer){ |
|
79 | 79 | $result = $renderer->render($node); |
80 | - if ($result !== null) { |
|
80 | + if ($result !== null){ |
|
81 | 81 | return new PHP($result, \token_get_all($result), $node->getContext()); |
82 | 82 | } |
83 | 83 | } |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | * In future this method can support context aware escaping based on tag location. |
95 | 95 | */ |
96 | 96 | |
97 | - if ($node->rawOutput) { |
|
97 | + if ($node->rawOutput){ |
|
98 | 98 | $result = \sprintf('<?php echo %s; ?>', \trim($node->body)); |
99 | - } else { |
|
99 | + }else{ |
|
100 | 100 | $filter = $node->filter ?? $this->getFilterContext($ctx); |
101 | 101 | |
102 | 102 | $result = \sprintf(\sprintf('<?php echo %s; ?>', $filter), \trim($node->body)); |
@@ -114,22 +114,22 @@ discard block |
||
114 | 114 | // only "interesting" nodes |
115 | 115 | $context = []; |
116 | 116 | |
117 | - foreach (\array_reverse($ctx->getScope()) as $node) { |
|
118 | - if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) { |
|
117 | + foreach (\array_reverse($ctx->getScope()) as $node){ |
|
118 | + if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim){ |
|
119 | 119 | $context[] = $node; |
120 | 120 | } |
121 | 121 | |
122 | - if (\count($context) === 2) { |
|
122 | + if (\count($context) === 2){ |
|
123 | 123 | break; |
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | - if (\count($context) !== 2) { |
|
127 | + if (\count($context) !== 2){ |
|
128 | 128 | return $this->defaultFilter; |
129 | 129 | } |
130 | 130 | |
131 | 131 | // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter |
132 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') { |
|
132 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script'){ |
|
133 | 133 | return \sprintf( |
134 | 134 | 'json_encode(%s, %s, %s)', |
135 | 135 | '%s', |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | // in on* and other attributes |
142 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') { |
|
142 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style'){ |
|
143 | 143 | return \sprintf("'%s', %s, '%s'", '"', $this->defaultFilter, '"'); |
144 | 144 | } |
145 | 145 |
@@ -55,17 +55,21 @@ discard block |
||
55 | 55 | |
56 | 56 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
57 | 57 | { |
58 | - if ($node instanceof Output) { |
|
58 | + if ($node instanceof Output) |
|
59 | + { |
|
59 | 60 | return $this->output($node, $ctx); |
60 | 61 | } |
61 | 62 | |
62 | - if ($node instanceof Directive) { |
|
63 | + if ($node instanceof Directive) |
|
64 | + { |
|
63 | 65 | return $this->directive($node); |
64 | 66 | } |
65 | 67 | |
66 | - if ($node instanceof Template) { |
|
68 | + if ($node instanceof Template) |
|
69 | + { |
|
67 | 70 | $extendsTag = $node->getAttribute(ExtendsParent::class); |
68 | - if ($extendsTag instanceof Tag) { |
|
71 | + if ($extendsTag instanceof Tag) |
|
72 | + { |
|
69 | 73 | $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs); |
70 | 74 | } |
71 | 75 | } |
@@ -75,9 +79,11 @@ discard block |
||
75 | 79 | |
76 | 80 | private function directive(Directive $node): PHP |
77 | 81 | { |
78 | - foreach ($this->directives as $renderer) { |
|
82 | + foreach ($this->directives as $renderer) |
|
83 | + { |
|
79 | 84 | $result = $renderer->render($node); |
80 | - if ($result !== null) { |
|
85 | + if ($result !== null) |
|
86 | + { |
|
81 | 87 | return new PHP($result, \token_get_all($result), $node->getContext()); |
82 | 88 | } |
83 | 89 | } |
@@ -94,9 +100,12 @@ discard block |
||
94 | 100 | * In future this method can support context aware escaping based on tag location. |
95 | 101 | */ |
96 | 102 | |
97 | - if ($node->rawOutput) { |
|
103 | + if ($node->rawOutput) |
|
104 | + { |
|
98 | 105 | $result = \sprintf('<?php echo %s; ?>', \trim($node->body)); |
99 | - } else { |
|
106 | + } |
|
107 | + else |
|
108 | + { |
|
100 | 109 | $filter = $node->filter ?? $this->getFilterContext($ctx); |
101 | 110 | |
102 | 111 | $result = \sprintf(\sprintf('<?php echo %s; ?>', $filter), \trim($node->body)); |
@@ -114,22 +123,27 @@ discard block |
||
114 | 123 | // only "interesting" nodes |
115 | 124 | $context = []; |
116 | 125 | |
117 | - foreach (\array_reverse($ctx->getScope()) as $node) { |
|
118 | - if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) { |
|
126 | + foreach (\array_reverse($ctx->getScope()) as $node) |
|
127 | + { |
|
128 | + if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) |
|
129 | + { |
|
119 | 130 | $context[] = $node; |
120 | 131 | } |
121 | 132 | |
122 | - if (\count($context) === 2) { |
|
133 | + if (\count($context) === 2) |
|
134 | + { |
|
123 | 135 | break; |
124 | 136 | } |
125 | 137 | } |
126 | 138 | |
127 | - if (\count($context) !== 2) { |
|
139 | + if (\count($context) !== 2) |
|
140 | + { |
|
128 | 141 | return $this->defaultFilter; |
129 | 142 | } |
130 | 143 | |
131 | 144 | // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter |
132 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') { |
|
145 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') |
|
146 | + { |
|
133 | 147 | return \sprintf( |
134 | 148 | 'json_encode(%s, %s, %s)', |
135 | 149 | '%s', |
@@ -139,7 +153,8 @@ discard block |
||
139 | 153 | } |
140 | 154 | |
141 | 155 | // in on* and other attributes |
142 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') { |
|
156 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') |
|
157 | + { |
|
143 | 158 | return \sprintf("'%s', %s, '%s'", '"', $this->defaultFilter, '"'); |
144 | 159 | } |
145 | 160 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | { |
17 | 17 | public function __construct( |
18 | 18 | private readonly string $characters = " \n\t\r" |
19 | - ) { |
|
19 | + ){ |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | |
27 | 27 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
28 | 28 | { |
29 | - if ($node instanceof Raw && \trim($node->content, $this->characters) === '') { |
|
30 | - foreach ($ctx->getScope() as $scope) { |
|
31 | - if ($scope instanceof Attr) { |
|
29 | + if ($node instanceof Raw && \trim($node->content, $this->characters) === ''){ |
|
30 | + foreach ($ctx->getScope() as $scope){ |
|
31 | + if ($scope instanceof Attr){ |
|
32 | 32 | // do not trim attribute values |
33 | 33 | return null; |
34 | 34 | } |
@@ -26,9 +26,12 @@ |
||
26 | 26 | |
27 | 27 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
28 | 28 | { |
29 | - if ($node instanceof Raw && \trim($node->content, $this->characters) === '') { |
|
30 | - foreach ($ctx->getScope() as $scope) { |
|
31 | - if ($scope instanceof Attr) { |
|
29 | + if ($node instanceof Raw && \trim($node->content, $this->characters) === '') |
|
30 | + { |
|
31 | + foreach ($ctx->getScope() as $scope) |
|
32 | + { |
|
33 | + if ($scope instanceof Attr) |
|
34 | + { |
|
32 | 35 | // do not trim attribute values |
33 | 36 | return null; |
34 | 37 | } |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | final class QuotedValue |
16 | 16 | { |
17 | 17 | public function __construct( |
18 | - private readonly NodeInterface|string $value |
|
19 | - ) { |
|
18 | + private readonly NodeInterface | string $value |
|
19 | + ){ |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function getValue(): mixed |
@@ -30,29 +30,29 @@ discard block |
||
30 | 30 | public function trimValue(): array |
31 | 31 | { |
32 | 32 | $value = $this->value; |
33 | - if ($value instanceof Nil) { |
|
33 | + if ($value instanceof Nil){ |
|
34 | 34 | return []; |
35 | 35 | } |
36 | 36 | |
37 | - if (\is_string($value)) { |
|
37 | + if (\is_string($value)){ |
|
38 | 38 | return [new Raw(\trim($value, '\'"'))]; |
39 | 39 | } |
40 | 40 | |
41 | - if (!$value instanceof Mixin) { |
|
41 | + if (!$value instanceof Mixin){ |
|
42 | 42 | return [$value]; |
43 | 43 | } |
44 | 44 | |
45 | 45 | // trim mixin quotes |
46 | 46 | $nodes = $value->nodes; |
47 | 47 | |
48 | - if (\count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[\count($nodes) - 1] instanceof Raw) { |
|
48 | + if (\count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[\count($nodes) - 1] instanceof Raw){ |
|
49 | 49 | /** |
50 | 50 | * TODO issue #767 |
51 | 51 | * @link https://github.com/spiral/framework/issues/767 |
52 | 52 | * @psalm-suppress InvalidArrayAccess |
53 | 53 | */ |
54 | 54 | $quote = $nodes[0]->content[0]; |
55 | - if (!\in_array($quote, ['"', "'"])) { |
|
55 | + if (!\in_array($quote, ['"', "'"])){ |
|
56 | 56 | return $nodes; |
57 | 57 | } |
58 | 58 | |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | ); |
69 | 69 | } |
70 | 70 | |
71 | - foreach ($nodes as $index => $node) { |
|
72 | - if ($node instanceof Raw && $node->content === '') { |
|
71 | + foreach ($nodes as $index => $node){ |
|
72 | + if ($node instanceof Raw && $node->content === ''){ |
|
73 | 73 | unset($nodes[$index]); |
74 | 74 | } |
75 | 75 | } |
@@ -30,29 +30,34 @@ discard block |
||
30 | 30 | public function trimValue(): array |
31 | 31 | { |
32 | 32 | $value = $this->value; |
33 | - if ($value instanceof Nil) { |
|
33 | + if ($value instanceof Nil) |
|
34 | + { |
|
34 | 35 | return []; |
35 | 36 | } |
36 | 37 | |
37 | - if (\is_string($value)) { |
|
38 | + if (\is_string($value)) |
|
39 | + { |
|
38 | 40 | return [new Raw(\trim($value, '\'"'))]; |
39 | 41 | } |
40 | 42 | |
41 | - if (!$value instanceof Mixin) { |
|
43 | + if (!$value instanceof Mixin) |
|
44 | + { |
|
42 | 45 | return [$value]; |
43 | 46 | } |
44 | 47 | |
45 | 48 | // trim mixin quotes |
46 | 49 | $nodes = $value->nodes; |
47 | 50 | |
48 | - if (\count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[\count($nodes) - 1] instanceof Raw) { |
|
51 | + if (\count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[\count($nodes) - 1] instanceof Raw) |
|
52 | + { |
|
49 | 53 | /** |
50 | 54 | * TODO issue #767 |
51 | 55 | * @link https://github.com/spiral/framework/issues/767 |
52 | 56 | * @psalm-suppress InvalidArrayAccess |
53 | 57 | */ |
54 | 58 | $quote = $nodes[0]->content[0]; |
55 | - if (!\in_array($quote, ['"', "'"])) { |
|
59 | + if (!\in_array($quote, ['"', "'"])) |
|
60 | + { |
|
56 | 61 | return $nodes; |
57 | 62 | } |
58 | 63 | |
@@ -68,8 +73,10 @@ discard block |
||
68 | 73 | ); |
69 | 74 | } |
70 | 75 | |
71 | - foreach ($nodes as $index => $node) { |
|
72 | - if ($node instanceof Raw && $node->content === '') { |
|
76 | + foreach ($nodes as $index => $node) |
|
77 | + { |
|
78 | + if ($node instanceof Raw && $node->content === '') |
|
79 | + { |
|
73 | 80 | unset($nodes[$index]); |
74 | 81 | } |
75 | 82 | } |