|
4 | 4 |
|
5 | 5 | namespace Smeghead\PhpClassDiagram\Php; |
6 | 6 |
|
7 | | -use PhpParser\NodeFinder; |
8 | | -use PhpParser\Node; |
9 | | -use PhpParser\Node\{ |
10 | | - NullableType, |
11 | | - Identifier, |
12 | | - Name, |
13 | | - UnionType, |
14 | | -}; |
15 | 7 | use PhpParser\Node\Name\FullyQualified; |
16 | 8 | use PhpParser\Node\Stmt; |
17 | 9 | use PhpParser\Node\Stmt\{ |
|
25 | 17 | Use_, |
26 | 18 | }; |
27 | 19 | use Smeghead\PhpClassDiagram\Php\Doc\PhpDocComment; |
28 | | -use Smeghead\PhpClassDiagram\Php\Finder\FindConstructerProperties; |
| 20 | +use Smeghead\PhpClassDiagram\Php\Finders\FindConstructerProperties; |
29 | 21 |
|
30 | 22 | class PhpClass |
31 | 23 | { |
@@ -156,27 +148,13 @@ private function getUsesRec($stmts, $uses = []) |
156 | 148 | * * useしているクラスに目的のクラスがあるかを探す |
157 | 149 | * * 自身のクラス名が目的のクラスかどうか ... (不要かもしれない。暗黙の参照と統合可能 |
158 | 150 | * * 暗黙の参照として、自身のnamespaceを返却する |
| 151 | + * |
| 152 | + * Since name resolution is done with NameResolver, unnecessary processing has been deleted. |
159 | 153 | */ |
160 | 154 | private function findNamespaceByTypeParts(array $type_parts): array |
161 | 155 | { |
162 | | - $type = str_replace('[]', '', array_pop($type_parts)); |
163 | | - $primitives = ['string', 'bool', 'boolean', 'int', 'integer', 'float', 'double', 'array', 'object', 'resource']; |
164 | | - if (in_array($type, $primitives)) { |
165 | | - return []; |
166 | | - } |
167 | | - foreach ($this->getUses() as $u) { |
168 | | - if ($u->getName() === $type) { |
169 | | - return $u->getNamespace(); |
170 | | - } |
171 | | - } |
172 | | - // 探したいクラスが、自身の型だった場合 |
173 | | - $t = $this->getClassType(); |
174 | | - if ($t->getName() === $type) { |
175 | | - return $t->getNamespace(); |
176 | | - } |
177 | | - |
178 | | - // 暗黙的な参照と見做す |
179 | | - return $this->getNamespace(); |
| 156 | + array_pop($type_parts); |
| 157 | + return $type_parts; |
180 | 158 | } |
181 | 159 |
|
182 | 160 | /** @return PhpMethod[] メソッド一覧 */ |
@@ -213,25 +191,19 @@ public function getExtends(): array |
213 | 191 | '', |
214 | 192 | end($Name->parts) |
215 | 193 | ); |
216 | | - } else { |
217 | | - $parts = $Name->parts; |
218 | | - $namespace = []; |
219 | | - if (count($parts) > 0) { |
220 | | - $namespace = $this->findNamespaceByTypeParts($parts); |
221 | | - $typeName = array_pop($parts); |
222 | | - } |
223 | | - $extends[] = new PhpType(array_merge($namespace, $parts), 'Stmt_Class', $typeName); |
224 | 194 | } |
225 | 195 | } |
| 196 | + |
226 | 197 | if (!empty($this->syntax->implements)) { |
227 | | - foreach ($this->syntax->implements as $i) { |
228 | | - $parts = $i->parts; |
229 | | - $namespace = []; |
230 | | - if (count($parts) > 0) { |
231 | | - $namespace = $this->findNamespaceByTypeParts($parts); |
232 | | - $typeName = array_pop($parts); |
| 198 | + foreach ($this->syntax->implements as $Name) { |
| 199 | + // $parts = $i->parts; |
| 200 | + if ($Name instanceof FullyQualified) { |
| 201 | + $extends[] = new PhpType( |
| 202 | + array_slice($Name->parts, 0, count($Name->parts) - 1), |
| 203 | + '', |
| 204 | + end($Name->parts) |
| 205 | + ); |
233 | 206 | } |
234 | | - $extends[] = new PhpType(array_merge($namespace, $parts), 'Stmt_Interface', $typeName); |
235 | 207 | } |
236 | 208 | } |
237 | 209 | return $extends; |
|
0 commit comments