@@ -25,7 +25,7 @@ |
||
25 | 25 | */ |
26 | 26 | public function leaveNode(Node $node) |
27 | 27 | { |
28 | - if ($node instanceof Node\Expr\Variable) { |
|
28 | + if ($node instanceof Node\Expr\Variable){ |
|
29 | 29 | $this->vars[] = $node->name; |
30 | 30 | } |
31 | 31 | } |
@@ -25,7 +25,8 @@ |
||
25 | 25 | */ |
26 | 26 | public function leaveNode(Node $node) |
27 | 27 | { |
28 | - if ($node instanceof Node\Expr\Variable) { |
|
28 | + if ($node instanceof Node\Expr\Variable) |
|
29 | + { |
|
29 | 30 | $this->vars[] = $node->name; |
30 | 31 | } |
31 | 32 | } |
@@ -27,17 +27,17 @@ |
||
27 | 27 | */ |
28 | 28 | public function leaveNode(Node $node) |
29 | 29 | { |
30 | - if (!$node instanceof Node\Stmt\Use_) { |
|
30 | + if (!$node instanceof Node\Stmt\Use_){ |
|
31 | 31 | return null; |
32 | 32 | } |
33 | 33 | |
34 | - foreach ($node->uses as $index => $use) { |
|
35 | - if ($use->name->toString() === PrototypeTrait::class) { |
|
34 | + foreach ($node->uses as $index => $use){ |
|
35 | + if ($use->name->toString() === PrototypeTrait::class){ |
|
36 | 36 | unset($node->uses[$index]); |
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - if (empty($node->uses)) { |
|
40 | + if (empty($node->uses)){ |
|
41 | 41 | return NodeTraverser::REMOVE_NODE; |
42 | 42 | } |
43 | 43 |
@@ -27,17 +27,21 @@ |
||
27 | 27 | */ |
28 | 28 | public function leaveNode(Node $node) |
29 | 29 | { |
30 | - if (!$node instanceof Node\Stmt\Use_) { |
|
30 | + if (!$node instanceof Node\Stmt\Use_) |
|
31 | + { |
|
31 | 32 | return null; |
32 | 33 | } |
33 | 34 | |
34 | - foreach ($node->uses as $index => $use) { |
|
35 | - if ($use->name->toString() === PrototypeTrait::class) { |
|
35 | + foreach ($node->uses as $index => $use) |
|
36 | + { |
|
37 | + if ($use->name->toString() === PrototypeTrait::class) |
|
38 | + { |
|
36 | 39 | unset($node->uses[$index]); |
37 | 40 | } |
38 | 41 | } |
39 | 42 | |
40 | - if (empty($node->uses)) { |
|
43 | + if (empty($node->uses)) |
|
44 | + { |
|
41 | 45 | return NodeTraverser::REMOVE_NODE; |
42 | 46 | } |
43 | 47 |
@@ -27,15 +27,15 @@ |
||
27 | 27 | */ |
28 | 28 | public function leaveNode(Node $node) |
29 | 29 | { |
30 | - if (!$node instanceof Node\Stmt\Class_) { |
|
30 | + if (!$node instanceof Node\Stmt\Class_){ |
|
31 | 31 | return null; |
32 | 32 | } |
33 | 33 | |
34 | 34 | $placementID = 0; |
35 | - foreach ($node->stmts as $index => $child) { |
|
35 | + foreach ($node->stmts as $index => $child){ |
|
36 | 36 | $placementID = $index; |
37 | - if ($child instanceof Node\Stmt\ClassMethod) { |
|
38 | - if ($child->name->name === '__construct') { |
|
37 | + if ($child instanceof Node\Stmt\ClassMethod){ |
|
38 | + if ($child->name->name === '__construct'){ |
|
39 | 39 | $node->setAttribute('constructor', $child); |
40 | 40 | |
41 | 41 | return null; |
@@ -27,15 +27,19 @@ |
||
27 | 27 | */ |
28 | 28 | public function leaveNode(Node $node) |
29 | 29 | { |
30 | - if (!$node instanceof Node\Stmt\Class_) { |
|
30 | + if (!$node instanceof Node\Stmt\Class_) |
|
31 | + { |
|
31 | 32 | return null; |
32 | 33 | } |
33 | 34 | |
34 | 35 | $placementID = 0; |
35 | - foreach ($node->stmts as $index => $child) { |
|
36 | + foreach ($node->stmts as $index => $child) |
|
37 | + { |
|
36 | 38 | $placementID = $index; |
37 | - if ($child instanceof Node\Stmt\ClassMethod) { |
|
38 | - if ($child->name->name === '__construct') { |
|
39 | + if ($child instanceof Node\Stmt\ClassMethod) |
|
40 | + { |
|
41 | + if ($child->name->name === '__construct') |
|
42 | + { |
|
39 | 43 | $node->setAttribute('constructor', $child); |
40 | 44 | |
41 | 45 | return null; |
@@ -38,12 +38,12 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function leaveNode(Node $node) |
40 | 40 | { |
41 | - if (!$node instanceof Node\Stmt\Class_) { |
|
41 | + if (!$node instanceof Node\Stmt\Class_){ |
|
42 | 42 | return null; |
43 | 43 | } |
44 | 44 | |
45 | 45 | $nodes = []; |
46 | - foreach ($this->definition->dependencies as $dependency) { |
|
46 | + foreach ($this->definition->dependencies as $dependency){ |
|
47 | 47 | $nodes[] = $this->buildProperty($dependency); |
48 | 48 | } |
49 | 49 | |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | */ |
60 | 60 | private function definePlacementID(Node\Stmt\Class_ $node): int |
61 | 61 | { |
62 | - foreach ($node->stmts as $index => $child) { |
|
63 | - if ($child instanceof Node\Stmt\ClassMethod || $child instanceof Node\Stmt\Property) { |
|
62 | + foreach ($node->stmts as $index => $child){ |
|
63 | + if ($child instanceof Node\Stmt\ClassMethod || $child instanceof Node\Stmt\Property){ |
|
64 | 64 | return $index; |
65 | 65 | } |
66 | 66 | } |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | */ |
88 | 88 | private function getPropertyType(Dependency $dependency): string |
89 | 89 | { |
90 | - foreach ($this->definition->getStmts() as $stmt) { |
|
91 | - if ($stmt->name === $dependency->type->fullName) { |
|
92 | - if ($stmt->alias) { |
|
90 | + foreach ($this->definition->getStmts() as $stmt){ |
|
91 | + if ($stmt->name === $dependency->type->fullName){ |
|
92 | + if ($stmt->alias){ |
|
93 | 93 | return $stmt->alias; |
94 | 94 | } |
95 | 95 | } |
@@ -38,12 +38,14 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function leaveNode(Node $node) |
40 | 40 | { |
41 | - if (!$node instanceof Node\Stmt\Class_) { |
|
41 | + if (!$node instanceof Node\Stmt\Class_) |
|
42 | + { |
|
42 | 43 | return null; |
43 | 44 | } |
44 | 45 | |
45 | 46 | $nodes = []; |
46 | - foreach ($this->definition->dependencies as $dependency) { |
|
47 | + foreach ($this->definition->dependencies as $dependency) |
|
48 | + { |
|
47 | 49 | $nodes[] = $this->buildProperty($dependency); |
48 | 50 | } |
49 | 51 | |
@@ -59,8 +61,10 @@ discard block |
||
59 | 61 | */ |
60 | 62 | private function definePlacementID(Node\Stmt\Class_ $node): int |
61 | 63 | { |
62 | - foreach ($node->stmts as $index => $child) { |
|
63 | - if ($child instanceof Node\Stmt\ClassMethod || $child instanceof Node\Stmt\Property) { |
|
64 | + foreach ($node->stmts as $index => $child) |
|
65 | + { |
|
66 | + if ($child instanceof Node\Stmt\ClassMethod || $child instanceof Node\Stmt\Property) |
|
67 | + { |
|
64 | 68 | return $index; |
65 | 69 | } |
66 | 70 | } |
@@ -87,9 +91,12 @@ discard block |
||
87 | 91 | */ |
88 | 92 | private function getPropertyType(Dependency $dependency): string |
89 | 93 | { |
90 | - foreach ($this->definition->getStmts() as $stmt) { |
|
91 | - if ($stmt->name === $dependency->type->fullName) { |
|
92 | - if ($stmt->alias) { |
|
94 | + foreach ($this->definition->getStmts() as $stmt) |
|
95 | + { |
|
96 | + if ($stmt->name === $dependency->type->fullName) |
|
97 | + { |
|
98 | + if ($stmt->alias) |
|
99 | + { |
|
93 | 100 | return $stmt->alias; |
94 | 101 | } |
95 | 102 | } |
@@ -42,16 +42,16 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function leaveNode(Node $node) |
44 | 44 | { |
45 | - if (!$node instanceof Node\Stmt\Namespace_) { |
|
45 | + if (!$node instanceof Node\Stmt\Namespace_){ |
|
46 | 46 | return null; |
47 | 47 | } |
48 | 48 | |
49 | 49 | $imported = []; |
50 | - if (!$this->node->hasConstructor && $this->node->constructorParams) { |
|
51 | - foreach ($this->node->constructorParams as $param) { |
|
52 | - if (!empty($param->type) && $param->type->fullName) { |
|
50 | + if (!$this->node->hasConstructor && $this->node->constructorParams){ |
|
51 | + foreach ($this->node->constructorParams as $param){ |
|
52 | + if (!empty($param->type) && $param->type->fullName){ |
|
53 | 53 | $import = [$param->type->fullName, $param->type->alias]; |
54 | - if (in_array($import, $imported, true)) { |
|
54 | + if (in_array($import, $imported, true)){ |
|
55 | 55 | continue; |
56 | 56 | } |
57 | 57 | |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | - foreach ($this->node->dependencies as $dependency) { |
|
64 | + foreach ($this->node->dependencies as $dependency){ |
|
65 | 65 | $import = [$dependency->type->fullName, $dependency->type->alias]; |
66 | - if (in_array($import, $imported, true)) { |
|
66 | + if (in_array($import, $imported, true)){ |
|
67 | 67 | continue; |
68 | 68 | } |
69 | 69 | |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | */ |
91 | 91 | private function definePlacementID(Node\Stmt\Namespace_ $node): int |
92 | 92 | { |
93 | - foreach ($node->stmts as $index => $child) { |
|
94 | - if ($child instanceof Node\Stmt\Class_) { |
|
93 | + foreach ($node->stmts as $index => $child){ |
|
94 | + if ($child instanceof Node\Stmt\Class_){ |
|
95 | 95 | return $index; |
96 | 96 | } |
97 | 97 | } |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | { |
109 | 109 | $uses = $this->getExistingUseParts($stmts); |
110 | 110 | |
111 | - foreach ($nodes as $i => $node) { |
|
112 | - if (!$node instanceof Node\Stmt\Use_) { |
|
111 | + foreach ($nodes as $i => $node){ |
|
112 | + if (!$node instanceof Node\Stmt\Use_){ |
|
113 | 113 | continue; |
114 | 114 | } |
115 | 115 | |
116 | - foreach ($node->uses as $use) { |
|
117 | - if (in_array($use->name->parts, $uses, true)) { |
|
116 | + foreach ($node->uses as $use){ |
|
117 | + if (in_array($use->name->parts, $uses, true)){ |
|
118 | 118 | unset($nodes[$i]); |
119 | 119 | } |
120 | 120 | } |
@@ -130,12 +130,12 @@ discard block |
||
130 | 130 | private function getExistingUseParts(array $stmts): array |
131 | 131 | { |
132 | 132 | $uses = []; |
133 | - foreach ($stmts as $stmt) { |
|
134 | - if (!$stmt instanceof Node\Stmt\Use_) { |
|
133 | + foreach ($stmts as $stmt){ |
|
134 | + if (!$stmt instanceof Node\Stmt\Use_){ |
|
135 | 135 | continue; |
136 | 136 | } |
137 | 137 | |
138 | - foreach ($stmt->uses as $use) { |
|
138 | + foreach ($stmt->uses as $use){ |
|
139 | 139 | $uses[] = $use->name->parts; |
140 | 140 | } |
141 | 141 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | private function buildUse(string $type, ?string $alias = null): Node\Stmt\Use_ |
152 | 152 | { |
153 | 153 | $b = new Use_(new Node\Name($type), Node\Stmt\Use_::TYPE_NORMAL); |
154 | - if (!empty($alias)) { |
|
154 | + if (!empty($alias)){ |
|
155 | 155 | $b->as($alias); |
156 | 156 | } |
157 | 157 |
@@ -42,16 +42,21 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function leaveNode(Node $node) |
44 | 44 | { |
45 | - if (!$node instanceof Node\Stmt\Namespace_) { |
|
45 | + if (!$node instanceof Node\Stmt\Namespace_) |
|
46 | + { |
|
46 | 47 | return null; |
47 | 48 | } |
48 | 49 | |
49 | 50 | $imported = []; |
50 | - if (!$this->node->hasConstructor && $this->node->constructorParams) { |
|
51 | - foreach ($this->node->constructorParams as $param) { |
|
52 | - if (!empty($param->type) && $param->type->fullName) { |
|
51 | + if (!$this->node->hasConstructor && $this->node->constructorParams) |
|
52 | + { |
|
53 | + foreach ($this->node->constructorParams as $param) |
|
54 | + { |
|
55 | + if (!empty($param->type) && $param->type->fullName) |
|
56 | + { |
|
53 | 57 | $import = [$param->type->fullName, $param->type->alias]; |
54 | - if (in_array($import, $imported, true)) { |
|
58 | + if (in_array($import, $imported, true)) |
|
59 | + { |
|
55 | 60 | continue; |
56 | 61 | } |
57 | 62 | |
@@ -61,9 +66,11 @@ discard block |
||
61 | 66 | } |
62 | 67 | } |
63 | 68 | |
64 | - foreach ($this->node->dependencies as $dependency) { |
|
69 | + foreach ($this->node->dependencies as $dependency) |
|
70 | + { |
|
65 | 71 | $import = [$dependency->type->fullName, $dependency->type->alias]; |
66 | - if (in_array($import, $imported, true)) { |
|
72 | + if (in_array($import, $imported, true)) |
|
73 | + { |
|
67 | 74 | continue; |
68 | 75 | } |
69 | 76 | |
@@ -90,8 +97,10 @@ discard block |
||
90 | 97 | */ |
91 | 98 | private function definePlacementID(Node\Stmt\Namespace_ $node): int |
92 | 99 | { |
93 | - foreach ($node->stmts as $index => $child) { |
|
94 | - if ($child instanceof Node\Stmt\Class_) { |
|
100 | + foreach ($node->stmts as $index => $child) |
|
101 | + { |
|
102 | + if ($child instanceof Node\Stmt\Class_) |
|
103 | + { |
|
95 | 104 | return $index; |
96 | 105 | } |
97 | 106 | } |
@@ -108,13 +117,17 @@ discard block |
||
108 | 117 | { |
109 | 118 | $uses = $this->getExistingUseParts($stmts); |
110 | 119 | |
111 | - foreach ($nodes as $i => $node) { |
|
112 | - if (!$node instanceof Node\Stmt\Use_) { |
|
120 | + foreach ($nodes as $i => $node) |
|
121 | + { |
|
122 | + if (!$node instanceof Node\Stmt\Use_) |
|
123 | + { |
|
113 | 124 | continue; |
114 | 125 | } |
115 | 126 | |
116 | - foreach ($node->uses as $use) { |
|
117 | - if (in_array($use->name->parts, $uses, true)) { |
|
127 | + foreach ($node->uses as $use) |
|
128 | + { |
|
129 | + if (in_array($use->name->parts, $uses, true)) |
|
130 | + { |
|
118 | 131 | unset($nodes[$i]); |
119 | 132 | } |
120 | 133 | } |
@@ -130,12 +143,15 @@ discard block |
||
130 | 143 | private function getExistingUseParts(array $stmts): array |
131 | 144 | { |
132 | 145 | $uses = []; |
133 | - foreach ($stmts as $stmt) { |
|
134 | - if (!$stmt instanceof Node\Stmt\Use_) { |
|
146 | + foreach ($stmts as $stmt) |
|
147 | + { |
|
148 | + if (!$stmt instanceof Node\Stmt\Use_) |
|
149 | + { |
|
135 | 150 | continue; |
136 | 151 | } |
137 | 152 | |
138 | - foreach ($stmt->uses as $use) { |
|
153 | + foreach ($stmt->uses as $use) |
|
154 | + { |
|
139 | 155 | $uses[] = $use->name->parts; |
140 | 156 | } |
141 | 157 | } |
@@ -151,7 +167,8 @@ discard block |
||
151 | 167 | private function buildUse(string $type, ?string $alias = null): Node\Stmt\Use_ |
152 | 168 | { |
153 | 169 | $b = new Use_(new Node\Name($type), Node\Stmt\Use_::TYPE_NORMAL); |
154 | - if (!empty($alias)) { |
|
170 | + if (!empty($alias)) |
|
171 | + { |
|
155 | 172 | $b->as($alias); |
156 | 173 | } |
157 | 174 |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function leaveNode(Node $node) |
44 | 44 | { |
45 | - if (!$node instanceof Node\Stmt\Class_) { |
|
45 | + if (!$node instanceof Node\Stmt\Class_){ |
|
46 | 46 | return null; |
47 | 47 | } |
48 | 48 | |
49 | 49 | $constructor = $this->getConstructorAttribute($node); |
50 | 50 | $this->addDependencies($constructor); |
51 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
51 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams){ |
|
52 | 52 | $this->addParentConstructorCall($constructor); |
53 | 53 | } |
54 | 54 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
68 | 68 | { |
69 | - foreach ($this->definition->dependencies as $name => $dependency) { |
|
69 | + foreach ($this->definition->dependencies as $name => $dependency){ |
|
70 | 70 | $constructor->params[] = (new Param($dependency->var))->setType( |
71 | 71 | new Node\Name($this->getPropertyType($dependency)) |
72 | 72 | )->getNode(); |
@@ -91,34 +91,34 @@ discard block |
||
91 | 91 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
92 | 92 | { |
93 | 93 | $parentConstructorDependencies = []; |
94 | - foreach ($this->definition->constructorParams as $param) { |
|
94 | + foreach ($this->definition->constructorParams as $param){ |
|
95 | 95 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
96 | 96 | |
97 | 97 | $cp = new Param($param->name); |
98 | - if (!empty($param->type)) { |
|
98 | + if (!empty($param->type)){ |
|
99 | 99 | $type = $this->getParamType($param); |
100 | - if ($param->nullable) { |
|
100 | + if ($param->nullable){ |
|
101 | 101 | $type = "?$type"; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $cp->setType(new Node\Name($type)); |
105 | 105 | } |
106 | 106 | |
107 | - if ($param->byRef) { |
|
107 | + if ($param->byRef){ |
|
108 | 108 | $cp->makeByRef(); |
109 | 109 | } |
110 | 110 | |
111 | - if ($param->isVariadic) { |
|
111 | + if ($param->isVariadic){ |
|
112 | 112 | $cp->makeVariadic(); |
113 | 113 | } |
114 | 114 | |
115 | - if ($param->hasDefault) { |
|
115 | + if ($param->hasDefault){ |
|
116 | 116 | $cp->setDefault($param->default); |
117 | 117 | } |
118 | 118 | $constructor->params[] = $cp->getNode(); |
119 | 119 | } |
120 | 120 | |
121 | - if ($parentConstructorDependencies) { |
|
121 | + if ($parentConstructorDependencies){ |
|
122 | 122 | array_unshift( |
123 | 123 | $constructor->stmts, |
124 | 124 | new Node\Stmt\Expression( |
@@ -153,18 +153,18 @@ discard block |
||
153 | 153 | |
154 | 154 | $params = []; |
155 | 155 | |
156 | - foreach ($this->definition->dependencies as $name => $dependency) { |
|
156 | + foreach ($this->definition->dependencies as $name => $dependency){ |
|
157 | 157 | $params[] = new Annotation\Line( |
158 | 158 | sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), |
159 | 159 | 'param' |
160 | 160 | ); |
161 | 161 | } |
162 | 162 | |
163 | - if (!$this->definition->hasConstructor) { |
|
164 | - foreach ($this->definition->constructorParams as $param) { |
|
165 | - if (!empty($param->type)) { |
|
163 | + if (!$this->definition->hasConstructor){ |
|
164 | + foreach ($this->definition->constructorParams as $param){ |
|
165 | + if (!empty($param->type)){ |
|
166 | 166 | $type = $this->getParamType($param); |
167 | - if ($param->nullable) { |
|
167 | + if ($param->nullable){ |
|
168 | 168 | $type = "$type|null"; |
169 | 169 | } |
170 | 170 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), |
173 | 173 | 'param' |
174 | 174 | ); |
175 | - } else { |
|
175 | + }else{ |
|
176 | 176 | $params[] = new Annotation\Line( |
177 | 177 | sprintf('$%s', $param->name), |
178 | 178 | 'param' |
@@ -183,12 +183,12 @@ discard block |
||
183 | 183 | |
184 | 184 | $placementID = 0; |
185 | 185 | $previous = null; |
186 | - foreach ($an->lines as $index => $line) { |
|
186 | + foreach ($an->lines as $index => $line){ |
|
187 | 187 | // always next node |
188 | 188 | $placementID = $index + 1; |
189 | 189 | |
190 | 190 | // inject before this parameters |
191 | - if ($line->is(['throws', 'return'])) { |
|
191 | + if ($line->is(['throws', 'return'])){ |
|
192 | 192 | // insert before given node |
193 | 193 | $placementID--; |
194 | 194 | break; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $previous = $line; |
198 | 198 | } |
199 | 199 | |
200 | - if ($previous !== null && !$previous->isEmpty()) { |
|
200 | + if ($previous !== null && !$previous->isEmpty()){ |
|
201 | 201 | $placementID++; |
202 | 202 | } |
203 | 203 | |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | */ |
213 | 213 | private function getPropertyType(Dependency $dependency): string |
214 | 214 | { |
215 | - foreach ($this->definition->getStmts() as $stmt) { |
|
216 | - if ($stmt->name === $dependency->type->fullName) { |
|
217 | - if ($stmt->alias) { |
|
215 | + foreach ($this->definition->getStmts() as $stmt){ |
|
216 | + if ($stmt->name === $dependency->type->fullName){ |
|
217 | + if ($stmt->alias){ |
|
218 | 218 | return $stmt->alias; |
219 | 219 | } |
220 | 220 | } |
@@ -229,15 +229,15 @@ discard block |
||
229 | 229 | */ |
230 | 230 | private function getParamType(ClassNode\ConstructorParam $param): string |
231 | 231 | { |
232 | - foreach ($this->definition->getStmts() as $stmt) { |
|
233 | - if ($stmt->name === $param->type->fullName) { |
|
234 | - if ($stmt->alias) { |
|
232 | + foreach ($this->definition->getStmts() as $stmt){ |
|
233 | + if ($stmt->name === $param->type->fullName){ |
|
234 | + if ($stmt->alias){ |
|
235 | 235 | return $stmt->alias; |
236 | 236 | } |
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | - if ($param->type->alias) { |
|
240 | + if ($param->type->alias){ |
|
241 | 241 | return $param->type->alias; |
242 | 242 | } |
243 | 243 |
@@ -42,13 +42,15 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function leaveNode(Node $node) |
44 | 44 | { |
45 | - if (!$node instanceof Node\Stmt\Class_) { |
|
45 | + if (!$node instanceof Node\Stmt\Class_) |
|
46 | + { |
|
46 | 47 | return null; |
47 | 48 | } |
48 | 49 | |
49 | 50 | $constructor = $this->getConstructorAttribute($node); |
50 | 51 | $this->addDependencies($constructor); |
51 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
52 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams) |
|
53 | + { |
|
52 | 54 | $this->addParentConstructorCall($constructor); |
53 | 55 | } |
54 | 56 | |
@@ -66,7 +68,8 @@ discard block |
||
66 | 68 | */ |
67 | 69 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
68 | 70 | { |
69 | - foreach ($this->definition->dependencies as $name => $dependency) { |
|
71 | + foreach ($this->definition->dependencies as $name => $dependency) |
|
72 | + { |
|
70 | 73 | $constructor->params[] = (new Param($dependency->var))->setType( |
71 | 74 | new Node\Name($this->getPropertyType($dependency)) |
72 | 75 | )->getNode(); |
@@ -91,34 +94,41 @@ discard block |
||
91 | 94 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
92 | 95 | { |
93 | 96 | $parentConstructorDependencies = []; |
94 | - foreach ($this->definition->constructorParams as $param) { |
|
97 | + foreach ($this->definition->constructorParams as $param) |
|
98 | + { |
|
95 | 99 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
96 | 100 | |
97 | 101 | $cp = new Param($param->name); |
98 | - if (!empty($param->type)) { |
|
102 | + if (!empty($param->type)) |
|
103 | + { |
|
99 | 104 | $type = $this->getParamType($param); |
100 | - if ($param->nullable) { |
|
105 | + if ($param->nullable) |
|
106 | + { |
|
101 | 107 | $type = "?$type"; |
102 | 108 | } |
103 | 109 | |
104 | 110 | $cp->setType(new Node\Name($type)); |
105 | 111 | } |
106 | 112 | |
107 | - if ($param->byRef) { |
|
113 | + if ($param->byRef) |
|
114 | + { |
|
108 | 115 | $cp->makeByRef(); |
109 | 116 | } |
110 | 117 | |
111 | - if ($param->isVariadic) { |
|
118 | + if ($param->isVariadic) |
|
119 | + { |
|
112 | 120 | $cp->makeVariadic(); |
113 | 121 | } |
114 | 122 | |
115 | - if ($param->hasDefault) { |
|
123 | + if ($param->hasDefault) |
|
124 | + { |
|
116 | 125 | $cp->setDefault($param->default); |
117 | 126 | } |
118 | 127 | $constructor->params[] = $cp->getNode(); |
119 | 128 | } |
120 | 129 | |
121 | - if ($parentConstructorDependencies) { |
|
130 | + if ($parentConstructorDependencies) |
|
131 | + { |
|
122 | 132 | array_unshift( |
123 | 133 | $constructor->stmts, |
124 | 134 | new Node\Stmt\Expression( |
@@ -153,18 +163,23 @@ discard block |
||
153 | 163 | |
154 | 164 | $params = []; |
155 | 165 | |
156 | - foreach ($this->definition->dependencies as $name => $dependency) { |
|
166 | + foreach ($this->definition->dependencies as $name => $dependency) |
|
167 | + { |
|
157 | 168 | $params[] = new Annotation\Line( |
158 | 169 | sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), |
159 | 170 | 'param' |
160 | 171 | ); |
161 | 172 | } |
162 | 173 | |
163 | - if (!$this->definition->hasConstructor) { |
|
164 | - foreach ($this->definition->constructorParams as $param) { |
|
165 | - if (!empty($param->type)) { |
|
174 | + if (!$this->definition->hasConstructor) |
|
175 | + { |
|
176 | + foreach ($this->definition->constructorParams as $param) |
|
177 | + { |
|
178 | + if (!empty($param->type)) |
|
179 | + { |
|
166 | 180 | $type = $this->getParamType($param); |
167 | - if ($param->nullable) { |
|
181 | + if ($param->nullable) |
|
182 | + { |
|
168 | 183 | $type = "$type|null"; |
169 | 184 | } |
170 | 185 | |
@@ -172,7 +187,9 @@ discard block |
||
172 | 187 | sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), |
173 | 188 | 'param' |
174 | 189 | ); |
175 | - } else { |
|
190 | + } |
|
191 | + else |
|
192 | + { |
|
176 | 193 | $params[] = new Annotation\Line( |
177 | 194 | sprintf('$%s', $param->name), |
178 | 195 | 'param' |
@@ -183,12 +200,14 @@ discard block |
||
183 | 200 | |
184 | 201 | $placementID = 0; |
185 | 202 | $previous = null; |
186 | - foreach ($an->lines as $index => $line) { |
|
203 | + foreach ($an->lines as $index => $line) |
|
204 | + { |
|
187 | 205 | // always next node |
188 | 206 | $placementID = $index + 1; |
189 | 207 | |
190 | 208 | // inject before this parameters |
191 | - if ($line->is(['throws', 'return'])) { |
|
209 | + if ($line->is(['throws', 'return'])) |
|
210 | + { |
|
192 | 211 | // insert before given node |
193 | 212 | $placementID--; |
194 | 213 | break; |
@@ -197,7 +216,8 @@ discard block |
||
197 | 216 | $previous = $line; |
198 | 217 | } |
199 | 218 | |
200 | - if ($previous !== null && !$previous->isEmpty()) { |
|
219 | + if ($previous !== null && !$previous->isEmpty()) |
|
220 | + { |
|
201 | 221 | $placementID++; |
202 | 222 | } |
203 | 223 | |
@@ -212,9 +232,12 @@ discard block |
||
212 | 232 | */ |
213 | 233 | private function getPropertyType(Dependency $dependency): string |
214 | 234 | { |
215 | - foreach ($this->definition->getStmts() as $stmt) { |
|
216 | - if ($stmt->name === $dependency->type->fullName) { |
|
217 | - if ($stmt->alias) { |
|
235 | + foreach ($this->definition->getStmts() as $stmt) |
|
236 | + { |
|
237 | + if ($stmt->name === $dependency->type->fullName) |
|
238 | + { |
|
239 | + if ($stmt->alias) |
|
240 | + { |
|
218 | 241 | return $stmt->alias; |
219 | 242 | } |
220 | 243 | } |
@@ -229,15 +252,19 @@ discard block |
||
229 | 252 | */ |
230 | 253 | private function getParamType(ClassNode\ConstructorParam $param): string |
231 | 254 | { |
232 | - foreach ($this->definition->getStmts() as $stmt) { |
|
233 | - if ($stmt->name === $param->type->fullName) { |
|
234 | - if ($stmt->alias) { |
|
255 | + foreach ($this->definition->getStmts() as $stmt) |
|
256 | + { |
|
257 | + if ($stmt->name === $param->type->fullName) |
|
258 | + { |
|
259 | + if ($stmt->alias) |
|
260 | + { |
|
235 | 261 | return $stmt->alias; |
236 | 262 | } |
237 | 263 | } |
238 | 264 | } |
239 | 265 | |
240 | - if ($param->type->alias) { |
|
266 | + if ($param->type->alias) |
|
267 | + { |
|
241 | 268 | return $param->type->alias; |
242 | 269 | } |
243 | 270 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public function __get(string $name) |
34 | 34 | { |
35 | 35 | $container = ContainerScope::getContainer(); |
36 | - if ($container === null || !$container->has(PrototypeRegistry::class)) { |
|
36 | + if ($container === null || !$container->has(PrototypeRegistry::class)){ |
|
37 | 37 | throw new ScopeException( |
38 | 38 | "Unable to resolve prototyped dependency `{$name}`, invalid container scope" |
39 | 39 | ); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $target === null || |
48 | 48 | $target instanceof \Throwable || |
49 | 49 | $target->type->fullName === null |
50 | - ) { |
|
50 | + ){ |
|
51 | 51 | throw new PrototypeException( |
52 | 52 | "Undefined prototype property `{$name}`", |
53 | 53 | 0, |
@@ -33,7 +33,8 @@ |
||
33 | 33 | public function __get(string $name) |
34 | 34 | { |
35 | 35 | $container = ContainerScope::getContainer(); |
36 | - if ($container === null || !$container->has(PrototypeRegistry::class)) { |
|
36 | + if ($container === null || !$container->has(PrototypeRegistry::class)) |
|
37 | + { |
|
37 | 38 | throw new ScopeException( |
38 | 39 | "Unable to resolve prototyped dependency `{$name}`, invalid container scope" |
39 | 40 | ); |
@@ -64,15 +64,15 @@ |
||
64 | 64 | public function resolveProperty(string $name) |
65 | 65 | { |
66 | 66 | $dependency = $this->dependencies[$name] ?? null; |
67 | - if ($dependency === null) { |
|
67 | + if ($dependency === null){ |
|
68 | 68 | return null; |
69 | 69 | } |
70 | 70 | |
71 | - try { |
|
71 | + try{ |
|
72 | 72 | $this->container->get($dependency->type->name()); |
73 | 73 | |
74 | 74 | return $dependency; |
75 | - } catch (ContainerExceptionInterface $e) { |
|
75 | + }catch (ContainerExceptionInterface $e){ |
|
76 | 76 | return $e; |
77 | 77 | } |
78 | 78 | } |
@@ -64,15 +64,19 @@ |
||
64 | 64 | public function resolveProperty(string $name) |
65 | 65 | { |
66 | 66 | $dependency = $this->dependencies[$name] ?? null; |
67 | - if ($dependency === null) { |
|
67 | + if ($dependency === null) |
|
68 | + { |
|
68 | 69 | return null; |
69 | 70 | } |
70 | 71 | |
71 | - try { |
|
72 | + try |
|
73 | + { |
|
72 | 74 | $this->container->get($dependency->type->name()); |
73 | 75 | |
74 | 76 | return $dependency; |
75 | - } catch (ContainerExceptionInterface $e) { |
|
77 | + } |
|
78 | + catch (ContainerExceptionInterface $e) |
|
79 | + { |
|
76 | 80 | return $e; |
77 | 81 | } |
78 | 82 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public static function shortName(string $name): string |
26 | 26 | { |
27 | 27 | $pos = mb_strrpos($name, '\\'); |
28 | - if ($pos === false) { |
|
28 | + if ($pos === false){ |
|
29 | 29 | return $name; |
30 | 30 | } |
31 | 31 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public static function trimTrailingDigits(string $name, int $number): string |
59 | 59 | { |
60 | 60 | $pos = mb_strripos($name, (string)$number); |
61 | - if ($pos === false) { |
|
61 | + if ($pos === false){ |
|
62 | 62 | return $name; |
63 | 63 | } |
64 | 64 |
@@ -25,7 +25,8 @@ discard block |
||
25 | 25 | public static function shortName(string $name): string |
26 | 26 | { |
27 | 27 | $pos = mb_strrpos($name, '\\'); |
28 | - if ($pos === false) { |
|
28 | + if ($pos === false) |
|
29 | + { |
|
29 | 30 | return $name; |
30 | 31 | } |
31 | 32 | |
@@ -58,7 +59,8 @@ discard block |
||
58 | 59 | public static function trimTrailingDigits(string $name, int $number): string |
59 | 60 | { |
60 | 61 | $pos = mb_strripos($name, (string)$number); |
61 | - if ($pos === false) { |
|
62 | + if ($pos === false) |
|
63 | + { |
|
62 | 64 | return $name; |
63 | 65 | } |
64 | 66 |