Skip to content

Commit

Permalink
Throw type in result cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 23, 2021
1 parent 1608a2d commit 30ec3a0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Dependency/DependencyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPStan\Reflection\ReflectionWithFilename;
use PHPStan\Type\ClosureType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Type;

class DependencyResolver
{
Expand Down Expand Up @@ -57,13 +58,15 @@ public function resolveDependencies(\PhpParser\Node $node, Scope $scope): NodeDe
$nativeMethod = $scope->getFunction();
if ($nativeMethod !== null) {
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($nativeMethod->getVariants());
$this->extractThrowType($nativeMethod->getThrowType(), $dependenciesReflections);
if ($parametersAcceptor instanceof \PHPStan\Reflection\ParametersAcceptorWithPhpDocs) {
$this->extractFromParametersAcceptor($parametersAcceptor, $dependenciesReflections);
}
}
} elseif ($node instanceof InFunctionNode) {
$functionReflection = $scope->getFunction();
if ($functionReflection !== null) {
$this->extractThrowType($functionReflection->getThrowType(), $dependenciesReflections);
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants());

if ($parametersAcceptor instanceof ParametersAcceptorWithPhpDocs) {
Expand Down Expand Up @@ -269,4 +272,22 @@ private function extractFromParametersAcceptor(
}
}

/**
* @param Type|null $throwType
* @param ReflectionWithFilename[] $dependenciesReflections
*/
private function extractThrowType(
?Type $throwType,
array &$dependenciesReflections
): void
{
if ($throwType === null) {
return;
}

foreach ($throwType->getReferencedClasses() as $referencedClass) {
$this->addClassToDependencies($referencedClass, $dependenciesReflections);
}
}

}

0 comments on commit 30ec3a0

Please sign in to comment.