Skip to content

Commit

Permalink
[NodeTypeResolver] Handle crash PHPStan\File\CouldNotReadFileExceptio…
Browse files Browse the repository at this point in the history
…n: Could not read file on IntermediateSourceLocator (#5438)

* [NodeTypeResolver] Handle crash PHPStan\File\CouldNotReadFileException: Could not read file on IntermediateSourceLocator

* also handle on locateIdentifiersByType()

* also handle on locateIdentifiersByType()
  • Loading branch information
samsonasik committed Jan 6, 2024
1 parent 9a794f4 commit a8cc19a
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPStan\BetterReflection\Reflection\Reflection;
use PHPStan\BetterReflection\Reflector\Reflector;
use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator;
use PHPStan\File\CouldNotReadFileException;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;

final class IntermediateSourceLocator implements SourceLocator
Expand All @@ -22,7 +23,12 @@ public function locateIdentifier(Reflector $reflector, Identifier $identifier):
{
$sourceLocator = $this->dynamicSourceLocatorProvider->provide();

$reflection = $sourceLocator->locateIdentifier($reflector, $identifier);
try {
$reflection = $sourceLocator->locateIdentifier($reflector, $identifier);
} catch (CouldNotReadFileException) {
return null;
}

if ($reflection instanceof Reflection) {
return $reflection;
}
Expand All @@ -38,7 +44,12 @@ public function locateIdentifiersByType(Reflector $reflector, IdentifierType $id
{
$sourceLocator = $this->dynamicSourceLocatorProvider->provide();

$reflections = $sourceLocator->locateIdentifiersByType($reflector, $identifierType);
try {
$reflections = $sourceLocator->locateIdentifiersByType($reflector, $identifierType);
} catch (CouldNotReadFileException) {
return [];
}

if ($reflections !== []) {
return $reflections;
}
Expand Down

0 comments on commit a8cc19a

Please sign in to comment.