@@ -16,19 +16,19 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | public function leaveNode(Node $node): void |
| 18 | 18 | { |
| 19 | - if ($node instanceof Node\Stmt\ClassMethod && $node->name->name === '__construct') { |
|
| 20 | - foreach ($node->params as $param) { |
|
| 21 | - if ($param->type instanceof Node\NullableType) { |
|
| 22 | - if ($param->type->type instanceof Node\Identifier) { |
|
| 19 | + if ($node instanceof Node\Stmt\ClassMethod && $node->name->name === '__construct'){ |
|
| 20 | + foreach ($node->params as $param){ |
|
| 21 | + if ($param->type instanceof Node\NullableType){ |
|
| 22 | + if ($param->type->type instanceof Node\Identifier){ |
|
| 23 | 23 | $type = $param->type->type->name; |
| 24 | - } else { |
|
| 24 | + }else{ |
|
| 25 | 25 | $type = implode('\\', $param->type->type->getParts()); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | $type = "?$type"; |
| 29 | - } elseif ($param->type instanceof Node\Name) { |
|
| 29 | + } elseif ($param->type instanceof Node\Name){ |
|
| 30 | 30 | $type = implode('\\', $param->type->getParts()); |
| 31 | - } else { |
|
| 31 | + }else{ |
|
| 32 | 32 | $type = $param->type->name ?? null; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -16,19 +16,29 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | public function leaveNode(Node $node): void |
| 18 | 18 | { |
| 19 | - if ($node instanceof Node\Stmt\ClassMethod && $node->name->name === '__construct') { |
|
| 20 | - foreach ($node->params as $param) { |
|
| 21 | - if ($param->type instanceof Node\NullableType) { |
|
| 22 | - if ($param->type->type instanceof Node\Identifier) { |
|
| 19 | + if ($node instanceof Node\Stmt\ClassMethod && $node->name->name === '__construct') |
|
| 20 | + { |
|
| 21 | + foreach ($node->params as $param) |
|
| 22 | + { |
|
| 23 | + if ($param->type instanceof Node\NullableType) |
|
| 24 | + { |
|
| 25 | + if ($param->type->type instanceof Node\Identifier) |
|
| 26 | + { |
|
| 23 | 27 | $type = $param->type->type->name; |
| 24 | - } else { |
|
| 28 | + } |
|
| 29 | + else |
|
| 30 | + { |
|
| 25 | 31 | $type = implode('\\', $param->type->type->getParts()); |
| 26 | 32 | } |
| 27 | 33 | |
| 28 | 34 | $type = "?$type"; |
| 29 | - } elseif ($param->type instanceof Node\Name) { |
|
| 35 | + } |
|
| 36 | + elseif ($param->type instanceof Node\Name) |
|
| 37 | + { |
|
| 30 | 38 | $type = implode('\\', $param->type->getParts()); |
| 31 | - } else { |
|
| 39 | + } |
|
| 40 | + else |
|
| 41 | + { |
|
| 32 | 42 | $type = $param->type->name ?? null; |
| 33 | 43 | } |
| 34 | 44 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | { |
| 22 | 22 | $i = new Injector(); |
| 23 | 23 | |
| 24 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 24 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 25 | 25 | $r = $i->injectDependencies( |
| 26 | 26 | file_get_contents($filename), |
| 27 | 27 | $this->getDefinition( |
@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | ) |
| 35 | 35 | ); |
| 36 | 36 | |
| 37 | - self::assertStringContainsString(Fixtures\Some::class . ';', $r); |
|
| 38 | - self::assertStringContainsString(Fixtures\SubFolder\Some::class . ' as Some2;', $r); |
|
| 39 | - self::assertStringNotContainsString(Fixtures\SubFolder\Some::class . ';', $r); |
|
| 40 | - self::assertStringContainsString(Fixtures\ATest3::class . ';', $r); |
|
| 37 | + self::assertStringContainsString(Fixtures\Some::class.';', $r); |
|
| 38 | + self::assertStringContainsString(Fixtures\SubFolder\Some::class.' as Some2;', $r); |
|
| 39 | + self::assertStringNotContainsString(Fixtures\SubFolder\Some::class.';', $r); |
|
| 40 | + self::assertStringContainsString(Fixtures\ATest3::class.';', $r); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | { |
| 48 | 48 | $i = new Injector(); |
| 49 | 49 | |
| 50 | - $filename = __DIR__ . '/Fixtures/TestClassWithImports.php'; |
|
| 50 | + $filename = __DIR__.'/Fixtures/TestClassWithImports.php'; |
|
| 51 | 51 | $r = $i->injectDependencies( |
| 52 | 52 | \file_get_contents($filename), |
| 53 | 53 | $this->getDefinition( |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | ) |
| 61 | 61 | ); |
| 62 | 62 | |
| 63 | - self::assertStringContainsString(Fixtures\Some::class . ' as FTest;', $r); |
|
| 64 | - self::assertStringNotContainsString(Fixtures\Some::class . ';', $r); |
|
| 65 | - self::assertStringContainsString(Fixtures\SubFolder\Some::class . ' as TestAlias;', $r); |
|
| 66 | - self::assertStringNotContainsString(Fixtures\SubFolder\Some::class . ';', $r); |
|
| 67 | - self::assertStringContainsString(Fixtures\ATest3::class . ' as ATest;', $r); |
|
| 68 | - self::assertStringNotContainsString(Fixtures\ATest3::class . ';', $r); |
|
| 63 | + self::assertStringContainsString(Fixtures\Some::class.' as FTest;', $r); |
|
| 64 | + self::assertStringNotContainsString(Fixtures\Some::class.';', $r); |
|
| 65 | + self::assertStringContainsString(Fixtures\SubFolder\Some::class.' as TestAlias;', $r); |
|
| 66 | + self::assertStringNotContainsString(Fixtures\SubFolder\Some::class.';', $r); |
|
| 67 | + self::assertStringContainsString(Fixtures\ATest3::class.' as ATest;', $r); |
|
| 68 | + self::assertStringNotContainsString(Fixtures\ATest3::class.';', $r); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | { |
| 76 | 76 | $i = new Injector(); |
| 77 | 77 | |
| 78 | - $filename = __DIR__ . '/Fixtures/ChildClass.php'; |
|
| 78 | + $filename = __DIR__.'/Fixtures/ChildClass.php'; |
|
| 79 | 79 | $r = $i->injectDependencies( |
| 80 | 80 | file_get_contents($filename), |
| 81 | 81 | $this->getDefinition( |
@@ -88,18 +88,18 @@ discard block |
||
| 88 | 88 | ) |
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | - self::assertStringContainsString(Fixtures\Some::class . ';', $r); |
|
| 92 | - self::assertStringContainsString(Fixtures\SubFolder\Some::class . ' as Some2;', $r); |
|
| 93 | - self::assertStringNotContainsString(Fixtures\SubFolder\Some::class . ';', $r); |
|
| 94 | - self::assertStringContainsString(Fixtures\ATest3::class . ' as ATestAlias;', $r); |
|
| 95 | - self::assertStringNotContainsString(Fixtures\ATest3::class . ';', $r); |
|
| 91 | + self::assertStringContainsString(Fixtures\Some::class.';', $r); |
|
| 92 | + self::assertStringContainsString(Fixtures\SubFolder\Some::class.' as Some2;', $r); |
|
| 93 | + self::assertStringNotContainsString(Fixtures\SubFolder\Some::class.';', $r); |
|
| 94 | + self::assertStringContainsString(Fixtures\ATest3::class.' as ATestAlias;', $r); |
|
| 95 | + self::assertStringNotContainsString(Fixtures\ATest3::class.';', $r); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | public function testDuplicateProperty(): void |
| 99 | 99 | { |
| 100 | 100 | $i = new Injector(); |
| 101 | 101 | |
| 102 | - $filename = __DIR__ . '/Fixtures/DuplicatePropertyClass.php'; |
|
| 102 | + $filename = __DIR__.'/Fixtures/DuplicatePropertyClass.php'; |
|
| 103 | 103 | $r = $i->injectDependencies( |
| 104 | 104 | \file_get_contents($filename), |
| 105 | 105 | $this->getDefinition( |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | ) |
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | - self::assertStringContainsString(Fixtures\Some::class . ';', $r); |
|
| 113 | + self::assertStringContainsString(Fixtures\Some::class.';', $r); |
|
| 114 | 114 | self::assertStringContainsString('__construct(private readonly Some $test)', $r); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | { |
| 20 | 20 | protected function setUp(): void |
| 21 | 21 | { |
| 22 | - if ((string)ini_get('zend.assertions') === 1) { |
|
| 22 | + if ((string)ini_get('zend.assertions') === 1){ |
|
| 23 | 23 | ini_set('zend.assertions', 0); |
| 24 | 24 | } |
| 25 | 25 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | { |
| 33 | 33 | $i = new Injector(); |
| 34 | 34 | |
| 35 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 35 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 36 | 36 | $printed = $i->injectDependencies( |
| 37 | 37 | \file_get_contents($filename), |
| 38 | 38 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $i = new Injector(); |
| 47 | 47 | |
| 48 | - $filename = __DIR__ . '/Fixtures/WithPromotedProperty.php'; |
|
| 48 | + $filename = __DIR__.'/Fixtures/WithPromotedProperty.php'; |
|
| 49 | 49 | $printed = $i->injectDependencies( |
| 50 | 50 | \file_get_contents($filename), |
| 51 | 51 | $this->getDefinition($filename, ['two' => InjectionTwo::class]) |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | $i = new Injector(); |
| 64 | 64 | |
| 65 | - $filename = __DIR__ . '/Fixtures/TestEmptyClass.php'; |
|
| 65 | + $filename = __DIR__.'/Fixtures/TestEmptyClass.php'; |
|
| 66 | 66 | $content = file_get_contents($filename); |
| 67 | 67 | $printed = $i->injectDependencies( |
| 68 | 68 | file_get_contents($filename), |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | { |
| 81 | 81 | $i = new Injector(); |
| 82 | 82 | |
| 83 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 83 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 84 | 84 | $r = $i->injectDependencies( |
| 85 | 85 | file_get_contents($filename), |
| 86 | 86 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | { |
| 106 | 106 | $i = new Injector(); |
| 107 | 107 | |
| 108 | - $filename = __DIR__ . '/Fixtures/ChildClass.php'; |
|
| 108 | + $filename = __DIR__.'/Fixtures/ChildClass.php'; |
|
| 109 | 109 | $r = $i->injectDependencies( |
| 110 | 110 | file_get_contents($filename), |
| 111 | 111 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | { |
| 124 | 124 | $i = new Injector(); |
| 125 | 125 | |
| 126 | - $filename = __DIR__ . '/Fixtures/ChildWithConstructorClass.php'; |
|
| 126 | + $filename = __DIR__.'/Fixtures/ChildWithConstructorClass.php'; |
|
| 127 | 127 | $r = $i->injectDependencies( |
| 128 | 128 | file_get_contents($filename), |
| 129 | 129 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function testModifyConstructor(): void |
| 141 | 141 | { |
| 142 | - $filename = __DIR__ . '/Fixtures/WithConstructor.php'; |
|
| 142 | + $filename = __DIR__.'/Fixtures/WithConstructor.php'; |
|
| 143 | 143 | $extractor = new Traverse\Extractor(); |
| 144 | 144 | |
| 145 | 145 | $parameters = $extractor->extractFromFilename($filename); |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function testPriorOptionalConstructorParameters(): void |
| 167 | 167 | { |
| 168 | - $filename = __DIR__ . '/Fixtures/OptionalConstructorArgsClass.php'; |
|
| 168 | + $filename = __DIR__.'/Fixtures/OptionalConstructorArgsClass.php'; |
|
| 169 | 169 | $extractor = new Traverse\Extractor(); |
| 170 | 170 | |
| 171 | 171 | $parameters = $extractor->extractFromFilename($filename); |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | { |
| 197 | 197 | $i = new Injector(); |
| 198 | 198 | |
| 199 | - $filename = __DIR__ . '/ClassNode/ConflictResolver/Fixtures/ChildClass.php'; |
|
| 199 | + $filename = __DIR__.'/ClassNode/ConflictResolver/Fixtures/ChildClass.php'; |
|
| 200 | 200 | $printed = $i->injectDependencies( |
| 201 | 201 | file_get_contents($filename), |
| 202 | 202 | $this->getDefinition( |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | private readonly ConflictResolver\Names $namesResolver, |
| 26 | 26 | private readonly ConflictResolver\Namespaces $namespacesResolver, |
| 27 | 27 | ?Parser $parser = null, |
| 28 | - ) { |
|
| 28 | + ){ |
|
| 29 | 29 | $this->parser = $parser ?? (new ParserFactory())->createForHostVersion(); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | $declarator = new DeclareClass(); |
| 61 | 61 | $this->traverse($filename, $declarator); |
| 62 | 62 | |
| 63 | - if (empty($declarator->getClass())) { |
|
| 63 | + if (empty($declarator->getClass())){ |
|
| 64 | 64 | throw new ClassNotDeclaredException($filename); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if ($declarator->getNamespace()) { |
|
| 67 | + if ($declarator->getNamespace()){ |
|
| 68 | 68 | return ClassNode::createWithNamespace($declarator->getClass(), $declarator->getNamespace()); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | { |
| 76 | 76 | $tr = new NodeTraverser(); |
| 77 | 77 | |
| 78 | - foreach ($visitors as $visitor) { |
|
| 78 | + foreach ($visitors as $visitor){ |
|
| 79 | 79 | $tr->addVisitor($visitor); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | private function fillStmts(ClassNode $definition, array $imports): void |
| 86 | 86 | { |
| 87 | - foreach ($imports as $import) { |
|
| 87 | + foreach ($imports as $import){ |
|
| 88 | 88 | $definition->addImportUsage($import['name'], $import['alias']); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | $reflection = new \ReflectionClass(\sprintf('%s\%s', $definition->namespace, $definition->class)); |
| 98 | 98 | |
| 99 | 99 | $constructor = $reflection->getConstructor(); |
| 100 | - if ($constructor !== null) { |
|
| 100 | + if ($constructor !== null){ |
|
| 101 | 101 | $definition->hasConstructor = $constructor->getDeclaringClass()->getName() === $reflection->getName(); |
| 102 | 102 | |
| 103 | - foreach ($reflection->getConstructor()->getParameters() as $parameter) { |
|
| 103 | + foreach ($reflection->getConstructor()->getParameters() as $parameter){ |
|
| 104 | 104 | $definition->addParam($parameter); |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | private function fillConstructorVars(array $vars, ClassNode $definition): void |
| 114 | 114 | { |
| 115 | - foreach ($vars as $k => $var) { |
|
| 116 | - if (isset($definition->constructorParams[$var])) { |
|
| 115 | + foreach ($vars as $k => $var){ |
|
| 116 | + if (isset($definition->constructorParams[$var])){ |
|
| 117 | 117 | unset($vars[$k]); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | public function __construct( |
| 29 | 29 | ?Lexer $lexer = null, |
| 30 | 30 | private readonly PrettyPrinterAbstract $printer = new Standard(), |
| 31 | - ) { |
|
| 31 | + ){ |
|
| 32 | 32 | $this->lexer = $lexer ?? new Lexer\Emulative(); |
| 33 | 33 | |
| 34 | 34 | $this->parser = new Parser\Php8($this->lexer); |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function injectDependencies(string $code, ClassNode $node, bool $removeTrait = false): string |
| 45 | 45 | { |
| 46 | - if (empty($node->dependencies)) { |
|
| 47 | - if ($removeTrait) { |
|
| 46 | + if (empty($node->dependencies)){ |
|
| 47 | + if ($removeTrait){ |
|
| 48 | 48 | $tr = new NodeTraverser(); |
| 49 | 49 | $tr->addVisitor(new RemoveUse()); |
| 50 | 50 | $tr->addVisitor(new RemoveTrait()); |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $tr = new NodeTraverser(); |
| 59 | 59 | $tr->addVisitor(new AddUse($node)); |
| 60 | 60 | |
| 61 | - if ($removeTrait) { |
|
| 61 | + if ($removeTrait){ |
|
| 62 | 62 | $tr->addVisitor(new RemoveUse()); |
| 63 | 63 | $tr->addVisitor(new RemoveTrait()); |
| 64 | 64 | } |
@@ -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->getParts()), |
| 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->getParts()), |
| 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->getParts()); |
| 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->getParts()); |
| 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; |
@@ -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->getParts())); |
| 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->getParts())); |
| 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 | |
@@ -20,20 +20,20 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | public function __construct( |
| 22 | 22 | private readonly ClassNode $node, |
| 23 | - ) {} |
|
| 23 | + ){} |
|
| 24 | 24 | |
| 25 | 25 | public function leaveNode(Node $node): ?Node |
| 26 | 26 | { |
| 27 | - if (!$node instanceof Node\Stmt\Namespace_) { |
|
| 27 | + if (!$node instanceof Node\Stmt\Namespace_){ |
|
| 28 | 28 | return null; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | $imported = []; |
| 32 | - if (!$this->node->hasConstructor && $this->node->constructorParams) { |
|
| 33 | - foreach ($this->node->constructorParams as $param) { |
|
| 34 | - if (!empty($param->type) && $param->type->fullName) { |
|
| 32 | + if (!$this->node->hasConstructor && $this->node->constructorParams){ |
|
| 33 | + foreach ($this->node->constructorParams as $param){ |
|
| 34 | + if (!empty($param->type) && $param->type->fullName){ |
|
| 35 | 35 | $import = [$param->type->fullName, $param->type->alias]; |
| 36 | - if (\in_array($import, $imported, true)) { |
|
| 36 | + if (\in_array($import, $imported, true)){ |
|
| 37 | 37 | continue; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - foreach ($this->node->dependencies as $dependency) { |
|
| 46 | + foreach ($this->node->dependencies as $dependency){ |
|
| 47 | 47 | $import = [$dependency->type->fullName, $dependency->type->alias]; |
| 48 | - if (\in_array($import, $imported, true)) { |
|
| 48 | + if (\in_array($import, $imported, true)){ |
|
| 49 | 49 | continue; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -68,8 +68,8 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | private function definePlacementID(Node\Stmt\Namespace_ $node): int |
| 70 | 70 | { |
| 71 | - foreach ($node->stmts as $index => $child) { |
|
| 72 | - if ($child instanceof Node\Stmt\Class_) { |
|
| 71 | + foreach ($node->stmts as $index => $child){ |
|
| 72 | + if ($child instanceof Node\Stmt\Class_){ |
|
| 73 | 73 | return $index; |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | { |
| 87 | 87 | $uses = $this->getExistingUseParts($stmts); |
| 88 | 88 | |
| 89 | - foreach ($nodes as $i => $node) { |
|
| 90 | - if (!$node instanceof Node\Stmt\Use_) { |
|
| 89 | + foreach ($nodes as $i => $node){ |
|
| 90 | + if (!$node instanceof Node\Stmt\Use_){ |
|
| 91 | 91 | continue; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - foreach ($node->uses as $use) { |
|
| 95 | - if (\in_array($use->name->getParts(), $uses, true)) { |
|
| 94 | + foreach ($node->uses as $use){ |
|
| 95 | + if (\in_array($use->name->getParts(), $uses, true)){ |
|
| 96 | 96 | unset($nodes[$i]); |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | private function getExistingUseParts(array $stmts): array |
| 112 | 112 | { |
| 113 | 113 | $uses = []; |
| 114 | - foreach ($stmts as $stmt) { |
|
| 115 | - if (!$stmt instanceof Node\Stmt\Use_) { |
|
| 114 | + foreach ($stmts as $stmt){ |
|
| 115 | + if (!$stmt instanceof Node\Stmt\Use_){ |
|
| 116 | 116 | continue; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - foreach ($stmt->uses as $use) { |
|
| 119 | + foreach ($stmt->uses as $use){ |
|
| 120 | 120 | $uses[] = $use->name->getParts(); |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | private function buildUse(string $type, ?string $alias = null): Node\Stmt\Use_ |
| 128 | 128 | { |
| 129 | 129 | $b = new Use_(new Node\Name($type), Node\Stmt\Use_::TYPE_NORMAL); |
| 130 | - if (!empty($alias)) { |
|
| 130 | + if (!empty($alias)){ |
|
| 131 | 131 | $b->as($alias); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -20,20 +20,26 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | public function __construct( |
| 22 | 22 | private readonly ClassNode $node, |
| 23 | - ) {} |
|
| 23 | + ) { |
|
| 24 | +} |
|
| 24 | 25 | |
| 25 | 26 | public function leaveNode(Node $node): ?Node |
| 26 | 27 | { |
| 27 | - if (!$node instanceof Node\Stmt\Namespace_) { |
|
| 28 | + if (!$node instanceof Node\Stmt\Namespace_) |
|
| 29 | + { |
|
| 28 | 30 | return null; |
| 29 | 31 | } |
| 30 | 32 | |
| 31 | 33 | $imported = []; |
| 32 | - if (!$this->node->hasConstructor && $this->node->constructorParams) { |
|
| 33 | - foreach ($this->node->constructorParams as $param) { |
|
| 34 | - if (!empty($param->type) && $param->type->fullName) { |
|
| 34 | + if (!$this->node->hasConstructor && $this->node->constructorParams) |
|
| 35 | + { |
|
| 36 | + foreach ($this->node->constructorParams as $param) |
|
| 37 | + { |
|
| 38 | + if (!empty($param->type) && $param->type->fullName) |
|
| 39 | + { |
|
| 35 | 40 | $import = [$param->type->fullName, $param->type->alias]; |
| 36 | - if (\in_array($import, $imported, true)) { |
|
| 41 | + if (\in_array($import, $imported, true)) |
|
| 42 | + { |
|
| 37 | 43 | continue; |
| 38 | 44 | } |
| 39 | 45 | |
@@ -43,9 +49,11 @@ discard block |
||
| 43 | 49 | } |
| 44 | 50 | } |
| 45 | 51 | |
| 46 | - foreach ($this->node->dependencies as $dependency) { |
|
| 52 | + foreach ($this->node->dependencies as $dependency) |
|
| 53 | + { |
|
| 47 | 54 | $import = [$dependency->type->fullName, $dependency->type->alias]; |
| 48 | - if (\in_array($import, $imported, true)) { |
|
| 55 | + if (\in_array($import, $imported, true)) |
|
| 56 | + { |
|
| 49 | 57 | continue; |
| 50 | 58 | } |
| 51 | 59 | |
@@ -68,8 +76,10 @@ discard block |
||
| 68 | 76 | |
| 69 | 77 | private function definePlacementID(Node\Stmt\Namespace_ $node): int |
| 70 | 78 | { |
| 71 | - foreach ($node->stmts as $index => $child) { |
|
| 72 | - if ($child instanceof Node\Stmt\Class_) { |
|
| 79 | + foreach ($node->stmts as $index => $child) |
|
| 80 | + { |
|
| 81 | + if ($child instanceof Node\Stmt\Class_) |
|
| 82 | + { |
|
| 73 | 83 | return $index; |
| 74 | 84 | } |
| 75 | 85 | } |
@@ -86,13 +96,17 @@ discard block |
||
| 86 | 96 | { |
| 87 | 97 | $uses = $this->getExistingUseParts($stmts); |
| 88 | 98 | |
| 89 | - foreach ($nodes as $i => $node) { |
|
| 90 | - if (!$node instanceof Node\Stmt\Use_) { |
|
| 99 | + foreach ($nodes as $i => $node) |
|
| 100 | + { |
|
| 101 | + if (!$node instanceof Node\Stmt\Use_) |
|
| 102 | + { |
|
| 91 | 103 | continue; |
| 92 | 104 | } |
| 93 | 105 | |
| 94 | - foreach ($node->uses as $use) { |
|
| 95 | - if (\in_array($use->name->getParts(), $uses, true)) { |
|
| 106 | + foreach ($node->uses as $use) |
|
| 107 | + { |
|
| 108 | + if (\in_array($use->name->getParts(), $uses, true)) |
|
| 109 | + { |
|
| 96 | 110 | unset($nodes[$i]); |
| 97 | 111 | } |
| 98 | 112 | } |
@@ -111,12 +125,15 @@ discard block |
||
| 111 | 125 | private function getExistingUseParts(array $stmts): array |
| 112 | 126 | { |
| 113 | 127 | $uses = []; |
| 114 | - foreach ($stmts as $stmt) { |
|
| 115 | - if (!$stmt instanceof Node\Stmt\Use_) { |
|
| 128 | + foreach ($stmts as $stmt) |
|
| 129 | + { |
|
| 130 | + if (!$stmt instanceof Node\Stmt\Use_) |
|
| 131 | + { |
|
| 116 | 132 | continue; |
| 117 | 133 | } |
| 118 | 134 | |
| 119 | - foreach ($stmt->uses as $use) { |
|
| 135 | + foreach ($stmt->uses as $use) |
|
| 136 | + { |
|
| 120 | 137 | $uses[] = $use->name->getParts(); |
| 121 | 138 | } |
| 122 | 139 | } |
@@ -127,7 +144,8 @@ discard block |
||
| 127 | 144 | private function buildUse(string $type, ?string $alias = null): Node\Stmt\Use_ |
| 128 | 145 | { |
| 129 | 146 | $b = new Use_(new Node\Name($type), Node\Stmt\Use_::TYPE_NORMAL); |
| 130 | - if (!empty($alias)) { |
|
| 147 | + if (!empty($alias)) |
|
| 148 | + { |
|
| 131 | 149 | $b->as($alias); |
| 132 | 150 | } |
| 133 | 151 | |