@@ -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 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | { |
| 12 | 12 | public function __construct( |
| 13 | 13 | private readonly Sequences $sequences |
| 14 | - ) { |
|
| 14 | + ){ |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | public function resolve(ClassNode $definition): void |
@@ -32,8 +32,8 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | private function getReservedNamespacesWithAlias(ClassNode $definition, array $namespaces): array |
| 34 | 34 | { |
| 35 | - foreach ($definition->getStmts() as $stmt) { |
|
| 36 | - if (!$stmt->alias) { |
|
| 35 | + foreach ($definition->getStmts() as $stmt){ |
|
| 36 | + if (!$stmt->alias){ |
|
| 37 | 37 | continue; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | private function getReservedNamespacesWithoutAlias(ClassNode $definition, array $namespaces): array |
| 47 | 47 | { |
| 48 | - foreach ($definition->getStmts() as $stmt) { |
|
| 49 | - if ($stmt->alias || isset($namespaces[$stmt->shortName])) { |
|
| 48 | + foreach ($definition->getStmts() as $stmt){ |
|
| 49 | + if ($stmt->alias || isset($namespaces[$stmt->shortName])){ |
|
| 50 | 50 | continue; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | private function initiateCounters(array $namespaces): array |
| 60 | 60 | { |
| 61 | 61 | $counters = []; |
| 62 | - foreach ($namespaces as $shortName => $fullName) { |
|
| 62 | + foreach ($namespaces as $shortName => $fullName){ |
|
| 63 | 63 | $namespace = $this->parseNamespace($shortName, $fullName); |
| 64 | 64 | |
| 65 | - if (isset($counters[$namespace->name])) { |
|
| 65 | + if (isset($counters[$namespace->name])){ |
|
| 66 | 66 | $counters[$namespace->name][$namespace->sequence] = $namespace; |
| 67 | - } else { |
|
| 67 | + }else{ |
|
| 68 | 68 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -74,52 +74,52 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | private function resolveImportsNamespaces(ClassNode $definition, array $counters): void |
| 76 | 76 | { |
| 77 | - if (!$definition->hasConstructor && $definition->constructorParams) { |
|
| 78 | - foreach ($definition->constructorParams as $param) { |
|
| 77 | + if (!$definition->hasConstructor && $definition->constructorParams){ |
|
| 78 | + foreach ($definition->constructorParams as $param){ |
|
| 79 | 79 | //no type (or type is internal), do nothing |
| 80 | - if (empty($param->type) || $param->isBuiltIn()) { |
|
| 80 | + if (empty($param->type) || $param->isBuiltIn()){ |
|
| 81 | 81 | continue; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | $namespace = $this->parseNamespaceFromType($param->type); |
| 85 | - if (isset($counters[$namespace->name])) { |
|
| 86 | - if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) { |
|
| 85 | + if (isset($counters[$namespace->name])){ |
|
| 86 | + if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)){ |
|
| 87 | 87 | continue; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | $sequence = $this->sequences->find(\array_keys($counters[$namespace->name]), $namespace->sequence); |
| 91 | - if ($sequence !== $namespace->sequence) { |
|
| 91 | + if ($sequence !== $namespace->sequence){ |
|
| 92 | 92 | $namespace->sequence = $sequence; |
| 93 | 93 | |
| 94 | 94 | $param->type->alias = $namespace->fullName(); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $counters[$namespace->name][$sequence] = $namespace; |
| 98 | - } else { |
|
| 98 | + }else{ |
|
| 99 | 99 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - foreach ($definition->dependencies as $dependency) { |
|
| 104 | + foreach ($definition->dependencies as $dependency){ |
|
| 105 | 105 | $namespace = $this->parseNamespaceFromType($dependency->type); |
| 106 | - if (isset($counters[$namespace->name])) { |
|
| 106 | + if (isset($counters[$namespace->name])){ |
|
| 107 | 107 | $alreadyImported = $this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace); |
| 108 | - if ($alreadyImported !== null) { |
|
| 108 | + if ($alreadyImported !== null){ |
|
| 109 | 109 | $dependency->type->alias = $alreadyImported->fullName(); |
| 110 | 110 | |
| 111 | 111 | continue; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $sequence = $this->sequences->find(\array_keys($counters[$namespace->name]), $namespace->sequence); |
| 115 | - if ($sequence !== $namespace->sequence) { |
|
| 115 | + if ($sequence !== $namespace->sequence){ |
|
| 116 | 116 | $namespace->sequence = $sequence; |
| 117 | 117 | |
| 118 | 118 | $dependency->type->alias = $namespace->fullName(); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $counters[$namespace->name][$sequence] = $namespace; |
| 122 | - } else { |
|
| 122 | + }else{ |
|
| 123 | 123 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -130,8 +130,8 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | private function getAlreadyImportedNamespace(array $counters, NamespaceEntity $namespace): ?NamespaceEntity |
| 132 | 132 | { |
| 133 | - foreach ($counters as $counter) { |
|
| 134 | - if ($counter->equals($namespace)) { |
|
| 133 | + foreach ($counters as $counter){ |
|
| 134 | + if ($counter->equals($namespace)){ |
|
| 135 | 135 | return $counter; |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -146,9 +146,9 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | private function parseNamespace(string $shortName, string $fullName): NamespaceEntity |
| 148 | 148 | { |
| 149 | - if (\preg_match("/\d+$/", $shortName, $match)) { |
|
| 149 | + if (\preg_match("/\d+$/", $shortName, $match)){ |
|
| 150 | 150 | $sequence = (int)$match[0]; |
| 151 | - if ($sequence > 0) { |
|
| 151 | + if ($sequence > 0){ |
|
| 152 | 152 | return NamespaceEntity::createWithSequence( |
| 153 | 153 | Utils::trimTrailingDigits($shortName, $sequence), |
| 154 | 154 | $fullName, |
@@ -32,8 +32,10 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | private function getReservedNamespacesWithAlias(ClassNode $definition, array $namespaces): array |
| 34 | 34 | { |
| 35 | - foreach ($definition->getStmts() as $stmt) { |
|
| 36 | - if (!$stmt->alias) { |
|
| 35 | + foreach ($definition->getStmts() as $stmt) |
|
| 36 | + { |
|
| 37 | + if (!$stmt->alias) |
|
| 38 | + { |
|
| 37 | 39 | continue; |
| 38 | 40 | } |
| 39 | 41 | |
@@ -45,8 +47,10 @@ discard block |
||
| 45 | 47 | |
| 46 | 48 | private function getReservedNamespacesWithoutAlias(ClassNode $definition, array $namespaces): array |
| 47 | 49 | { |
| 48 | - foreach ($definition->getStmts() as $stmt) { |
|
| 49 | - if ($stmt->alias || isset($namespaces[$stmt->shortName])) { |
|
| 50 | + foreach ($definition->getStmts() as $stmt) |
|
| 51 | + { |
|
| 52 | + if ($stmt->alias || isset($namespaces[$stmt->shortName])) |
|
| 53 | + { |
|
| 50 | 54 | continue; |
| 51 | 55 | } |
| 52 | 56 | |
@@ -59,12 +63,16 @@ discard block |
||
| 59 | 63 | private function initiateCounters(array $namespaces): array |
| 60 | 64 | { |
| 61 | 65 | $counters = []; |
| 62 | - foreach ($namespaces as $shortName => $fullName) { |
|
| 66 | + foreach ($namespaces as $shortName => $fullName) |
|
| 67 | + { |
|
| 63 | 68 | $namespace = $this->parseNamespace($shortName, $fullName); |
| 64 | 69 | |
| 65 | - if (isset($counters[$namespace->name])) { |
|
| 70 | + if (isset($counters[$namespace->name])) |
|
| 71 | + { |
|
| 66 | 72 | $counters[$namespace->name][$namespace->sequence] = $namespace; |
| 67 | - } else { |
|
| 73 | + } |
|
| 74 | + else |
|
| 75 | + { |
|
| 68 | 76 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
| 69 | 77 | } |
| 70 | 78 | } |
@@ -74,52 +82,66 @@ discard block |
||
| 74 | 82 | |
| 75 | 83 | private function resolveImportsNamespaces(ClassNode $definition, array $counters): void |
| 76 | 84 | { |
| 77 | - if (!$definition->hasConstructor && $definition->constructorParams) { |
|
| 78 | - foreach ($definition->constructorParams as $param) { |
|
| 85 | + if (!$definition->hasConstructor && $definition->constructorParams) |
|
| 86 | + { |
|
| 87 | + foreach ($definition->constructorParams as $param) |
|
| 88 | + { |
|
| 79 | 89 | //no type (or type is internal), do nothing |
| 80 | - if (empty($param->type) || $param->isBuiltIn()) { |
|
| 90 | + if (empty($param->type) || $param->isBuiltIn()) |
|
| 91 | + { |
|
| 81 | 92 | continue; |
| 82 | 93 | } |
| 83 | 94 | |
| 84 | 95 | $namespace = $this->parseNamespaceFromType($param->type); |
| 85 | - if (isset($counters[$namespace->name])) { |
|
| 86 | - if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) { |
|
| 96 | + if (isset($counters[$namespace->name])) |
|
| 97 | + { |
|
| 98 | + if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) |
|
| 99 | + { |
|
| 87 | 100 | continue; |
| 88 | 101 | } |
| 89 | 102 | |
| 90 | 103 | $sequence = $this->sequences->find(\array_keys($counters[$namespace->name]), $namespace->sequence); |
| 91 | - if ($sequence !== $namespace->sequence) { |
|
| 104 | + if ($sequence !== $namespace->sequence) |
|
| 105 | + { |
|
| 92 | 106 | $namespace->sequence = $sequence; |
| 93 | 107 | |
| 94 | 108 | $param->type->alias = $namespace->fullName(); |
| 95 | 109 | } |
| 96 | 110 | |
| 97 | 111 | $counters[$namespace->name][$sequence] = $namespace; |
| 98 | - } else { |
|
| 112 | + } |
|
| 113 | + else |
|
| 114 | + { |
|
| 99 | 115 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
| 100 | 116 | } |
| 101 | 117 | } |
| 102 | 118 | } |
| 103 | 119 | |
| 104 | - foreach ($definition->dependencies as $dependency) { |
|
| 120 | + foreach ($definition->dependencies as $dependency) |
|
| 121 | + { |
|
| 105 | 122 | $namespace = $this->parseNamespaceFromType($dependency->type); |
| 106 | - if (isset($counters[$namespace->name])) { |
|
| 123 | + if (isset($counters[$namespace->name])) |
|
| 124 | + { |
|
| 107 | 125 | $alreadyImported = $this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace); |
| 108 | - if ($alreadyImported !== null) { |
|
| 126 | + if ($alreadyImported !== null) |
|
| 127 | + { |
|
| 109 | 128 | $dependency->type->alias = $alreadyImported->fullName(); |
| 110 | 129 | |
| 111 | 130 | continue; |
| 112 | 131 | } |
| 113 | 132 | |
| 114 | 133 | $sequence = $this->sequences->find(\array_keys($counters[$namespace->name]), $namespace->sequence); |
| 115 | - if ($sequence !== $namespace->sequence) { |
|
| 134 | + if ($sequence !== $namespace->sequence) |
|
| 135 | + { |
|
| 116 | 136 | $namespace->sequence = $sequence; |
| 117 | 137 | |
| 118 | 138 | $dependency->type->alias = $namespace->fullName(); |
| 119 | 139 | } |
| 120 | 140 | |
| 121 | 141 | $counters[$namespace->name][$sequence] = $namespace; |
| 122 | - } else { |
|
| 142 | + } |
|
| 143 | + else |
|
| 144 | + { |
|
| 123 | 145 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
| 124 | 146 | } |
| 125 | 147 | } |
@@ -130,8 +152,10 @@ discard block |
||
| 130 | 152 | */ |
| 131 | 153 | private function getAlreadyImportedNamespace(array $counters, NamespaceEntity $namespace): ?NamespaceEntity |
| 132 | 154 | { |
| 133 | - foreach ($counters as $counter) { |
|
| 134 | - if ($counter->equals($namespace)) { |
|
| 155 | + foreach ($counters as $counter) |
|
| 156 | + { |
|
| 157 | + if ($counter->equals($namespace)) |
|
| 158 | + { |
|
| 135 | 159 | return $counter; |
| 136 | 160 | } |
| 137 | 161 | } |
@@ -146,9 +170,11 @@ discard block |
||
| 146 | 170 | |
| 147 | 171 | private function parseNamespace(string $shortName, string $fullName): NamespaceEntity |
| 148 | 172 | { |
| 149 | - if (\preg_match("/\d+$/", $shortName, $match)) { |
|
| 173 | + if (\preg_match("/\d+$/", $shortName, $match)) |
|
| 174 | + { |
|
| 150 | 175 | $sequence = (int)$match[0]; |
| 151 | - if ($sequence > 0) { |
|
| 176 | + if ($sequence > 0) |
|
| 177 | + { |
|
| 152 | 178 | return NamespaceEntity::createWithSequence( |
| 153 | 179 | Utils::trimTrailingDigits($shortName, $sequence), |
| 154 | 180 | $fullName, |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | { |
| 12 | 12 | public function __construct( |
| 13 | 13 | private readonly Sequences $sequences |
| 14 | - ) { |
|
| 14 | + ){ |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | public function resolve(ClassNode $definition): void |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | private function getConstructorReservedNames(ClassNode $definition): array |
| 26 | 26 | { |
| 27 | 27 | $names = \array_values($definition->constructorVars); |
| 28 | - foreach ($definition->constructorParams as $param) { |
|
| 28 | + foreach ($definition->constructorParams as $param){ |
|
| 29 | 29 | $names[] = $param->name; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | private function initiateCounters(array $names): array |
| 36 | 36 | { |
| 37 | 37 | $counters = []; |
| 38 | - foreach ($names as $name) { |
|
| 38 | + foreach ($names as $name){ |
|
| 39 | 39 | $name = $this->parseName($name); |
| 40 | 40 | |
| 41 | - if (isset($counters[$name->name])) { |
|
| 41 | + if (isset($counters[$name->name])){ |
|
| 42 | 42 | $counters[$name->name][$name->sequence] = $name->fullName(); |
| 43 | - } else { |
|
| 43 | + }else{ |
|
| 44 | 44 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -50,18 +50,18 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | private function addPostfixes(ClassNode $definition, array $counters): void |
| 52 | 52 | { |
| 53 | - foreach ($definition->dependencies as $dependency) { |
|
| 53 | + foreach ($definition->dependencies as $dependency){ |
|
| 54 | 54 | $name = $this->parseName($dependency->var); |
| 55 | - if (isset($counters[$name->name])) { |
|
| 55 | + if (isset($counters[$name->name])){ |
|
| 56 | 56 | $sequence = $this->sequences->find(\array_keys($counters[$name->name]), $name->sequence); |
| 57 | - if ($sequence !== $name->sequence) { |
|
| 57 | + if ($sequence !== $name->sequence){ |
|
| 58 | 58 | $name->sequence = $sequence; |
| 59 | 59 | |
| 60 | 60 | $dependency->var = $name->fullName(); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $counters[$name->name][$sequence] = $name->fullName(); |
| 64 | - } else { |
|
| 64 | + }else{ |
|
| 65 | 65 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | private function parseName(string $name): NameEntity |
| 71 | 71 | { |
| 72 | - if (\preg_match("/\d+$/", $name, $match)) { |
|
| 72 | + if (\preg_match("/\d+$/", $name, $match)){ |
|
| 73 | 73 | $sequence = (int)$match[0]; |
| 74 | - if ($sequence > 0) { |
|
| 74 | + if ($sequence > 0){ |
|
| 75 | 75 | return NameEntity::createWithSequence(Utils::trimTrailingDigits($name, $sequence), $sequence); |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -25,7 +25,8 @@ discard block |
||
| 25 | 25 | private function getConstructorReservedNames(ClassNode $definition): array |
| 26 | 26 | { |
| 27 | 27 | $names = \array_values($definition->constructorVars); |
| 28 | - foreach ($definition->constructorParams as $param) { |
|
| 28 | + foreach ($definition->constructorParams as $param) |
|
| 29 | + { |
|
| 29 | 30 | $names[] = $param->name; |
| 30 | 31 | } |
| 31 | 32 | |
@@ -35,12 +36,16 @@ discard block |
||
| 35 | 36 | private function initiateCounters(array $names): array |
| 36 | 37 | { |
| 37 | 38 | $counters = []; |
| 38 | - foreach ($names as $name) { |
|
| 39 | + foreach ($names as $name) |
|
| 40 | + { |
|
| 39 | 41 | $name = $this->parseName($name); |
| 40 | 42 | |
| 41 | - if (isset($counters[$name->name])) { |
|
| 43 | + if (isset($counters[$name->name])) |
|
| 44 | + { |
|
| 42 | 45 | $counters[$name->name][$name->sequence] = $name->fullName(); |
| 43 | - } else { |
|
| 46 | + } |
|
| 47 | + else |
|
| 48 | + { |
|
| 44 | 49 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
| 45 | 50 | } |
| 46 | 51 | } |
@@ -50,18 +55,23 @@ discard block |
||
| 50 | 55 | |
| 51 | 56 | private function addPostfixes(ClassNode $definition, array $counters): void |
| 52 | 57 | { |
| 53 | - foreach ($definition->dependencies as $dependency) { |
|
| 58 | + foreach ($definition->dependencies as $dependency) |
|
| 59 | + { |
|
| 54 | 60 | $name = $this->parseName($dependency->var); |
| 55 | - if (isset($counters[$name->name])) { |
|
| 61 | + if (isset($counters[$name->name])) |
|
| 62 | + { |
|
| 56 | 63 | $sequence = $this->sequences->find(\array_keys($counters[$name->name]), $name->sequence); |
| 57 | - if ($sequence !== $name->sequence) { |
|
| 64 | + if ($sequence !== $name->sequence) |
|
| 65 | + { |
|
| 58 | 66 | $name->sequence = $sequence; |
| 59 | 67 | |
| 60 | 68 | $dependency->var = $name->fullName(); |
| 61 | 69 | } |
| 62 | 70 | |
| 63 | 71 | $counters[$name->name][$sequence] = $name->fullName(); |
| 64 | - } else { |
|
| 72 | + } |
|
| 73 | + else |
|
| 74 | + { |
|
| 65 | 75 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
| 66 | 76 | } |
| 67 | 77 | } |
@@ -69,9 +79,11 @@ discard block |
||
| 69 | 79 | |
| 70 | 80 | private function parseName(string $name): NameEntity |
| 71 | 81 | { |
| 72 | - if (\preg_match("/\d+$/", $name, $match)) { |
|
| 82 | + if (\preg_match("/\d+$/", $name, $match)) |
|
| 83 | + { |
|
| 73 | 84 | $sequence = (int)$match[0]; |
| 74 | - if ($sequence > 0) { |
|
| 85 | + if ($sequence > 0) |
|
| 86 | + { |
|
| 75 | 87 | return NameEntity::createWithSequence(Utils::trimTrailingDigits($name, $sequence), $sequence); |
| 76 | 88 | } |
| 77 | 89 | } |
@@ -14,21 +14,21 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | public function find(array $sequences, int $originSequence): int |
| 16 | 16 | { |
| 17 | - if (empty($sequences) || $originSequence > \max($sequences)) { |
|
| 17 | + if (empty($sequences) || $originSequence > \max($sequences)){ |
|
| 18 | 18 | return $originSequence; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | $gaps = $this->skippedSequences($sequences); |
| 22 | 22 | |
| 23 | - if (isset($gaps[$originSequence])) { |
|
| 23 | + if (isset($gaps[$originSequence])){ |
|
| 24 | 24 | return $originSequence; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | //we do not add "1" as postfix: $var, $var2, $var3, etc |
| 28 | 28 | unset($gaps[1]); |
| 29 | - if (empty($gaps)) { |
|
| 29 | + if (empty($gaps)){ |
|
| 30 | 30 | $max = \max($sequences); |
| 31 | - if ($max === 0) { |
|
| 31 | + if ($max === 0){ |
|
| 32 | 32 | return 2; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | $skipped = []; |
| 44 | 44 | $max = \max($sequences); |
| 45 | - for ($i = 0; $i < $max; $i++) { |
|
| 46 | - if (!\in_array($i, $sequences, true)) { |
|
| 45 | + for ($i = 0; $i < $max; $i++){ |
|
| 46 | + if (!\in_array($i, $sequences, true)){ |
|
| 47 | 47 | $skipped[$i] = $i; |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -14,21 +14,25 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | public function find(array $sequences, int $originSequence): int |
| 16 | 16 | { |
| 17 | - if (empty($sequences) || $originSequence > \max($sequences)) { |
|
| 17 | + if (empty($sequences) || $originSequence > \max($sequences)) |
|
| 18 | + { |
|
| 18 | 19 | return $originSequence; |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | 22 | $gaps = $this->skippedSequences($sequences); |
| 22 | 23 | |
| 23 | - if (isset($gaps[$originSequence])) { |
|
| 24 | + if (isset($gaps[$originSequence])) |
|
| 25 | + { |
|
| 24 | 26 | return $originSequence; |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | 29 | //we do not add "1" as postfix: $var, $var2, $var3, etc |
| 28 | 30 | unset($gaps[1]); |
| 29 | - if (empty($gaps)) { |
|
| 31 | + if (empty($gaps)) |
|
| 32 | + { |
|
| 30 | 33 | $max = \max($sequences); |
| 31 | - if ($max === 0) { |
|
| 34 | + if ($max === 0) |
|
| 35 | + { |
|
| 32 | 36 | return 2; |
| 33 | 37 | } |
| 34 | 38 | |
@@ -42,8 +46,10 @@ discard block |
||
| 42 | 46 | { |
| 43 | 47 | $skipped = []; |
| 44 | 48 | $max = \max($sequences); |
| 45 | - for ($i = 0; $i < $max; $i++) { |
|
| 46 | - if (!\in_array($i, $sequences, true)) { |
|
| 49 | + for ($i = 0; $i < $max; $i++) |
|
| 50 | + { |
|
| 51 | + if (!\in_array($i, $sequences, true)) |
|
| 52 | + { |
|
| 47 | 53 | $skipped[$i] = $i; |
| 48 | 54 | } |
| 49 | 55 | } |