@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | $i = new Injector(); |
| 26 | 26 | |
| 27 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 27 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 28 | 28 | $r = $i->injectDependencies( |
| 29 | 29 | file_get_contents($filename), |
| 30 | 30 | $this->getDefinition( |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | ) |
| 38 | 38 | ); |
| 39 | 39 | |
| 40 | - $this->assertStringContainsString(Fixtures\Test::class . ';', $r); |
|
| 40 | + $this->assertStringContainsString(Fixtures\Test::class.';', $r); |
|
| 41 | 41 | $this->assertStringContainsString('private Test $test', $r); |
| 42 | 42 | |
| 43 | - $this->assertStringContainsString(Fixtures\SubFolder\Test::class . ' as Test2;', $r); |
|
| 44 | - $this->assertStringNotContainsString(Fixtures\SubFolder\Test::class . ';', $r); |
|
| 43 | + $this->assertStringContainsString(Fixtures\SubFolder\Test::class.' as Test2;', $r); |
|
| 44 | + $this->assertStringNotContainsString(Fixtures\SubFolder\Test::class.';', $r); |
|
| 45 | 45 | $this->assertStringContainsString('private Test2 $test2', $r); |
| 46 | 46 | |
| 47 | - $this->assertStringContainsString(Fixtures\ATest3::class . ';', $r); |
|
| 47 | + $this->assertStringContainsString(Fixtures\ATest3::class.';', $r); |
|
| 48 | 48 | $this->assertStringContainsString('private ATest3 $test3', $r); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | { |
| 56 | 56 | $i = new Injector(); |
| 57 | 57 | |
| 58 | - $filename = __DIR__ . '/Fixtures/TestClassWithImports.php'; |
|
| 58 | + $filename = __DIR__.'/Fixtures/TestClassWithImports.php'; |
|
| 59 | 59 | $r = $i->injectDependencies( |
| 60 | 60 | file_get_contents($filename), |
| 61 | 61 | $this->getDefinition( |
@@ -68,16 +68,16 @@ discard block |
||
| 68 | 68 | ) |
| 69 | 69 | ); |
| 70 | 70 | |
| 71 | - $this->assertStringContainsString(Fixtures\Test::class . ' as FTest;', $r); |
|
| 72 | - $this->assertStringNotContainsString(Fixtures\Test::class . ';', $r); |
|
| 71 | + $this->assertStringContainsString(Fixtures\Test::class.' as FTest;', $r); |
|
| 72 | + $this->assertStringNotContainsString(Fixtures\Test::class.';', $r); |
|
| 73 | 73 | $this->assertStringContainsString('private FTest $test', $r); |
| 74 | 74 | |
| 75 | - $this->assertStringContainsString(Fixtures\SubFolder\Test::class . ' as TestAlias;', $r); |
|
| 76 | - $this->assertStringNotContainsString(Fixtures\SubFolder\Test::class . ';', $r); |
|
| 75 | + $this->assertStringContainsString(Fixtures\SubFolder\Test::class.' as TestAlias;', $r); |
|
| 76 | + $this->assertStringNotContainsString(Fixtures\SubFolder\Test::class.';', $r); |
|
| 77 | 77 | $this->assertStringContainsString('private TestAlias $test2', $r); |
| 78 | 78 | |
| 79 | - $this->assertStringContainsString(Fixtures\ATest3::class . ' as ATest;', $r); |
|
| 80 | - $this->assertStringNotContainsString(Fixtures\ATest3::class . ';', $r); |
|
| 79 | + $this->assertStringContainsString(Fixtures\ATest3::class.' as ATest;', $r); |
|
| 80 | + $this->assertStringNotContainsString(Fixtures\ATest3::class.';', $r); |
|
| 81 | 81 | $this->assertStringContainsString('private ATest $test3', $r); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | { |
| 89 | 89 | $i = new Injector(); |
| 90 | 90 | |
| 91 | - $filename = __DIR__ . '/Fixtures/ChildClass.php'; |
|
| 91 | + $filename = __DIR__.'/Fixtures/ChildClass.php'; |
|
| 92 | 92 | $r = $i->injectDependencies( |
| 93 | 93 | file_get_contents($filename), |
| 94 | 94 | $this->getDefinition( |
@@ -101,15 +101,15 @@ discard block |
||
| 101 | 101 | ) |
| 102 | 102 | ); |
| 103 | 103 | |
| 104 | - $this->assertStringContainsString(Fixtures\Test::class . ';', $r); |
|
| 104 | + $this->assertStringContainsString(Fixtures\Test::class.';', $r); |
|
| 105 | 105 | $this->assertStringContainsString('private Test $test', $r); |
| 106 | 106 | |
| 107 | - $this->assertStringContainsString(Fixtures\SubFolder\Test::class . ' as Test2;', $r); |
|
| 108 | - $this->assertStringNotContainsString(Fixtures\SubFolder\Test::class . ';', $r); |
|
| 107 | + $this->assertStringContainsString(Fixtures\SubFolder\Test::class.' as Test2;', $r); |
|
| 108 | + $this->assertStringNotContainsString(Fixtures\SubFolder\Test::class.';', $r); |
|
| 109 | 109 | $this->assertStringContainsString('private Test2 $test2', $r); |
| 110 | 110 | |
| 111 | - $this->assertStringContainsString(Fixtures\ATest3::class . ' as ATestAlias;', $r); |
|
| 112 | - $this->assertStringNotContainsString(Fixtures\ATest3::class . ';', $r); |
|
| 111 | + $this->assertStringContainsString(Fixtures\ATest3::class.' as ATestAlias;', $r); |
|
| 112 | + $this->assertStringNotContainsString(Fixtures\ATest3::class.';', $r); |
|
| 113 | 113 | $this->assertStringContainsString('private ATestAlias $test3', $r); |
| 114 | 114 | } |
| 115 | 115 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | { |
| 118 | 118 | $i = new Injector(); |
| 119 | 119 | |
| 120 | - $filename = __DIR__ . '/Fixtures/DuplicatePropertyClass.php'; |
|
| 120 | + $filename = __DIR__.'/Fixtures/DuplicatePropertyClass.php'; |
|
| 121 | 121 | $r = $i->injectDependencies( |
| 122 | 122 | file_get_contents($filename), |
| 123 | 123 | $this->getDefinition( |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | ) |
| 129 | 129 | ); |
| 130 | 130 | |
| 131 | - $this->assertStringContainsString(Fixtures\Test::class . ';', $r); |
|
| 131 | + $this->assertStringContainsString(Fixtures\Test::class.';', $r); |
|
| 132 | 132 | $this->assertStringContainsString('__construct(private Test $test)', $r); |
| 133 | 133 | } |
| 134 | 134 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public function setUp(): void |
| 23 | 23 | { |
| 24 | - if ((string)ini_get('zend.assertions') === 1) { |
|
| 24 | + if ((string)ini_get('zend.assertions') === 1){ |
|
| 25 | 25 | ini_set('zend.assertions', 0); |
| 26 | 26 | } |
| 27 | 27 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | { |
| 35 | 35 | $i = new Injector(); |
| 36 | 36 | |
| 37 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 37 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 38 | 38 | $printed = $i->injectDependencies( |
| 39 | 39 | file_get_contents($filename), |
| 40 | 40 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | { |
| 48 | 48 | $i = new Injector(); |
| 49 | 49 | |
| 50 | - $filename = __DIR__ . '/Fixtures/WithPromotedProperty.php'; |
|
| 50 | + $filename = __DIR__.'/Fixtures/WithPromotedProperty.php'; |
|
| 51 | 51 | $printed = $i->injectDependencies( |
| 52 | 52 | file_get_contents($filename), |
| 53 | 53 | $this->getDefinition($filename, ['two' => InjectionTwo::class]) |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | { |
| 68 | 68 | $i = new Injector(); |
| 69 | 69 | |
| 70 | - $filename = __DIR__ . '/Fixtures/TestEmptyClass.php'; |
|
| 70 | + $filename = __DIR__.'/Fixtures/TestEmptyClass.php'; |
|
| 71 | 71 | $content = file_get_contents($filename); |
| 72 | 72 | $printed = $i->injectDependencies( |
| 73 | 73 | file_get_contents($filename), |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | $i = new Injector(); |
| 87 | 87 | |
| 88 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 88 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 89 | 89 | $r = $i->injectDependencies( |
| 90 | 90 | file_get_contents($filename), |
| 91 | 91 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | $i = new Injector(); |
| 112 | 112 | |
| 113 | - $filename = __DIR__ . '/Fixtures/ChildClass.php'; |
|
| 113 | + $filename = __DIR__.'/Fixtures/ChildClass.php'; |
|
| 114 | 114 | $r = $i->injectDependencies( |
| 115 | 115 | file_get_contents($filename), |
| 116 | 116 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | { |
| 129 | 129 | $i = new Injector(); |
| 130 | 130 | |
| 131 | - $filename = __DIR__ . '/Fixtures/ChildWithConstructorClass.php'; |
|
| 131 | + $filename = __DIR__.'/Fixtures/ChildWithConstructorClass.php'; |
|
| 132 | 132 | $r = $i->injectDependencies( |
| 133 | 133 | file_get_contents($filename), |
| 134 | 134 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public function testModifyConstructor(): void |
| 146 | 146 | { |
| 147 | - $filename = __DIR__ . '/Fixtures/WithConstructor.php'; |
|
| 147 | + $filename = __DIR__.'/Fixtures/WithConstructor.php'; |
|
| 148 | 148 | $extractor = new Traverse\Extractor(); |
| 149 | 149 | |
| 150 | 150 | $parameters = $extractor->extractFromFilename($filename); |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | public function testPriorOptionalConstructorParameters(): void |
| 172 | 172 | { |
| 173 | - $filename = __DIR__ . '/Fixtures/OptionalConstructorArgsClass.php'; |
|
| 173 | + $filename = __DIR__.'/Fixtures/OptionalConstructorArgsClass.php'; |
|
| 174 | 174 | $extractor = new Traverse\Extractor(); |
| 175 | 175 | |
| 176 | 176 | $parameters = $extractor->extractFromFilename($filename); |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | { |
| 202 | 202 | $i = new Injector(); |
| 203 | 203 | |
| 204 | - $filename = __DIR__ . '/ClassNode/ConflictResolver/Fixtures/ChildClass.php'; |
|
| 204 | + $filename = __DIR__.'/ClassNode/ConflictResolver/Fixtures/ChildClass.php'; |
|
| 205 | 205 | $printed = $i->injectDependencies( |
| 206 | 206 | file_get_contents($filename), |
| 207 | 207 | $this->getDefinition( |
@@ -21,7 +21,8 @@ |
||
| 21 | 21 | |
| 22 | 22 | public function setUp(): void |
| 23 | 23 | { |
| 24 | - if ((string)ini_get('zend.assertions') === 1) { |
|
| 24 | + if ((string)ini_get('zend.assertions') === 1) |
|
| 25 | + { |
|
| 25 | 26 | ini_set('zend.assertions', 0); |
| 26 | 27 | } |
| 27 | 28 | } |
@@ -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 | 'usedAttributes' => [ |
| 34 | 34 | 'comments', |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function injectDependencies(string $code, ClassNode $node, bool $removeTrait = false): string |
| 53 | 53 | { |
| 54 | - if (empty($node->dependencies)) { |
|
| 55 | - if ($removeTrait) { |
|
| 54 | + if (empty($node->dependencies)){ |
|
| 55 | + if ($removeTrait){ |
|
| 56 | 56 | $tr = new NodeTraverser(); |
| 57 | 57 | $tr->addVisitor(new RemoveUse()); |
| 58 | 58 | $tr->addVisitor(new RemoveTrait()); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $tr = new NodeTraverser(); |
| 67 | 67 | $tr->addVisitor(new AddUse($node)); |
| 68 | 68 | |
| 69 | - if ($removeTrait) { |
|
| 69 | + if ($removeTrait){ |
|
| 70 | 70 | $tr->addVisitor(new RemoveUse()); |
| 71 | 71 | $tr->addVisitor(new RemoveTrait()); |
| 72 | 72 | } |
@@ -51,8 +51,10 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function injectDependencies(string $code, ClassNode $node, bool $removeTrait = false): string |
| 53 | 53 | { |
| 54 | - if (empty($node->dependencies)) { |
|
| 55 | - if ($removeTrait) { |
|
| 54 | + if (empty($node->dependencies)) |
|
| 55 | + { |
|
| 56 | + if ($removeTrait) |
|
| 57 | + { |
|
| 56 | 58 | $tr = new NodeTraverser(); |
| 57 | 59 | $tr->addVisitor(new RemoveUse()); |
| 58 | 60 | $tr->addVisitor(new RemoveTrait()); |
@@ -66,7 +68,8 @@ discard block |
||
| 66 | 68 | $tr = new NodeTraverser(); |
| 67 | 69 | $tr->addVisitor(new AddUse($node)); |
| 68 | 70 | |
| 69 | - if ($removeTrait) { |
|
| 71 | + if ($removeTrait) |
|
| 72 | + { |
|
| 70 | 73 | $tr->addVisitor(new RemoveUse()); |
| 71 | 74 | $tr->addVisitor(new RemoveTrait()); |
| 72 | 75 | } |
@@ -39,26 +39,26 @@ |
||
| 39 | 39 | $node->var instanceof Node\Expr\Variable && |
| 40 | 40 | $node->var->name === 'this' && |
| 41 | 41 | $node->name instanceof Node\Identifier |
| 42 | - ) { |
|
| 42 | + ){ |
|
| 43 | 43 | $this->requested[$node->name->name] = $node->name->name; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if ($node instanceof Node\Stmt\Property) { |
|
| 47 | - foreach ($node->props as $prop) { |
|
| 48 | - if ($prop instanceof Node\Stmt\PropertyProperty) { |
|
| 46 | + if ($node instanceof Node\Stmt\Property){ |
|
| 47 | + foreach ($node->props as $prop){ |
|
| 48 | + if ($prop instanceof Node\Stmt\PropertyProperty){ |
|
| 49 | 49 | $this->properties[$prop->name->name] = $prop->name->name; |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if ($this->isPromotedProperty($node)) { |
|
| 54 | + if ($this->isPromotedProperty($node)){ |
|
| 55 | 55 | $this->properties[$node->var->name] = $node->var->name; |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | private function isPromotedProperty(Node $node): bool |
| 60 | 60 | { |
| 61 | - if (!$node instanceof Node\Param) { |
|
| 61 | + if (!$node instanceof Node\Param){ |
|
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -43,22 +43,27 @@ |
||
| 43 | 43 | $this->requested[$node->name->name] = $node->name->name; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if ($node instanceof Node\Stmt\Property) { |
|
| 47 | - foreach ($node->props as $prop) { |
|
| 48 | - if ($prop instanceof Node\Stmt\PropertyProperty) { |
|
| 46 | + if ($node instanceof Node\Stmt\Property) |
|
| 47 | + { |
|
| 48 | + foreach ($node->props as $prop) |
|
| 49 | + { |
|
| 50 | + if ($prop instanceof Node\Stmt\PropertyProperty) |
|
| 51 | + { |
|
| 49 | 52 | $this->properties[$prop->name->name] = $prop->name->name; |
| 50 | 53 | } |
| 51 | 54 | } |
| 52 | 55 | } |
| 53 | 56 | |
| 54 | - if ($this->isPromotedProperty($node)) { |
|
| 57 | + if ($this->isPromotedProperty($node)) |
|
| 58 | + { |
|
| 55 | 59 | $this->properties[$node->var->name] = $node->var->name; |
| 56 | 60 | } |
| 57 | 61 | } |
| 58 | 62 | |
| 59 | 63 | private function isPromotedProperty(Node $node): bool |
| 60 | 64 | { |
| 61 | - if (!$node instanceof Node\Param) { |
|
| 65 | + if (!$node instanceof Node\Param) |
|
| 66 | + { |
|
| 62 | 67 | return false; |
| 63 | 68 | } |
| 64 | 69 | |
@@ -62,8 +62,8 @@ |
||
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - return $node->flags === Modifiers::PUBLIC |
|
| 66 | - || $node->flags === Modifiers::PROTECTED |
|
| 67 | - || $node->flags === Modifiers::PRIVATE; |
|
| 65 | + return $node->flags === Modifiers::public |
|
| 66 | + || $node->flags === Modifiers::protected |
|
| 67 | + || $node->flags === Modifiers::private; |
|
| 68 | 68 | } |
| 69 | 69 | } |
@@ -20,18 +20,18 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | public function __construct( |
| 22 | 22 | private readonly ClassNode $definition |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - public function leaveNode(Node $node): int|Node|null |
|
| 26 | + public function leaveNode(Node $node): int | Node | null |
|
| 27 | 27 | { |
| 28 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 28 | + if (!$node instanceof Node\Stmt\Class_){ |
|
| 29 | 29 | return null; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $constructor = $this->getConstructorAttribute($node); |
| 33 | 33 | $this->addDependencies($constructor); |
| 34 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
| 34 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams){ |
|
| 35 | 35 | $this->addParentConstructorCall($constructor); |
| 36 | 36 | } |
| 37 | 37 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
| 45 | 45 | { |
| 46 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 46 | + foreach ($this->definition->dependencies as $dependency){ |
|
| 47 | 47 | \array_unshift($constructor->params, $this->buildConstructorParam($dependency)); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -60,34 +60,34 @@ discard block |
||
| 60 | 60 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
| 61 | 61 | { |
| 62 | 62 | $parentConstructorDependencies = []; |
| 63 | - foreach ($this->definition->constructorParams as $param) { |
|
| 63 | + foreach ($this->definition->constructorParams as $param){ |
|
| 64 | 64 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
| 65 | 65 | |
| 66 | 66 | $cp = new Param($param->name); |
| 67 | - if (!empty($param->type)) { |
|
| 67 | + if (!empty($param->type)){ |
|
| 68 | 68 | $type = $this->getParamType($param); |
| 69 | - if ($param->nullable) { |
|
| 69 | + if ($param->nullable){ |
|
| 70 | 70 | $type = \sprintf('?%s', $type); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | $cp->setType(new Node\Name($type)); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - if ($param->byRef) { |
|
| 76 | + if ($param->byRef){ |
|
| 77 | 77 | $cp->makeByRef(); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if ($param->isVariadic) { |
|
| 80 | + if ($param->isVariadic){ |
|
| 81 | 81 | $cp->makeVariadic(); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if ($param->hasDefault) { |
|
| 84 | + if ($param->hasDefault){ |
|
| 85 | 85 | $cp->setDefault($param->default); |
| 86 | 86 | } |
| 87 | 87 | $constructor->params[] = $cp->getNode(); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if ($parentConstructorDependencies !== []) { |
|
| 90 | + if ($parentConstructorDependencies !== []){ |
|
| 91 | 91 | \array_unshift( |
| 92 | 92 | $constructor->stmts, |
| 93 | 93 | new Node\Stmt\Expression( |
@@ -115,18 +115,18 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | $params = []; |
| 117 | 117 | |
| 118 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 118 | + foreach ($this->definition->dependencies as $dependency){ |
|
| 119 | 119 | $params[] = new Annotation\Line( |
| 120 | 120 | \sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), |
| 121 | 121 | 'param' |
| 122 | 122 | ); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if (!$this->definition->hasConstructor) { |
|
| 126 | - foreach ($this->definition->constructorParams as $param) { |
|
| 127 | - if (!empty($param->type)) { |
|
| 125 | + if (!$this->definition->hasConstructor){ |
|
| 126 | + foreach ($this->definition->constructorParams as $param){ |
|
| 127 | + if (!empty($param->type)){ |
|
| 128 | 128 | $type = $this->getParamType($param); |
| 129 | - if ($param->nullable) { |
|
| 129 | + if ($param->nullable){ |
|
| 130 | 130 | $type = \sprintf('%s|null', $type); |
| 131 | 131 | } |
| 132 | 132 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | \sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), |
| 135 | 135 | 'param' |
| 136 | 136 | ); |
| 137 | - } else { |
|
| 137 | + }else{ |
|
| 138 | 138 | $params[] = new Annotation\Line( |
| 139 | 139 | \sprintf('$%s', $param->name), |
| 140 | 140 | 'param' |
@@ -145,12 +145,12 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | $placementID = 0; |
| 147 | 147 | $previous = null; |
| 148 | - foreach ($an->lines as $index => $line) { |
|
| 148 | + foreach ($an->lines as $index => $line){ |
|
| 149 | 149 | // always next node |
| 150 | 150 | $placementID = $index + 1; |
| 151 | 151 | |
| 152 | 152 | // inject before this parameters |
| 153 | - if ($line->is(['throws', 'return'])) { |
|
| 153 | + if ($line->is(['throws', 'return'])){ |
|
| 154 | 154 | // insert before given node |
| 155 | 155 | $placementID--; |
| 156 | 156 | break; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $previous = $line; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - if ($previous !== null && !$previous->isEmpty()) { |
|
| 162 | + if ($previous !== null && !$previous->isEmpty()){ |
|
| 163 | 163 | $placementID++; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | private function getPropertyType(Dependency $dependency): string |
| 172 | 172 | { |
| 173 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 174 | - if ($stmt->name === $dependency->type->fullName && $stmt->alias) { |
|
| 173 | + foreach ($this->definition->getStmts() as $stmt){ |
|
| 174 | + if ($stmt->name === $dependency->type->fullName && $stmt->alias){ |
|
| 175 | 175 | return $stmt->alias; |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -181,13 +181,13 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | private function getParamType(ClassNode\ConstructorParam $param): string |
| 183 | 183 | { |
| 184 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 185 | - if ($stmt->name === $param->type->fullName && $stmt->alias) { |
|
| 184 | + foreach ($this->definition->getStmts() as $stmt){ |
|
| 185 | + if ($stmt->name === $param->type->fullName && $stmt->alias){ |
|
| 186 | 186 | return $stmt->alias; |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if ($param->type->alias) { |
|
| 190 | + if ($param->type->alias){ |
|
| 191 | 191 | return $param->type->alias; |
| 192 | 192 | } |
| 193 | 193 | |
@@ -25,13 +25,15 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function leaveNode(Node $node): int|Node|null |
| 27 | 27 | { |
| 28 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 28 | + if (!$node instanceof Node\Stmt\Class_) |
|
| 29 | + { |
|
| 29 | 30 | return null; |
| 30 | 31 | } |
| 31 | 32 | |
| 32 | 33 | $constructor = $this->getConstructorAttribute($node); |
| 33 | 34 | $this->addDependencies($constructor); |
| 34 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
| 35 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams) |
|
| 36 | + { |
|
| 35 | 37 | $this->addParentConstructorCall($constructor); |
| 36 | 38 | } |
| 37 | 39 | |
@@ -43,7 +45,8 @@ discard block |
||
| 43 | 45 | */ |
| 44 | 46 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
| 45 | 47 | { |
| 46 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 48 | + foreach ($this->definition->dependencies as $dependency) |
|
| 49 | + { |
|
| 47 | 50 | \array_unshift($constructor->params, $this->buildConstructorParam($dependency)); |
| 48 | 51 | } |
| 49 | 52 | } |
@@ -60,34 +63,41 @@ discard block |
||
| 60 | 63 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
| 61 | 64 | { |
| 62 | 65 | $parentConstructorDependencies = []; |
| 63 | - foreach ($this->definition->constructorParams as $param) { |
|
| 66 | + foreach ($this->definition->constructorParams as $param) |
|
| 67 | + { |
|
| 64 | 68 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
| 65 | 69 | |
| 66 | 70 | $cp = new Param($param->name); |
| 67 | - if (!empty($param->type)) { |
|
| 71 | + if (!empty($param->type)) |
|
| 72 | + { |
|
| 68 | 73 | $type = $this->getParamType($param); |
| 69 | - if ($param->nullable) { |
|
| 74 | + if ($param->nullable) |
|
| 75 | + { |
|
| 70 | 76 | $type = \sprintf('?%s', $type); |
| 71 | 77 | } |
| 72 | 78 | |
| 73 | 79 | $cp->setType(new Node\Name($type)); |
| 74 | 80 | } |
| 75 | 81 | |
| 76 | - if ($param->byRef) { |
|
| 82 | + if ($param->byRef) |
|
| 83 | + { |
|
| 77 | 84 | $cp->makeByRef(); |
| 78 | 85 | } |
| 79 | 86 | |
| 80 | - if ($param->isVariadic) { |
|
| 87 | + if ($param->isVariadic) |
|
| 88 | + { |
|
| 81 | 89 | $cp->makeVariadic(); |
| 82 | 90 | } |
| 83 | 91 | |
| 84 | - if ($param->hasDefault) { |
|
| 92 | + if ($param->hasDefault) |
|
| 93 | + { |
|
| 85 | 94 | $cp->setDefault($param->default); |
| 86 | 95 | } |
| 87 | 96 | $constructor->params[] = $cp->getNode(); |
| 88 | 97 | } |
| 89 | 98 | |
| 90 | - if ($parentConstructorDependencies !== []) { |
|
| 99 | + if ($parentConstructorDependencies !== []) |
|
| 100 | + { |
|
| 91 | 101 | \array_unshift( |
| 92 | 102 | $constructor->stmts, |
| 93 | 103 | new Node\Stmt\Expression( |
@@ -115,18 +125,23 @@ discard block |
||
| 115 | 125 | |
| 116 | 126 | $params = []; |
| 117 | 127 | |
| 118 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 128 | + foreach ($this->definition->dependencies as $dependency) |
|
| 129 | + { |
|
| 119 | 130 | $params[] = new Annotation\Line( |
| 120 | 131 | \sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), |
| 121 | 132 | 'param' |
| 122 | 133 | ); |
| 123 | 134 | } |
| 124 | 135 | |
| 125 | - if (!$this->definition->hasConstructor) { |
|
| 126 | - foreach ($this->definition->constructorParams as $param) { |
|
| 127 | - if (!empty($param->type)) { |
|
| 136 | + if (!$this->definition->hasConstructor) |
|
| 137 | + { |
|
| 138 | + foreach ($this->definition->constructorParams as $param) |
|
| 139 | + { |
|
| 140 | + if (!empty($param->type)) |
|
| 141 | + { |
|
| 128 | 142 | $type = $this->getParamType($param); |
| 129 | - if ($param->nullable) { |
|
| 143 | + if ($param->nullable) |
|
| 144 | + { |
|
| 130 | 145 | $type = \sprintf('%s|null', $type); |
| 131 | 146 | } |
| 132 | 147 | |
@@ -134,7 +149,9 @@ discard block |
||
| 134 | 149 | \sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), |
| 135 | 150 | 'param' |
| 136 | 151 | ); |
| 137 | - } else { |
|
| 152 | + } |
|
| 153 | + else |
|
| 154 | + { |
|
| 138 | 155 | $params[] = new Annotation\Line( |
| 139 | 156 | \sprintf('$%s', $param->name), |
| 140 | 157 | 'param' |
@@ -145,12 +162,14 @@ discard block |
||
| 145 | 162 | |
| 146 | 163 | $placementID = 0; |
| 147 | 164 | $previous = null; |
| 148 | - foreach ($an->lines as $index => $line) { |
|
| 165 | + foreach ($an->lines as $index => $line) |
|
| 166 | + { |
|
| 149 | 167 | // always next node |
| 150 | 168 | $placementID = $index + 1; |
| 151 | 169 | |
| 152 | 170 | // inject before this parameters |
| 153 | - if ($line->is(['throws', 'return'])) { |
|
| 171 | + if ($line->is(['throws', 'return'])) |
|
| 172 | + { |
|
| 154 | 173 | // insert before given node |
| 155 | 174 | $placementID--; |
| 156 | 175 | break; |
@@ -159,7 +178,8 @@ discard block |
||
| 159 | 178 | $previous = $line; |
| 160 | 179 | } |
| 161 | 180 | |
| 162 | - if ($previous !== null && !$previous->isEmpty()) { |
|
| 181 | + if ($previous !== null && !$previous->isEmpty()) |
|
| 182 | + { |
|
| 163 | 183 | $placementID++; |
| 164 | 184 | } |
| 165 | 185 | |
@@ -170,8 +190,10 @@ discard block |
||
| 170 | 190 | |
| 171 | 191 | private function getPropertyType(Dependency $dependency): string |
| 172 | 192 | { |
| 173 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 174 | - if ($stmt->name === $dependency->type->fullName && $stmt->alias) { |
|
| 193 | + foreach ($this->definition->getStmts() as $stmt) |
|
| 194 | + { |
|
| 195 | + if ($stmt->name === $dependency->type->fullName && $stmt->alias) |
|
| 196 | + { |
|
| 175 | 197 | return $stmt->alias; |
| 176 | 198 | } |
| 177 | 199 | } |
@@ -181,13 +203,16 @@ discard block |
||
| 181 | 203 | |
| 182 | 204 | private function getParamType(ClassNode\ConstructorParam $param): string |
| 183 | 205 | { |
| 184 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 185 | - if ($stmt->name === $param->type->fullName && $stmt->alias) { |
|
| 206 | + foreach ($this->definition->getStmts() as $stmt) |
|
| 207 | + { |
|
| 208 | + if ($stmt->name === $param->type->fullName && $stmt->alias) |
|
| 209 | + { |
|
| 186 | 210 | return $stmt->alias; |
| 187 | 211 | } |
| 188 | 212 | } |
| 189 | 213 | |
| 190 | - if ($param->type->alias) { |
|
| 214 | + if ($param->type->alias) |
|
| 215 | + { |
|
| 191 | 216 | return $param->type->alias; |
| 192 | 217 | } |
| 193 | 218 | |