Skip to content

Commit 45774c5

Browse files
wip
1 parent 26eb956 commit 45774c5

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

src/Analyzer/FileVisitor.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,25 @@ public function enterNode(Node $node): void
2929
{
3030
$this->handleClassNode($node);
3131

32+
// handles anonymous class definition like new class() {}
3233
$this->handleAnonClassNode($node);
3334

35+
// handles enum definition
3436
$this->handleEnumNode($node);
3537

38+
// handles interface definition like interface MyInterface {}
39+
$this->handleInterfaceNode($node);
40+
41+
// handles trait definition like trait MyTrait {}
42+
$this->handleTraitNode($node);
43+
3644
// handles code like $constantValue = StaticClass::constant;
3745
$this->handleStaticClassConstantNode($node);
3846

3947
// handles code like $static = StaticClass::foo();
4048
$this->handleStaticClassCallsNode($node);
4149

50+
// handles code lik $a instanceof MyClass
4251
$this->handleInstanceOf($node);
4352

4453
$this->handleNewExpression($node);
@@ -49,12 +58,9 @@ public function enterNode(Node $node): void
4958

5059
$this->handleParamDependency($node);
5160

52-
$this->handleInterfaceNode($node);
53-
54-
$this->handleTraitNode($node);
55-
5661
$this->handleReturnTypeDependency($node);
5762

63+
// handles attribute definition like #[MyAttribute]
5864
$this->handleAttributeNode($node);
5965
}
6066

@@ -248,7 +254,7 @@ private function handleTypedProperty(Node $node): void
248254

249255
$type = $node->type instanceof NullableType ? $node->type->type : $node->type;
250256

251-
if (!method_exists($type, 'toString')) {
257+
if (!($type instanceof Node\Name\FullyQualified)) {
252258
return;
253259
}
254260

@@ -349,18 +355,13 @@ private function addParamDependency(Node\Param $node): void
349355
return;
350356
}
351357

352-
$type = $node->type;
353-
if ($type instanceof NullableType) {
354-
/** @var NullableType * */
355-
$nullableType = $type;
356-
$type = $nullableType->type;
357-
}
358+
$type = $node->type instanceof NullableType ? $node->type->type : $node->type;
358359

359-
if (method_exists($type, 'isSpecialClassName') && true === $type->isSpecialClassName()) {
360+
if (!($type instanceof Node\Name\FullyQualified)) {
360361
return;
361362
}
362363

363-
if (!method_exists($type, 'toString')) {
364+
if ($type->isSpecialClassName()) {
364365
return;
365366
}
366367

@@ -374,6 +375,24 @@ private function addParamDependency(Node\Param $node): void
374375

375376
private function isBuiltInType(string $typeName): bool
376377
{
377-
return \in_array($typeName, ['bool', 'int', 'float', 'string', 'array', 'resource', 'object', 'null']);
378+
$builtInTypes = [
379+
'bool',
380+
'int',
381+
'float',
382+
'string',
383+
'array',
384+
'object',
385+
'resource',
386+
'never',
387+
'void',
388+
'false',
389+
'true',
390+
'null',
391+
'callable',
392+
'mixed',
393+
'iterable',
394+
];
395+
396+
return \in_array($typeName, $builtInTypes);
378397
}
379398
}

0 commit comments

Comments
 (0)