@@ -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 | } |
@@ -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 |
@@ -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 |