@@ -23,25 +23,25 @@ |
||
23 | 23 | private string $path, |
24 | 24 | private ?string $prefix = null, |
25 | 25 | ?Context $context = null |
26 | - ) { |
|
26 | + ){ |
|
27 | 27 | $this->context = $context; |
28 | 28 | } |
29 | 29 | |
30 | 30 | public function resolve(Builder $builder, string $name): ?Template |
31 | 31 | { |
32 | - if ($this->template === null) { |
|
32 | + if ($this->template === null){ |
|
33 | 33 | $this->template = $builder->load($this->path); |
34 | 34 | } |
35 | 35 | |
36 | 36 | $path = $name; |
37 | - if ($this->prefix !== null) { |
|
37 | + if ($this->prefix !== null){ |
|
38 | 38 | $path = \substr($path, \strlen($this->prefix) + 1); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** @var ImportInterface $import */ |
42 | - foreach ($this->template->getAttribute(ImportContext::class, []) as $import) { |
|
42 | + foreach ($this->template->getAttribute(ImportContext::class, []) as $import){ |
|
43 | 43 | $tpl = $import->resolve($builder, $path); |
44 | - if ($tpl !== null) { |
|
44 | + if ($tpl !== null){ |
|
45 | 45 | return $tpl; |
46 | 46 | } |
47 | 47 | } |
@@ -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 |
@@ -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 |
@@ -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)', |
@@ -24,22 +24,22 @@ discard block |
||
24 | 24 | |
25 | 25 | public function withinContext(?Context $ctx, callable $body): void |
26 | 26 | { |
27 | - if ($ctx === null || $ctx->getPath() === null) { |
|
27 | + if ($ctx === null || $ctx->getPath() === null){ |
|
28 | 28 | $body($this); |
29 | 29 | return; |
30 | 30 | } |
31 | 31 | |
32 | - try { |
|
32 | + try{ |
|
33 | 33 | $this->parent = Location::fromContext($ctx, $this->parent); |
34 | 34 | $body($this); |
35 | - } finally { |
|
35 | + }finally{ |
|
36 | 36 | $this->parent = $this->parent->parent; |
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | 40 | public function push(string $content, ?Context $ctx = null): void |
41 | 41 | { |
42 | - if ($ctx !== null && $ctx->getPath() !== null) { |
|
42 | + if ($ctx !== null && $ctx->getPath() !== null){ |
|
43 | 43 | $this->locations[\strlen($this->content)] = Location::fromContext($ctx, $this->parent); |
44 | 44 | } |
45 | 45 | |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | $paths = []; |
60 | 60 | |
61 | 61 | // We can scan top level only |
62 | - foreach ($this->locations as $loc) { |
|
63 | - if (!\in_array($loc->path, $paths, true)) { |
|
62 | + foreach ($this->locations as $loc){ |
|
63 | + if (!\in_array($loc->path, $paths, true)){ |
|
64 | 64 | $paths[] = $loc->path; |
65 | 65 | } |
66 | 66 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | { |
76 | 76 | $locations = []; |
77 | 77 | |
78 | - foreach ($this->locations as $offset => $location) { |
|
78 | + foreach ($this->locations as $offset => $location){ |
|
79 | 79 | $locations[$offset] = $location; |
80 | 80 | } |
81 | 81 |
@@ -24,22 +24,27 @@ discard block |
||
24 | 24 | |
25 | 25 | public function withinContext(?Context $ctx, callable $body): void |
26 | 26 | { |
27 | - if ($ctx === null || $ctx->getPath() === null) { |
|
27 | + if ($ctx === null || $ctx->getPath() === null) |
|
28 | + { |
|
28 | 29 | $body($this); |
29 | 30 | return; |
30 | 31 | } |
31 | 32 | |
32 | - try { |
|
33 | + try |
|
34 | + { |
|
33 | 35 | $this->parent = Location::fromContext($ctx, $this->parent); |
34 | 36 | $body($this); |
35 | - } finally { |
|
37 | + } |
|
38 | + finally |
|
39 | + { |
|
36 | 40 | $this->parent = $this->parent->parent; |
37 | 41 | } |
38 | 42 | } |
39 | 43 | |
40 | 44 | public function push(string $content, ?Context $ctx = null): void |
41 | 45 | { |
42 | - if ($ctx !== null && $ctx->getPath() !== null) { |
|
46 | + if ($ctx !== null && $ctx->getPath() !== null) |
|
47 | + { |
|
43 | 48 | $this->locations[\strlen($this->content)] = Location::fromContext($ctx, $this->parent); |
44 | 49 | } |
45 | 50 | |
@@ -59,8 +64,10 @@ discard block |
||
59 | 64 | $paths = []; |
60 | 65 | |
61 | 66 | // We can scan top level only |
62 | - foreach ($this->locations as $loc) { |
|
63 | - if (!\in_array($loc->path, $paths, true)) { |
|
67 | + foreach ($this->locations as $loc) |
|
68 | + { |
|
69 | + if (!\in_array($loc->path, $paths, true)) |
|
70 | + { |
|
64 | 71 | $paths[] = $loc->path; |
65 | 72 | } |
66 | 73 | } |
@@ -75,7 +82,8 @@ discard block |
||
75 | 82 | { |
76 | 83 | $locations = []; |
77 | 84 | |
78 | - foreach ($this->locations as $offset => $location) { |
|
85 | + foreach ($this->locations as $offset => $location) |
|
86 | + { |
|
79 | 87 | $locations[$offset] = $location; |
80 | 88 | } |
81 | 89 |
@@ -15,7 +15,7 @@ |
||
15 | 15 | string $message, |
16 | 16 | private Context $context, |
17 | 17 | ?\Throwable $previous = null |
18 | - ) { |
|
18 | + ){ |
|
19 | 19 | parent::__construct($message, 0, $previous); |
20 | 20 | } |
21 | 21 |
@@ -22,20 +22,20 @@ |
||
22 | 22 | $this->renders[] = $renderer; |
23 | 23 | } |
24 | 24 | |
25 | - public function compile(array|NodeInterface $node, ?Result $result = null): Result |
|
25 | + public function compile(array | NodeInterface $node, ?Result $result = null): Result |
|
26 | 26 | { |
27 | 27 | $result ??= new Result(); |
28 | 28 | |
29 | - if (\is_array($node)) { |
|
30 | - foreach ($node as $child) { |
|
29 | + if (\is_array($node)){ |
|
30 | + foreach ($node as $child){ |
|
31 | 31 | $this->compile($child, $result); |
32 | 32 | } |
33 | 33 | |
34 | 34 | return $result; |
35 | 35 | } |
36 | 36 | |
37 | - foreach ($this->renders as $renderer) { |
|
38 | - if ($renderer->render($this, $result, $node)) { |
|
37 | + foreach ($this->renders as $renderer){ |
|
38 | + if ($renderer->render($this, $result, $node)){ |
|
39 | 39 | return $result; |
40 | 40 | } |
41 | 41 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function __construct( |
26 | 26 | ?Context $context = null, |
27 | 27 | public string $pattern = '*' |
28 | - ) { |
|
28 | + ){ |
|
29 | 29 | $this->context = $context; |
30 | 30 | } |
31 | 31 | |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function accepts(string $name): ?string |
37 | 37 | { |
38 | - if ($this->pattern === '' || $this->pattern === '*') { |
|
38 | + if ($this->pattern === '' || $this->pattern === '*'){ |
|
39 | 39 | // accept everything |
40 | 40 | return $name; |
41 | 41 | } |
42 | 42 | |
43 | 43 | $conditions = []; |
44 | - foreach (\explode(';', $this->pattern) as $condition) { |
|
45 | - if (!\str_contains($condition, ':')) { |
|
44 | + foreach (\explode(';', $this->pattern) as $condition){ |
|
45 | + if (!\str_contains($condition, ':')){ |
|
46 | 46 | //Invalid |
47 | 47 | continue; |
48 | 48 | } |
@@ -51,27 +51,27 @@ discard block |
||
51 | 51 | $conditions[$option] = $value; |
52 | 52 | } |
53 | 53 | |
54 | - if (isset($conditions['include'])) { |
|
54 | + if (isset($conditions['include'])){ |
|
55 | 55 | $include = \explode(',', $conditions['include']); |
56 | - if (\in_array($name, $include)) { |
|
56 | + if (\in_array($name, $include)){ |
|
57 | 57 | return $name; |
58 | 58 | } |
59 | 59 | |
60 | 60 | return null; |
61 | 61 | } |
62 | 62 | |
63 | - if (isset($conditions['exclude'])) { |
|
63 | + if (isset($conditions['exclude'])){ |
|
64 | 64 | $exclude = \explode(',', $conditions['exclude']); |
65 | - if (\in_array($name, $exclude)) { |
|
65 | + if (\in_array($name, $exclude)){ |
|
66 | 66 | return null; |
67 | 67 | } |
68 | 68 | |
69 | 69 | return $name; |
70 | 70 | } |
71 | 71 | |
72 | - if (isset($conditions['prefix'])) { |
|
72 | + if (isset($conditions['prefix'])){ |
|
73 | 73 | $conditions['prefix'] = \rtrim($conditions['prefix'], ' *'); |
74 | - if (\str_starts_with($name, $conditions['prefix'])) { |
|
74 | + if (\str_starts_with($name, $conditions['prefix'])){ |
|
75 | 75 | return substr($name, \strlen($conditions['prefix'])); |
76 | 76 | } |
77 | 77 |
@@ -25,7 +25,7 @@ |
||
25 | 25 | public function __construct( |
26 | 26 | public ?string $name, |
27 | 27 | ?Context $context = null |
28 | - ) { |
|
28 | + ){ |
|
29 | 29 | $this->context = $context; |
30 | 30 | } |
31 | 31 |