@@ -16,8 +16,8 @@ |
||
| 16 | 16 | |
| 17 | 17 | public function enterNode(Node $node): void |
| 18 | 18 | { |
| 19 | - if ($node instanceof Node\Stmt\Use_) { |
|
| 20 | - foreach ($node->uses as $use) { |
|
| 19 | + if ($node instanceof Node\Stmt\Use_){ |
|
| 20 | + foreach ($node->uses as $use){ |
|
| 21 | 21 | $this->imports[] = [ |
| 22 | 22 | 'name' => \implode('\\', $use->name->parts), |
| 23 | 23 | 'alias' => $use->alias->name ?? null, |
@@ -16,8 +16,10 @@ |
||
| 16 | 16 | |
| 17 | 17 | public function enterNode(Node $node): void |
| 18 | 18 | { |
| 19 | - if ($node instanceof Node\Stmt\Use_) { |
|
| 20 | - foreach ($node->uses as $use) { |
|
| 19 | + if ($node instanceof Node\Stmt\Use_) |
|
| 20 | + { |
|
| 21 | + foreach ($node->uses as $use) |
|
| 22 | + { |
|
| 21 | 23 | $this->imports[] = [ |
| 22 | 24 | 'name' => \implode('\\', $use->name->parts), |
| 23 | 25 | 'alias' => $use->alias->name ?? null, |
@@ -15,11 +15,11 @@ |
||
| 15 | 15 | |
| 16 | 16 | public function enterNode(Node $node): ?int |
| 17 | 17 | { |
| 18 | - if ($node instanceof Node\Stmt\Namespace_) { |
|
| 18 | + if ($node instanceof Node\Stmt\Namespace_){ |
|
| 19 | 19 | $this->namespace = \implode('\\', $node->name->parts); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - if ($node instanceof Node\Stmt\Class_) { |
|
| 22 | + if ($node instanceof Node\Stmt\Class_){ |
|
| 23 | 23 | $this->class = $node->name->name; |
| 24 | 24 | |
| 25 | 25 | return NodeTraverser::STOP_TRAVERSAL; |
@@ -15,11 +15,13 @@ |
||
| 15 | 15 | |
| 16 | 16 | public function enterNode(Node $node): ?int |
| 17 | 17 | { |
| 18 | - if ($node instanceof Node\Stmt\Namespace_) { |
|
| 18 | + if ($node instanceof Node\Stmt\Namespace_) |
|
| 19 | + { |
|
| 19 | 20 | $this->namespace = \implode('\\', $node->name->parts); |
| 20 | 21 | } |
| 21 | 22 | |
| 22 | - if ($node instanceof Node\Stmt\Class_) { |
|
| 23 | + if ($node instanceof Node\Stmt\Class_) |
|
| 24 | + { |
|
| 23 | 25 | $this->class = $node->name->name; |
| 24 | 26 | |
| 25 | 27 | return NodeTraverser::STOP_TRAVERSAL; |
@@ -18,17 +18,17 @@ discard block |
||
| 18 | 18 | private readonly ClassNode $definition, |
| 19 | 19 | private readonly bool $useTypedProperties = false, |
| 20 | 20 | private readonly bool $noPhpDoc = false |
| 21 | - ) { |
|
| 21 | + ){ |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function leaveNode(Node $node): ?Node |
| 25 | 25 | { |
| 26 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 26 | + if (!$node instanceof Node\Stmt\Class_){ |
|
| 27 | 27 | return null; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | $nodes = []; |
| 31 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 31 | + foreach ($this->definition->dependencies as $dependency){ |
|
| 32 | 32 | $nodes[] = $this->buildProperty($dependency); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | private function definePlacementID(Node\Stmt\Class_ $node): int |
| 42 | 42 | { |
| 43 | - foreach ($node->stmts as $index => $child) { |
|
| 44 | - if ($child instanceof Node\Stmt\ClassMethod || $child instanceof Node\Stmt\Property) { |
|
| 43 | + foreach ($node->stmts as $index => $child){ |
|
| 44 | + if ($child instanceof Node\Stmt\ClassMethod || $child instanceof Node\Stmt\Property){ |
|
| 45 | 45 | return $index; |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | $b = new Property($dependency->property); |
| 55 | 55 | $b->makePrivate(); |
| 56 | 56 | |
| 57 | - if ($this->useTypedProperty()) { |
|
| 57 | + if ($this->useTypedProperty()){ |
|
| 58 | 58 | $b->setType($this->getPropertyType($dependency)); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - if ($this->renderDoc()) { |
|
| 61 | + if ($this->renderDoc()){ |
|
| 62 | 62 | $b->setDocComment(new Doc(\sprintf('/** @var %s */', $this->getPropertyType($dependency)))); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | private function getPropertyType(Dependency $dependency): string |
| 79 | 79 | { |
| 80 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 81 | - if (($stmt->name === $dependency->type->fullName) && $stmt->alias) { |
|
| 80 | + foreach ($this->definition->getStmts() as $stmt){ |
|
| 81 | + if (($stmt->name === $dependency->type->fullName) && $stmt->alias){ |
|
| 82 | 82 | return $stmt->alias; |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -23,12 +23,14 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | public function leaveNode(Node $node): ?Node |
| 25 | 25 | { |
| 26 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 26 | + if (!$node instanceof Node\Stmt\Class_) |
|
| 27 | + { |
|
| 27 | 28 | return null; |
| 28 | 29 | } |
| 29 | 30 | |
| 30 | 31 | $nodes = []; |
| 31 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 32 | + foreach ($this->definition->dependencies as $dependency) |
|
| 33 | + { |
|
| 32 | 34 | $nodes[] = $this->buildProperty($dependency); |
| 33 | 35 | } |
| 34 | 36 | |
@@ -40,8 +42,10 @@ discard block |
||
| 40 | 42 | |
| 41 | 43 | private function definePlacementID(Node\Stmt\Class_ $node): int |
| 42 | 44 | { |
| 43 | - foreach ($node->stmts as $index => $child) { |
|
| 44 | - if ($child instanceof Node\Stmt\ClassMethod || $child instanceof Node\Stmt\Property) { |
|
| 45 | + foreach ($node->stmts as $index => $child) |
|
| 46 | + { |
|
| 47 | + if ($child instanceof Node\Stmt\ClassMethod || $child instanceof Node\Stmt\Property) |
|
| 48 | + { |
|
| 45 | 49 | return $index; |
| 46 | 50 | } |
| 47 | 51 | } |
@@ -54,11 +58,13 @@ discard block |
||
| 54 | 58 | $b = new Property($dependency->property); |
| 55 | 59 | $b->makePrivate(); |
| 56 | 60 | |
| 57 | - if ($this->useTypedProperty()) { |
|
| 61 | + if ($this->useTypedProperty()) |
|
| 62 | + { |
|
| 58 | 63 | $b->setType($this->getPropertyType($dependency)); |
| 59 | 64 | } |
| 60 | 65 | |
| 61 | - if ($this->renderDoc()) { |
|
| 66 | + if ($this->renderDoc()) |
|
| 67 | + { |
|
| 62 | 68 | $b->setDocComment(new Doc(\sprintf('/** @var %s */', $this->getPropertyType($dependency)))); |
| 63 | 69 | } |
| 64 | 70 | |
@@ -77,8 +83,10 @@ discard block |
||
| 77 | 83 | |
| 78 | 84 | private function getPropertyType(Dependency $dependency): string |
| 79 | 85 | { |
| 80 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 81 | - if (($stmt->name === $dependency->type->fullName) && $stmt->alias) { |
|
| 86 | + foreach ($this->definition->getStmts() as $stmt) |
|
| 87 | + { |
|
| 88 | + if (($stmt->name === $dependency->type->fullName) && $stmt->alias) |
|
| 89 | + { |
|
| 82 | 90 | return $stmt->alias; |
| 83 | 91 | } |
| 84 | 92 | } |
@@ -15,28 +15,28 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | final class RemoveTrait extends NodeVisitorAbstract |
| 17 | 17 | { |
| 18 | - public function leaveNode(Node $node): int|Node|null |
|
| 18 | + public function leaveNode(Node $node): int | Node | null |
|
| 19 | 19 | { |
| 20 | - if (!$node instanceof Node\Stmt\TraitUse) { |
|
| 20 | + if (!$node instanceof Node\Stmt\TraitUse){ |
|
| 21 | 21 | return null; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - foreach ($node->traits as $index => $use) { |
|
| 25 | - if ($use instanceof Node\Name) { |
|
| 24 | + foreach ($node->traits as $index => $use){ |
|
| 25 | + if ($use instanceof Node\Name){ |
|
| 26 | 26 | $name = $this->trimSlashes(\implode('\\', $use->parts)); |
| 27 | 27 | if ( |
| 28 | 28 | \in_array($name, [ |
| 29 | 29 | $this->trimSlashes(PrototypeTrait::class), |
| 30 | 30 | Utils::shortName(PrototypeTrait::class), |
| 31 | 31 | ], true) |
| 32 | - ) { |
|
| 32 | + ){ |
|
| 33 | 33 | unset($node->traits[$index]); |
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | $node->traits = \array_values($node->traits); |
| 39 | - if (empty($node->traits)) { |
|
| 39 | + if (empty($node->traits)){ |
|
| 40 | 40 | return NodeTraverser::REMOVE_NODE; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -17,12 +17,15 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | public function leaveNode(Node $node): int|Node|null |
| 19 | 19 | { |
| 20 | - if (!$node instanceof Node\Stmt\TraitUse) { |
|
| 20 | + if (!$node instanceof Node\Stmt\TraitUse) |
|
| 21 | + { |
|
| 21 | 22 | return null; |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | - foreach ($node->traits as $index => $use) { |
|
| 25 | - if ($use instanceof Node\Name) { |
|
| 25 | + foreach ($node->traits as $index => $use) |
|
| 26 | + { |
|
| 27 | + if ($use instanceof Node\Name) |
|
| 28 | + { |
|
| 26 | 29 | $name = $this->trimSlashes(\implode('\\', $use->parts)); |
| 27 | 30 | if ( |
| 28 | 31 | \in_array($name, [ |
@@ -36,7 +39,8 @@ discard block |
||
| 36 | 39 | } |
| 37 | 40 | |
| 38 | 41 | $node->traits = \array_values($node->traits); |
| 39 | - if (empty($node->traits)) { |
|
| 42 | + if (empty($node->traits)) |
|
| 43 | + { |
|
| 40 | 44 | return NodeTraverser::REMOVE_NODE; |
| 41 | 45 | } |
| 42 | 46 | |
@@ -14,19 +14,19 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | final class RemoveUse extends NodeVisitorAbstract |
| 16 | 16 | { |
| 17 | - public function leaveNode(Node $node): int|Node|null |
|
| 17 | + public function leaveNode(Node $node): int | Node | null |
|
| 18 | 18 | { |
| 19 | - if (!$node instanceof Node\Stmt\Use_) { |
|
| 19 | + if (!$node instanceof Node\Stmt\Use_){ |
|
| 20 | 20 | return null; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - foreach ($node->uses as $index => $use) { |
|
| 24 | - if ($use->name->toString() === PrototypeTrait::class) { |
|
| 23 | + foreach ($node->uses as $index => $use){ |
|
| 24 | + if ($use->name->toString() === PrototypeTrait::class){ |
|
| 25 | 25 | unset($node->uses[$index]); |
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if (empty($node->uses)) { |
|
| 29 | + if (empty($node->uses)){ |
|
| 30 | 30 | return NodeTraverser::REMOVE_NODE; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -16,17 +16,21 @@ |
||
| 16 | 16 | { |
| 17 | 17 | public function leaveNode(Node $node): int|Node|null |
| 18 | 18 | { |
| 19 | - if (!$node instanceof Node\Stmt\Use_) { |
|
| 19 | + if (!$node instanceof Node\Stmt\Use_) |
|
| 20 | + { |
|
| 20 | 21 | return null; |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | - foreach ($node->uses as $index => $use) { |
|
| 24 | - if ($use->name->toString() === PrototypeTrait::class) { |
|
| 24 | + foreach ($node->uses as $index => $use) |
|
| 25 | + { |
|
| 26 | + if ($use->name->toString() === PrototypeTrait::class) |
|
| 27 | + { |
|
| 25 | 28 | unset($node->uses[$index]); |
| 26 | 29 | } |
| 27 | 30 | } |
| 28 | 31 | |
| 29 | - if (empty($node->uses)) { |
|
| 32 | + if (empty($node->uses)) |
|
| 33 | + { |
|
| 30 | 34 | return NodeTraverser::REMOVE_NODE; |
| 31 | 35 | } |
| 32 | 36 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | public function __construct( |
| 20 | 20 | private readonly ContainerInterface $container |
| 21 | - ) { |
|
| 21 | + ){ |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -40,18 +40,18 @@ discard block |
||
| 40 | 40 | /** |
| 41 | 41 | * Resolves the name of prototype dependency into target class name. |
| 42 | 42 | */ |
| 43 | - public function resolveProperty(string $name): Dependency|ContainerExceptionInterface|null |
|
| 43 | + public function resolveProperty(string $name): Dependency | ContainerExceptionInterface | null |
|
| 44 | 44 | { |
| 45 | 45 | $dependency = $this->dependencies[$name] ?? null; |
| 46 | - if ($dependency === null) { |
|
| 46 | + if ($dependency === null){ |
|
| 47 | 47 | return null; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - try { |
|
| 50 | + try{ |
|
| 51 | 51 | $this->container->get($dependency->type->name()); |
| 52 | 52 | |
| 53 | 53 | return $dependency; |
| 54 | - } catch (ContainerExceptionInterface $e) { |
|
| 54 | + }catch (ContainerExceptionInterface $e){ |
|
| 55 | 55 | return $e; |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -43,15 +43,19 @@ |
||
| 43 | 43 | public function resolveProperty(string $name): Dependency|ContainerExceptionInterface|null |
| 44 | 44 | { |
| 45 | 45 | $dependency = $this->dependencies[$name] ?? null; |
| 46 | - if ($dependency === null) { |
|
| 46 | + if ($dependency === null) |
|
| 47 | + { |
|
| 47 | 48 | return null; |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | - try { |
|
| 51 | + try |
|
| 52 | + { |
|
| 51 | 53 | $this->container->get($dependency->type->name()); |
| 52 | 54 | |
| 53 | 55 | return $dependency; |
| 54 | - } catch (ContainerExceptionInterface $e) { |
|
| 56 | + } |
|
| 57 | + catch (ContainerExceptionInterface $e) |
|
| 58 | + { |
|
| 55 | 59 | return $e; |
| 56 | 60 | } |
| 57 | 61 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | public function __get(string $name): mixed |
| 24 | 24 | { |
| 25 | 25 | $container = ContainerScope::getContainer(); |
| 26 | - if ($container === null || !$container->has(PrototypeRegistry::class)) { |
|
| 26 | + if ($container === null || !$container->has(PrototypeRegistry::class)){ |
|
| 27 | 27 | throw new ScopeException( |
| 28 | 28 | \sprintf('Unable to resolve prototyped dependency `%s`, invalid container scope', $name) |
| 29 | 29 | ); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $target === null || |
| 38 | 38 | $target instanceof \Throwable || |
| 39 | 39 | $target->type->fullName === null |
| 40 | - ) { |
|
| 40 | + ){ |
|
| 41 | 41 | throw new PrototypeException( |
| 42 | 42 | \sprintf('Undefined prototype property `%s`', $name), |
| 43 | 43 | 0, |
@@ -23,7 +23,8 @@ |
||
| 23 | 23 | public function __get(string $name): mixed |
| 24 | 24 | { |
| 25 | 25 | $container = ContainerScope::getContainer(); |
| 26 | - if ($container === null || !$container->has(PrototypeRegistry::class)) { |
|
| 26 | + if ($container === null || !$container->has(PrototypeRegistry::class)) |
|
| 27 | + { |
|
| 27 | 28 | throw new ScopeException( |
| 28 | 29 | \sprintf('Unable to resolve prototyped dependency `%s`, invalid container scope', $name) |
| 29 | 30 | ); |
@@ -13,13 +13,13 @@ discard block |
||
| 13 | 13 | private function __construct( |
| 14 | 14 | public readonly string $shortName, |
| 15 | 15 | public readonly ?string $fullName = null, |
| 16 | - ) { |
|
| 16 | + ){ |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public static function create(string $name): Type |
| 20 | 20 | { |
| 21 | 21 | $fullName = null; |
| 22 | - if (Utils::hasShortName($name)) { |
|
| 22 | + if (Utils::hasShortName($name)){ |
|
| 23 | 23 | $fullName = $name; |
| 24 | 24 | $name = Utils::shortName($name); |
| 25 | 25 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | public function getSlashedShortName(bool $builtIn): string |
| 36 | 36 | { |
| 37 | 37 | $type = $this->shortName; |
| 38 | - if (!$builtIn && !$this->fullName) { |
|
| 38 | + if (!$builtIn && !$this->fullName){ |
|
| 39 | 39 | $type = "\\$type"; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -19,7 +19,8 @@ discard block |
||
| 19 | 19 | public static function create(string $name): Type |
| 20 | 20 | { |
| 21 | 21 | $fullName = null; |
| 22 | - if (Utils::hasShortName($name)) { |
|
| 22 | + if (Utils::hasShortName($name)) |
|
| 23 | + { |
|
| 23 | 24 | $fullName = $name; |
| 24 | 25 | $name = Utils::shortName($name); |
| 25 | 26 | } |
@@ -35,7 +36,8 @@ discard block |
||
| 35 | 36 | public function getSlashedShortName(bool $builtIn): string |
| 36 | 37 | { |
| 37 | 38 | $type = $this->shortName; |
| 38 | - if (!$builtIn && !$this->fullName) { |
|
| 39 | + if (!$builtIn && !$this->fullName) |
|
| 40 | + { |
|
| 39 | 41 | $type = "\\$type"; |
| 40 | 42 | } |
| 41 | 43 | |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | |
| 19 | 19 | public function __toString(): string |
| 20 | 20 | { |
| 21 | - if ($this->alias) { |
|
| 21 | + if ($this->alias){ |
|
| 22 | 22 | return \sprintf('%s as %s', $this->name, $this->alias); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -18,7 +18,8 @@ |
||
| 18 | 18 | |
| 19 | 19 | public function __toString(): string |
| 20 | 20 | { |
| 21 | - if ($this->alias) { |
|
| 21 | + if ($this->alias) |
|
| 22 | + { |
|
| 22 | 23 | return \sprintf('%s as %s', $this->name, $this->alias); |
| 23 | 24 | } |
| 24 | 25 | |