Skip to content

Commit

Permalink
Fixed CallableType::getReferencedClasses()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 1, 2021
1 parent 5ad91d2 commit 09da0a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Type/CallableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public function __construct(
*/
public function getReferencedClasses(): array
{
return [];
$classes = [];
foreach ($this->parameters as $parameter) {
$classes = array_merge($classes, $parameter->getType()->getReferencedClasses());
}

return array_merge($classes, $this->returnType->getReferencedClasses());
}

public function accepts(Type $type, bool $strictTypes): TrinaryLogic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ public function testExistingClassInTypehint(): void
'Parameter $array of method TestMethodTypehints\FooMethodTypehints::unknownTypesInArrays() has invalid typehint type TestMethodTypehints\AnotherNonexistentClass.',
102,
],
[
'Parameter $cb of method TestMethodTypehints\CallableTypehints::doFoo() has invalid typehint type TestMethodTypehints\Bla.',
113,
],
[
'Parameter $cb of method TestMethodTypehints\CallableTypehints::doFoo() has invalid typehint type TestMethodTypehints\Ble.',
113,
],
]);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/PHPStan/Rules/Methods/data/typehints.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,14 @@ function unknownTypesInArrays(array $array)
}

}

class CallableTypehints
{

/** @param callable(Bla): Ble $cb */
public function doFoo(callable $cb): void
{

}

}

0 comments on commit 09da0a3

Please sign in to comment.