@@ -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 | } |
@@ -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 | } |
@@ -28,12 +28,12 @@ discard block |
||
| 28 | 28 | public function __construct( |
| 29 | 29 | private readonly Builder $builder, |
| 30 | 30 | private readonly Merger $merger = new Merger() |
| 31 | - ) { |
|
| 31 | + ){ |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
| 35 | 35 | { |
| 36 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->extendsKeyword)) { |
|
| 36 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->extendsKeyword)){ |
|
| 37 | 37 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
| 44 | 44 | { |
| 45 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->extendsKeyword)) { |
|
| 45 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->extendsKeyword)){ |
|
| 46 | 46 | $parent = $ctx->getParentNode(); |
| 47 | - if (!$parent instanceof AttributedInterface) { |
|
| 47 | + if (!$parent instanceof AttributedInterface){ |
|
| 48 | 48 | throw new LogicException(\sprintf( |
| 49 | 49 | 'Unable to extend non attributable node (%s)', |
| 50 | 50 | \get_debug_type($node) |
@@ -58,11 +58,11 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | // extend current node |
| 60 | 60 | /** @psalm-var Template|Block|Verbatim|Tag $node */ |
| 61 | - if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null) { |
|
| 61 | + if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null){ |
|
| 62 | 62 | /** @var Tag $extends */ |
| 63 | 63 | $extends = $node->getAttribute(self::class); |
| 64 | 64 | |
| 65 | - foreach ($node->nodes as $child) { |
|
| 65 | + foreach ($node->nodes as $child){ |
|
| 66 | 66 | /** |
| 67 | 67 | * TODO issue #767 |
| 68 | 68 | * @link https://github.com/spiral/framework/issues/767 |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $path = 'undefined'; |
| 75 | - try { |
|
| 75 | + try{ |
|
| 76 | 76 | $path = $this->getPath($extends); |
| 77 | 77 | |
| 78 | 78 | return $this->merger->merge($this->builder->load($path), $extends); |
| 79 | - } catch (\Throwable $e) { |
|
| 79 | + }catch (\Throwable $e){ |
|
| 80 | 80 | throw new ExtendsException( |
| 81 | 81 | \sprintf('Unable to extend parent `%s`', $path), |
| 82 | 82 | $extends->getContext(), |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | private function getPath(Tag $tag): string |
| 92 | 92 | { |
| 93 | - if (\str_starts_with($tag->name, $this->extendsKeyword . ':')) { |
|
| 93 | + if (\str_starts_with($tag->name, $this->extendsKeyword.':')){ |
|
| 94 | 94 | $name = \substr($tag->name, \strlen($this->extendsKeyword) + 1); |
| 95 | 95 | |
| 96 | 96 | return \str_replace(['.'], DIRECTORY_SEPARATOR, $name); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - foreach ($tag->attrs as $attr) { |
|
| 100 | - if ($attr->name === 'path' && \is_string($attr->value)) { |
|
| 99 | + foreach ($tag->attrs as $attr){ |
|
| 100 | + if ($attr->name === 'path' && \is_string($attr->value)){ |
|
| 101 | 101 | return \trim($attr->value, '\'"'); |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -33,7 +33,8 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
| 35 | 35 | { |
| 36 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->extendsKeyword)) { |
|
| 36 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->extendsKeyword)) |
|
| 37 | + { |
|
| 37 | 38 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
| 38 | 39 | } |
| 39 | 40 | |
@@ -42,9 +43,11 @@ discard block |
||
| 42 | 43 | |
| 43 | 44 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
| 44 | 45 | { |
| 45 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->extendsKeyword)) { |
|
| 46 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->extendsKeyword)) |
|
| 47 | + { |
|
| 46 | 48 | $parent = $ctx->getParentNode(); |
| 47 | - if (!$parent instanceof AttributedInterface) { |
|
| 49 | + if (!$parent instanceof AttributedInterface) |
|
| 50 | + { |
|
| 48 | 51 | throw new LogicException(\sprintf( |
| 49 | 52 | 'Unable to extend non attributable node (%s)', |
| 50 | 53 | \get_debug_type($node) |
@@ -58,11 +61,13 @@ discard block |
||
| 58 | 61 | |
| 59 | 62 | // extend current node |
| 60 | 63 | /** @psalm-var Template|Block|Verbatim|Tag $node */ |
| 61 | - if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null) { |
|
| 64 | + if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null) |
|
| 65 | + { |
|
| 62 | 66 | /** @var Tag $extends */ |
| 63 | 67 | $extends = $node->getAttribute(self::class); |
| 64 | 68 | |
| 65 | - foreach ($node->nodes as $child) { |
|
| 69 | + foreach ($node->nodes as $child) |
|
| 70 | + { |
|
| 66 | 71 | /** |
| 67 | 72 | * TODO issue #767 |
| 68 | 73 | * @link https://github.com/spiral/framework/issues/767 |
@@ -72,11 +77,14 @@ discard block |
||
| 72 | 77 | } |
| 73 | 78 | |
| 74 | 79 | $path = 'undefined'; |
| 75 | - try { |
|
| 80 | + try |
|
| 81 | + { |
|
| 76 | 82 | $path = $this->getPath($extends); |
| 77 | 83 | |
| 78 | 84 | return $this->merger->merge($this->builder->load($path), $extends); |
| 79 | - } catch (\Throwable $e) { |
|
| 85 | + } |
|
| 86 | + catch (\Throwable $e) |
|
| 87 | + { |
|
| 80 | 88 | throw new ExtendsException( |
| 81 | 89 | \sprintf('Unable to extend parent `%s`', $path), |
| 82 | 90 | $extends->getContext(), |
@@ -90,14 +98,17 @@ discard block |
||
| 90 | 98 | |
| 91 | 99 | private function getPath(Tag $tag): string |
| 92 | 100 | { |
| 93 | - if (\str_starts_with($tag->name, $this->extendsKeyword . ':')) { |
|
| 101 | + if (\str_starts_with($tag->name, $this->extendsKeyword . ':')) |
|
| 102 | + { |
|
| 94 | 103 | $name = \substr($tag->name, \strlen($this->extendsKeyword) + 1); |
| 95 | 104 | |
| 96 | 105 | return \str_replace(['.'], DIRECTORY_SEPARATOR, $name); |
| 97 | 106 | } |
| 98 | 107 | |
| 99 | - foreach ($tag->attrs as $attr) { |
|
| 100 | - if ($attr->name === 'path' && \is_string($attr->value)) { |
|
| 108 | + foreach ($tag->attrs as $attr) |
|
| 109 | + { |
|
| 110 | + if ($attr->name === 'path' && \is_string($attr->value)) |
|
| 111 | + { |
|
| 101 | 112 | return \trim($attr->value, '\'"'); |
| 102 | 113 | } |
| 103 | 114 | } |
@@ -22,24 +22,24 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | public function __construct( |
| 24 | 24 | private readonly BlockClaims $blocks |
| 25 | - ) { |
|
| 25 | + ){ |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
| 29 | 29 | { |
| 30 | - if (!$node instanceof Aggregate) { |
|
| 30 | + if (!$node instanceof Aggregate){ |
|
| 31 | 31 | return null; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - foreach ($this->blocks->getUnclaimed() as $name) { |
|
| 34 | + foreach ($this->blocks->getUnclaimed() as $name){ |
|
| 35 | 35 | $alias = $node->accepts($name); |
| 36 | - if ($alias === null) { |
|
| 36 | + if ($alias === null){ |
|
| 37 | 37 | continue; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $value = $this->blocks->claim($name); |
| 41 | 41 | |
| 42 | - if ($value instanceof QuotedValue) { |
|
| 42 | + if ($value instanceof QuotedValue){ |
|
| 43 | 43 | /** |
| 44 | 44 | * TODO issue #767 |
| 45 | 45 | * @link https://github.com/spiral/framework/issues/767 |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // simple copy attribute copy |
| 53 | - if ($value instanceof Attr) { |
|
| 53 | + if ($value instanceof Attr){ |
|
| 54 | 54 | /** |
| 55 | 55 | * TODO issue #767 |
| 56 | 56 | * @link https://github.com/spiral/framework/issues/767 |
@@ -27,19 +27,23 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
| 29 | 29 | { |
| 30 | - if (!$node instanceof Aggregate) { |
|
| 30 | + if (!$node instanceof Aggregate) |
|
| 31 | + { |
|
| 31 | 32 | return null; |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | - foreach ($this->blocks->getUnclaimed() as $name) { |
|
| 35 | + foreach ($this->blocks->getUnclaimed() as $name) |
|
| 36 | + { |
|
| 35 | 37 | $alias = $node->accepts($name); |
| 36 | - if ($alias === null) { |
|
| 38 | + if ($alias === null) |
|
| 39 | + { |
|
| 37 | 40 | continue; |
| 38 | 41 | } |
| 39 | 42 | |
| 40 | 43 | $value = $this->blocks->claim($name); |
| 41 | 44 | |
| 42 | - if ($value instanceof QuotedValue) { |
|
| 45 | + if ($value instanceof QuotedValue) |
|
| 46 | + { |
|
| 43 | 47 | /** |
| 44 | 48 | * TODO issue #767 |
| 45 | 49 | * @link https://github.com/spiral/framework/issues/767 |
@@ -50,7 +54,8 @@ discard block |
||
| 50 | 54 | } |
| 51 | 55 | |
| 52 | 56 | // simple copy attribute copy |
| 53 | - if ($value instanceof Attr) { |
|
| 57 | + if ($value instanceof Attr) |
|
| 58 | + { |
|
| 54 | 59 | /** |
| 55 | 60 | * TODO issue #767 |
| 56 | 61 | * @link https://github.com/spiral/framework/issues/767 |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | public function __construct( |
| 20 | 20 | private readonly BlockClaims $blocks |
| 21 | - ) { |
|
| 21 | + ){ |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
@@ -28,19 +28,19 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
| 30 | 30 | { |
| 31 | - if (!$node instanceof Block || $node->name === null || !$this->blocks->has($node->name)) { |
|
| 31 | + if (!$node instanceof Block || $node->name === null || !$this->blocks->has($node->name)){ |
|
| 32 | 32 | return null; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $inject = $this->blocks->claim($node->name); |
| 36 | 36 | |
| 37 | - if ($inject instanceof QuotedValue) { |
|
| 37 | + if ($inject instanceof QuotedValue){ |
|
| 38 | 38 | // exclude quotes |
| 39 | 39 | $inject = $inject->trimValue(); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // mount block:parent content |
| 43 | - if ($node->name !== 'parent') { |
|
| 43 | + if ($node->name !== 'parent'){ |
|
| 44 | 44 | $traverser = new Traverser(); |
| 45 | 45 | $traverser->addVisitor(new InjectBlocks(new BlockClaims([ |
| 46 | 46 | 'parent' => $node->nodes, |
@@ -28,19 +28,22 @@ |
||
| 28 | 28 | |
| 29 | 29 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
| 30 | 30 | { |
| 31 | - if (!$node instanceof Block || $node->name === null || !$this->blocks->has($node->name)) { |
|
| 31 | + if (!$node instanceof Block || $node->name === null || !$this->blocks->has($node->name)) |
|
| 32 | + { |
|
| 32 | 33 | return null; |
| 33 | 34 | } |
| 34 | 35 | |
| 35 | 36 | $inject = $this->blocks->claim($node->name); |
| 36 | 37 | |
| 37 | - if ($inject instanceof QuotedValue) { |
|
| 38 | + if ($inject instanceof QuotedValue) |
|
| 39 | + { |
|
| 38 | 40 | // exclude quotes |
| 39 | 41 | $inject = $inject->trimValue(); |
| 40 | 42 | } |
| 41 | 43 | |
| 42 | 44 | // mount block:parent content |
| 43 | - if ($node->name !== 'parent') { |
|
| 45 | + if ($node->name !== 'parent') |
|
| 46 | + { |
|
| 44 | 47 | $traverser = new Traverser(); |
| 45 | 48 | $traverser->addVisitor(new InjectBlocks(new BlockClaims([ |
| 46 | 49 | 'parent' => $node->nodes, |
@@ -42,15 +42,18 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | $php = new PHPMixin($node->tokens, self::PHP_MACRO_FUNCTION); |
| 45 | - foreach ($this->blocks->getNames() as $name) { |
|
| 45 | + foreach ($this->blocks->getNames() as $name) |
|
| 46 | + { |
|
| 46 | 47 | $block = $this->blocks->get($name); |
| 47 | 48 | |
| 48 | - if ($this->isReference($block)) { |
|
| 49 | + if ($this->isReference($block)) |
|
| 50 | + { |
|
| 49 | 51 | // resolved on later stage |
| 50 | 52 | continue; |
| 51 | 53 | } |
| 52 | 54 | |
| 53 | - if ($php->has($name)) { |
|
| 55 | + if ($php->has($name)) |
|
| 56 | + { |
|
| 54 | 57 | $php->set($name, $this->trimPHP($this->blocks->claim($name))); |
| 55 | 58 | } |
| 56 | 59 | } |
@@ -59,15 +62,18 @@ discard block |
||
| 59 | 62 | $node->tokens = \token_get_all($node->content); |
| 60 | 63 | |
| 61 | 64 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
| 62 | - foreach ($this->blocks->getNames() as $name) { |
|
| 65 | + foreach ($this->blocks->getNames() as $name) |
|
| 66 | + { |
|
| 63 | 67 | $block = $this->blocks->get($name); |
| 64 | 68 | |
| 65 | - if ($this->isReference($block)) { |
|
| 69 | + if ($this->isReference($block)) |
|
| 70 | + { |
|
| 66 | 71 | // resolved on later stage |
| 67 | 72 | continue; |
| 68 | 73 | } |
| 69 | 74 | |
| 70 | - if ($exists->has($name)) { |
|
| 75 | + if ($exists->has($name)) |
|
| 76 | + { |
|
| 71 | 77 | $exists->set($name, 'true'); |
| 72 | 78 | } |
| 73 | 79 | } |
@@ -85,10 +91,13 @@ discard block |
||
| 85 | 91 | |
| 86 | 92 | private function isReference(mixed $node): bool |
| 87 | 93 | { |
| 88 | - switch (true) { |
|
| 94 | + switch (true) |
|
| 95 | + { |
|
| 89 | 96 | case \is_array($node): |
| 90 | - foreach ($node as $child) { |
|
| 91 | - if ($this->isReference($child)) { |
|
| 97 | + foreach ($node as $child) |
|
| 98 | + { |
|
| 99 | + if ($this->isReference($child)) |
|
| 100 | + { |
|
| 92 | 101 | return true; |
| 93 | 102 | } |
| 94 | 103 | } |
@@ -99,8 +108,10 @@ discard block |
||
| 99 | 108 | return $this->isReference($node->getValue()); |
| 100 | 109 | |
| 101 | 110 | case $node instanceof Mixin: |
| 102 | - foreach ($node->nodes as $child) { |
|
| 103 | - if ($this->isReference($child)) { |
|
| 111 | + foreach ($node->nodes as $child) |
|
| 112 | + { |
|
| 113 | + if ($this->isReference($child)) |
|
| 114 | + { |
|
| 104 | 115 | return true; |
| 105 | 116 | } |
| 106 | 117 | } |
@@ -116,10 +127,12 @@ discard block |
||
| 116 | 127 | |
| 117 | 128 | private function trimPHP(mixed $node): string |
| 118 | 129 | { |
| 119 | - switch (true) { |
|
| 130 | + switch (true) |
|
| 131 | + { |
|
| 120 | 132 | case \is_array($node): |
| 121 | 133 | $result = []; |
| 122 | - foreach ($node as $child) { |
|
| 134 | + foreach ($node as $child) |
|
| 135 | + { |
|
| 123 | 136 | $result[] = $this->trimPHP($child); |
| 124 | 137 | } |
| 125 | 138 | |
@@ -127,7 +140,8 @@ discard block |
||
| 127 | 140 | |
| 128 | 141 | case $node instanceof Mixin: |
| 129 | 142 | $result = []; |
| 130 | - foreach ($node->nodes as $child) { |
|
| 143 | + foreach ($node->nodes as $child) |
|
| 144 | + { |
|
| 131 | 145 | $result[] = $this->trimPHP($child); |
| 132 | 146 | } |
| 133 | 147 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | public function __construct( |
| 28 | 28 | private readonly BlockClaims $blocks |
| 29 | - ) { |
|
| 29 | + ){ |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
@@ -37,20 +37,20 @@ discard block |
||
| 37 | 37 | !\str_contains($node->content, self::PHP_MACRO_FUNCTION) |
| 38 | 38 | && !\str_contains($node->content, self::PHP_MARCO_EXISTS_FUNCTION) |
| 39 | 39 | ) |
| 40 | - ) { |
|
| 40 | + ){ |
|
| 41 | 41 | return null; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | $php = new PHPMixin($node->tokens, self::PHP_MACRO_FUNCTION); |
| 45 | - foreach ($this->blocks->getNames() as $name) { |
|
| 45 | + foreach ($this->blocks->getNames() as $name){ |
|
| 46 | 46 | $block = $this->blocks->get($name); |
| 47 | 47 | |
| 48 | - if ($this->isReference($block)) { |
|
| 48 | + if ($this->isReference($block)){ |
|
| 49 | 49 | // resolved on later stage |
| 50 | 50 | continue; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if ($php->has($name)) { |
|
| 53 | + if ($php->has($name)){ |
|
| 54 | 54 | $php->set($name, $this->trimPHP($this->blocks->claim($name))); |
| 55 | 55 | } |
| 56 | 56 | } |
@@ -59,15 +59,15 @@ discard block |
||
| 59 | 59 | $node->tokens = \token_get_all($node->content); |
| 60 | 60 | |
| 61 | 61 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
| 62 | - foreach ($this->blocks->getNames() as $name) { |
|
| 62 | + foreach ($this->blocks->getNames() as $name){ |
|
| 63 | 63 | $block = $this->blocks->get($name); |
| 64 | 64 | |
| 65 | - if ($this->isReference($block)) { |
|
| 65 | + if ($this->isReference($block)){ |
|
| 66 | 66 | // resolved on later stage |
| 67 | 67 | continue; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if ($exists->has($name)) { |
|
| 70 | + if ($exists->has($name)){ |
|
| 71 | 71 | $exists->set($name, 'true'); |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -85,10 +85,10 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | private function isReference(mixed $node): bool |
| 87 | 87 | { |
| 88 | - switch (true) { |
|
| 88 | + switch (true){ |
|
| 89 | 89 | case \is_array($node): |
| 90 | - foreach ($node as $child) { |
|
| 91 | - if ($this->isReference($child)) { |
|
| 90 | + foreach ($node as $child){ |
|
| 91 | + if ($this->isReference($child)){ |
|
| 92 | 92 | return true; |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | return $this->isReference($node->getValue()); |
| 100 | 100 | |
| 101 | 101 | case $node instanceof Mixin: |
| 102 | - foreach ($node->nodes as $child) { |
|
| 103 | - if ($this->isReference($child)) { |
|
| 102 | + foreach ($node->nodes as $child){ |
|
| 103 | + if ($this->isReference($child)){ |
|
| 104 | 104 | return true; |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -116,10 +116,10 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | private function trimPHP(mixed $node): string |
| 118 | 118 | { |
| 119 | - switch (true) { |
|
| 119 | + switch (true){ |
|
| 120 | 120 | case \is_array($node): |
| 121 | 121 | $result = []; |
| 122 | - foreach ($node as $child) { |
|
| 122 | + foreach ($node as $child){ |
|
| 123 | 123 | $result[] = $this->trimPHP($child); |
| 124 | 124 | } |
| 125 | 125 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | case $node instanceof Mixin: |
| 129 | 129 | $result = []; |
| 130 | - foreach ($node->nodes as $child) { |
|
| 130 | + foreach ($node->nodes as $child){ |
|
| 131 | 131 | $result[] = $this->trimPHP($child); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | return $this->exportValue($node); |
| 138 | 138 | |
| 139 | 139 | case $node instanceof Output: |
| 140 | - return \trim((string) $node->body); |
|
| 140 | + return \trim((string)$node->body); |
|
| 141 | 141 | |
| 142 | 142 | case $node instanceof PHP: |
| 143 | 143 | return $node->getContext()?->getValue(PHP::ORIGINAL_BODY) |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | return match (true) { |
| 157 | 157 | \strtolower($value) === 'true' => 'true', |
| 158 | 158 | \strtolower($value) === 'false' => 'false', |
| 159 | - \is_float($value) || \is_numeric($value) => (string) $value, |
|
| 159 | + \is_float($value) || \is_numeric($value) => (string)$value, |
|
| 160 | 160 | default => \var_export($node->content, true), |
| 161 | 161 | }; |
| 162 | 162 | } |