@@ -24,7 +24,8 @@ |
||
| 24 | 24 | { |
| 25 | 25 | public function setUp(): void |
| 26 | 26 | { |
| 27 | - if ((string)ini_get('zend.assertions') === 1) { |
|
| 27 | + if ((string)ini_get('zend.assertions') === 1) |
|
| 28 | + { |
|
| 28 | 29 | ini_set('zend.assertions', 0); |
| 29 | 30 | } |
| 30 | 31 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | { |
| 20 | 20 | public 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]) |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | { |
| 66 | 66 | $i = new Injector(); |
| 67 | 67 | |
| 68 | - $filename = __DIR__ . '/Fixtures/TestEmptyClass.php'; |
|
| 68 | + $filename = __DIR__.'/Fixtures/TestEmptyClass.php'; |
|
| 69 | 69 | $content = file_get_contents($filename); |
| 70 | 70 | $printed = $i->injectDependencies( |
| 71 | 71 | file_get_contents($filename), |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | { |
| 84 | 84 | $i = new Injector(); |
| 85 | 85 | |
| 86 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 86 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 87 | 87 | $r = $i->injectDependencies( |
| 88 | 88 | file_get_contents($filename), |
| 89 | 89 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | $i = new Injector(); |
| 110 | 110 | |
| 111 | - $filename = __DIR__ . '/Fixtures/ChildClass.php'; |
|
| 111 | + $filename = __DIR__.'/Fixtures/ChildClass.php'; |
|
| 112 | 112 | $r = $i->injectDependencies( |
| 113 | 113 | file_get_contents($filename), |
| 114 | 114 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | $i = new Injector(); |
| 128 | 128 | |
| 129 | - $filename = __DIR__ . '/Fixtures/ChildWithConstructorClass.php'; |
|
| 129 | + $filename = __DIR__.'/Fixtures/ChildWithConstructorClass.php'; |
|
| 130 | 130 | $r = $i->injectDependencies( |
| 131 | 131 | file_get_contents($filename), |
| 132 | 132 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function testModifyConstructor(): void |
| 144 | 144 | { |
| 145 | - $filename = __DIR__ . '/Fixtures/WithConstructor.php'; |
|
| 145 | + $filename = __DIR__.'/Fixtures/WithConstructor.php'; |
|
| 146 | 146 | $extractor = new Traverse\Extractor(); |
| 147 | 147 | |
| 148 | 148 | $parameters = $extractor->extractFromFilename($filename); |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | public function testPriorOptionalConstructorParameters(): void |
| 170 | 170 | { |
| 171 | - $filename = __DIR__ . '/Fixtures/OptionalConstructorArgsClass.php'; |
|
| 171 | + $filename = __DIR__.'/Fixtures/OptionalConstructorArgsClass.php'; |
|
| 172 | 172 | $extractor = new Traverse\Extractor(); |
| 173 | 173 | |
| 174 | 174 | $parameters = $extractor->extractFromFilename($filename); |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | { |
| 200 | 200 | $i = new Injector(); |
| 201 | 201 | |
| 202 | - $filename = __DIR__ . '/ClassNode/ConflictResolver/Fixtures/ChildClass.php'; |
|
| 202 | + $filename = __DIR__.'/ClassNode/ConflictResolver/Fixtures/ChildClass.php'; |
|
| 203 | 203 | $printed = $i->injectDependencies( |
| 204 | 204 | file_get_contents($filename), |
| 205 | 205 | $this->getDefinition( |
@@ -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 | } |
@@ -43,9 +43,12 @@ discard block |
||
| 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 | } |
@@ -56,7 +59,8 @@ discard block |
||
| 56 | 59 | |
| 57 | 60 | private function promotedProperties(Node $node): void |
| 58 | 61 | { |
| 59 | - if (!$node instanceof Node\Param || !$node->var instanceof Node\Expr\Variable) { |
|
| 62 | + if (!$node instanceof Node\Param || !$node->var instanceof Node\Expr\Variable) |
|
| 63 | + { |
|
| 60 | 64 | return; |
| 61 | 65 | } |
| 62 | 66 | |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | $node->var instanceof Node\Expr\Variable && |
| 39 | 39 | $node->var->name === 'this' && |
| 40 | 40 | $node->name instanceof Node\Identifier |
| 41 | - ) { |
|
| 41 | + ){ |
|
| 42 | 42 | $this->requested[$node->name->name] = $node->name->name; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if ($node instanceof Node\Stmt\Property) { |
|
| 46 | - foreach ($node->props as $prop) { |
|
| 47 | - if ($prop instanceof Node\Stmt\PropertyProperty) { |
|
| 45 | + if ($node instanceof Node\Stmt\Property){ |
|
| 46 | + foreach ($node->props as $prop){ |
|
| 47 | + if ($prop instanceof Node\Stmt\PropertyProperty){ |
|
| 48 | 48 | $this->properties[$prop->name->name] = $prop->name->name; |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | private function promotedProperties(Node $node): void |
| 57 | 57 | { |
| 58 | - if (!$node instanceof Node\Param || !$node->var instanceof Node\Expr\Variable) { |
|
| 58 | + if (!$node instanceof Node\Param || !$node->var instanceof Node\Expr\Variable){ |
|
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $node->flags & Node\Stmt\Class_::MODIFIER_PUBLIC || |
| 64 | 64 | $node->flags & Node\Stmt\Class_::MODIFIER_PROTECTED || |
| 65 | 65 | $node->flags & Node\Stmt\Class_::MODIFIER_PRIVATE |
| 66 | - ) { |
|
| 66 | + ){ |
|
| 67 | 67 | $this->properties[$node->var->name] = $node->var->name; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -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 | - $this->assertStringContainsString(Fixtures\Some::class . ';', $r); |
|
| 38 | - $this->assertStringContainsString(Fixtures\SubFolder\Some::class . ' as Some2;', $r); |
|
| 39 | - $this->assertStringNotContainsString(Fixtures\SubFolder\Some::class . ';', $r); |
|
| 40 | - $this->assertStringContainsString(Fixtures\ATest3::class . ';', $r); |
|
| 37 | + $this->assertStringContainsString(Fixtures\Some::class.';', $r); |
|
| 38 | + $this->assertStringContainsString(Fixtures\SubFolder\Some::class.' as Some2;', $r); |
|
| 39 | + $this->assertStringNotContainsString(Fixtures\SubFolder\Some::class.';', $r); |
|
| 40 | + $this->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 | - $this->assertStringContainsString(Fixtures\Some::class . ' as FTest;', $r); |
|
| 64 | - $this->assertStringNotContainsString(Fixtures\Some::class . ';', $r); |
|
| 65 | - $this->assertStringContainsString(Fixtures\SubFolder\Some::class . ' as TestAlias;', $r); |
|
| 66 | - $this->assertStringNotContainsString(Fixtures\SubFolder\Some::class . ';', $r); |
|
| 67 | - $this->assertStringContainsString(Fixtures\ATest3::class . ' as ATest;', $r); |
|
| 68 | - $this->assertStringNotContainsString(Fixtures\ATest3::class . ';', $r); |
|
| 63 | + $this->assertStringContainsString(Fixtures\Some::class.' as FTest;', $r); |
|
| 64 | + $this->assertStringNotContainsString(Fixtures\Some::class.';', $r); |
|
| 65 | + $this->assertStringContainsString(Fixtures\SubFolder\Some::class.' as TestAlias;', $r); |
|
| 66 | + $this->assertStringNotContainsString(Fixtures\SubFolder\Some::class.';', $r); |
|
| 67 | + $this->assertStringContainsString(Fixtures\ATest3::class.' as ATest;', $r); |
|
| 68 | + $this->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 | - $this->assertStringContainsString(Fixtures\Some::class . ';', $r); |
|
| 92 | - $this->assertStringContainsString(Fixtures\SubFolder\Some::class . ' as Some2;', $r); |
|
| 93 | - $this->assertStringNotContainsString(Fixtures\SubFolder\Some::class . ';', $r); |
|
| 94 | - $this->assertStringContainsString(Fixtures\ATest3::class . ' as ATestAlias;', $r); |
|
| 95 | - $this->assertStringNotContainsString(Fixtures\ATest3::class . ';', $r); |
|
| 91 | + $this->assertStringContainsString(Fixtures\Some::class.';', $r); |
|
| 92 | + $this->assertStringContainsString(Fixtures\SubFolder\Some::class.' as Some2;', $r); |
|
| 93 | + $this->assertStringNotContainsString(Fixtures\SubFolder\Some::class.';', $r); |
|
| 94 | + $this->assertStringContainsString(Fixtures\ATest3::class.' as ATestAlias;', $r); |
|
| 95 | + $this->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 | - $this->assertStringContainsString(Fixtures\Some::class . ';', $r); |
|
| 113 | + $this->assertStringContainsString(Fixtures\Some::class.';', $r); |
|
| 114 | 114 | $this->assertStringContainsString('__construct(private readonly Some $test)', $r); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -17,18 +17,18 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | public function __construct( |
| 19 | 19 | private readonly ClassNode $definition |
| 20 | - ) { |
|
| 20 | + ){ |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public function leaveNode(Node $node): int|Node|null |
|
| 23 | + public function leaveNode(Node $node): int | Node | null |
|
| 24 | 24 | { |
| 25 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 25 | + if (!$node instanceof Node\Stmt\Class_){ |
|
| 26 | 26 | return null; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | $constructor = $this->getConstructorAttribute($node); |
| 30 | 30 | $this->addDependencies($constructor); |
| 31 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
| 31 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams){ |
|
| 32 | 32 | $this->addParentConstructorCall($constructor); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
| 42 | 42 | { |
| 43 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 43 | + foreach ($this->definition->dependencies as $dependency){ |
|
| 44 | 44 | \array_unshift($constructor->params, $this->buildConstructorParam($dependency)); |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -57,34 +57,34 @@ discard block |
||
| 57 | 57 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
| 58 | 58 | { |
| 59 | 59 | $parentConstructorDependencies = []; |
| 60 | - foreach ($this->definition->constructorParams as $param) { |
|
| 60 | + foreach ($this->definition->constructorParams as $param){ |
|
| 61 | 61 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
| 62 | 62 | |
| 63 | 63 | $cp = new Param($param->name); |
| 64 | - if (!empty($param->type)) { |
|
| 64 | + if (!empty($param->type)){ |
|
| 65 | 65 | $type = $this->getParamType($param); |
| 66 | - if ($param->nullable) { |
|
| 66 | + if ($param->nullable){ |
|
| 67 | 67 | $type = \sprintf('?%s', $type); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | $cp->setType(new Node\Name($type)); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if ($param->byRef) { |
|
| 73 | + if ($param->byRef){ |
|
| 74 | 74 | $cp->makeByRef(); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if ($param->isVariadic) { |
|
| 77 | + if ($param->isVariadic){ |
|
| 78 | 78 | $cp->makeVariadic(); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - if ($param->hasDefault) { |
|
| 81 | + if ($param->hasDefault){ |
|
| 82 | 82 | $cp->setDefault($param->default); |
| 83 | 83 | } |
| 84 | 84 | $constructor->params[] = $cp->getNode(); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if ($parentConstructorDependencies !== []) { |
|
| 87 | + if ($parentConstructorDependencies !== []){ |
|
| 88 | 88 | \array_unshift( |
| 89 | 89 | $constructor->stmts, |
| 90 | 90 | new Node\Stmt\Expression( |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | private function getPropertyType(Dependency $dependency): string |
| 107 | 107 | { |
| 108 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 109 | - if ($stmt->name === $dependency->type->fullName && $stmt->alias) { |
|
| 108 | + foreach ($this->definition->getStmts() as $stmt){ |
|
| 109 | + if ($stmt->name === $dependency->type->fullName && $stmt->alias){ |
|
| 110 | 110 | return $stmt->alias; |
| 111 | 111 | } |
| 112 | 112 | } |
@@ -116,13 +116,13 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | private function getParamType(ClassNode\ConstructorParam $param): string |
| 118 | 118 | { |
| 119 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 120 | - if ($stmt->name === $param->type->fullName && $stmt->alias) { |
|
| 119 | + foreach ($this->definition->getStmts() as $stmt){ |
|
| 120 | + if ($stmt->name === $param->type->fullName && $stmt->alias){ |
|
| 121 | 121 | return $stmt->alias; |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if ($param->type->alias) { |
|
| 125 | + if ($param->type->alias){ |
|
| 126 | 126 | return $param->type->alias; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -22,13 +22,15 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | public function leaveNode(Node $node): int|Node|null |
| 24 | 24 | { |
| 25 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 25 | + if (!$node instanceof Node\Stmt\Class_) |
|
| 26 | + { |
|
| 26 | 27 | return null; |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | $constructor = $this->getConstructorAttribute($node); |
| 30 | 31 | $this->addDependencies($constructor); |
| 31 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
| 32 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams) |
|
| 33 | + { |
|
| 32 | 34 | $this->addParentConstructorCall($constructor); |
| 33 | 35 | } |
| 34 | 36 | |
@@ -40,7 +42,8 @@ discard block |
||
| 40 | 42 | */ |
| 41 | 43 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
| 42 | 44 | { |
| 43 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 45 | + foreach ($this->definition->dependencies as $dependency) |
|
| 46 | + { |
|
| 44 | 47 | \array_unshift($constructor->params, $this->buildConstructorParam($dependency)); |
| 45 | 48 | } |
| 46 | 49 | } |
@@ -57,34 +60,41 @@ discard block |
||
| 57 | 60 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
| 58 | 61 | { |
| 59 | 62 | $parentConstructorDependencies = []; |
| 60 | - foreach ($this->definition->constructorParams as $param) { |
|
| 63 | + foreach ($this->definition->constructorParams as $param) |
|
| 64 | + { |
|
| 61 | 65 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
| 62 | 66 | |
| 63 | 67 | $cp = new Param($param->name); |
| 64 | - if (!empty($param->type)) { |
|
| 68 | + if (!empty($param->type)) |
|
| 69 | + { |
|
| 65 | 70 | $type = $this->getParamType($param); |
| 66 | - if ($param->nullable) { |
|
| 71 | + if ($param->nullable) |
|
| 72 | + { |
|
| 67 | 73 | $type = \sprintf('?%s', $type); |
| 68 | 74 | } |
| 69 | 75 | |
| 70 | 76 | $cp->setType(new Node\Name($type)); |
| 71 | 77 | } |
| 72 | 78 | |
| 73 | - if ($param->byRef) { |
|
| 79 | + if ($param->byRef) |
|
| 80 | + { |
|
| 74 | 81 | $cp->makeByRef(); |
| 75 | 82 | } |
| 76 | 83 | |
| 77 | - if ($param->isVariadic) { |
|
| 84 | + if ($param->isVariadic) |
|
| 85 | + { |
|
| 78 | 86 | $cp->makeVariadic(); |
| 79 | 87 | } |
| 80 | 88 | |
| 81 | - if ($param->hasDefault) { |
|
| 89 | + if ($param->hasDefault) |
|
| 90 | + { |
|
| 82 | 91 | $cp->setDefault($param->default); |
| 83 | 92 | } |
| 84 | 93 | $constructor->params[] = $cp->getNode(); |
| 85 | 94 | } |
| 86 | 95 | |
| 87 | - if ($parentConstructorDependencies !== []) { |
|
| 96 | + if ($parentConstructorDependencies !== []) |
|
| 97 | + { |
|
| 88 | 98 | \array_unshift( |
| 89 | 99 | $constructor->stmts, |
| 90 | 100 | new Node\Stmt\Expression( |
@@ -105,8 +115,10 @@ discard block |
||
| 105 | 115 | |
| 106 | 116 | private function getPropertyType(Dependency $dependency): string |
| 107 | 117 | { |
| 108 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 109 | - if ($stmt->name === $dependency->type->fullName && $stmt->alias) { |
|
| 118 | + foreach ($this->definition->getStmts() as $stmt) |
|
| 119 | + { |
|
| 120 | + if ($stmt->name === $dependency->type->fullName && $stmt->alias) |
|
| 121 | + { |
|
| 110 | 122 | return $stmt->alias; |
| 111 | 123 | } |
| 112 | 124 | } |
@@ -116,13 +128,16 @@ discard block |
||
| 116 | 128 | |
| 117 | 129 | private function getParamType(ClassNode\ConstructorParam $param): string |
| 118 | 130 | { |
| 119 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 120 | - if ($stmt->name === $param->type->fullName && $stmt->alias) { |
|
| 131 | + foreach ($this->definition->getStmts() as $stmt) |
|
| 132 | + { |
|
| 133 | + if ($stmt->name === $param->type->fullName && $stmt->alias) |
|
| 134 | + { |
|
| 121 | 135 | return $stmt->alias; |
| 122 | 136 | } |
| 123 | 137 | } |
| 124 | 138 | |
| 125 | - if ($param->type->alias) { |
|
| 139 | + if ($param->type->alias) |
|
| 140 | + { |
|
| 126 | 141 | return $param->type->alias; |
| 127 | 142 | } |
| 128 | 143 | |