Skip to content

Commit

Permalink
[PHPStan] Handle PHPStan internal ShouldNotHappenException on FamilyR…
Browse files Browse the repository at this point in the history
…elationsAnalyzer and PHPStanNodeScopeResolver (#5885)

* [PHPStan] Handle PHPStan internal ShouldNotHappenException on FamilyRelationsAnalyzer

* fix
  • Loading branch information
samsonasik committed May 16, 2024
1 parent 6a5f6c5 commit db213ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/FamilyTree/Reflection/FamilyRelationsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\ShouldNotHappenException;
use Rector\Caching\Cache;
use Rector\Caching\Enum\CacheKey;
use Rector\NodeNameResolver\NodeNameResolver;
Expand Down Expand Up @@ -113,7 +114,7 @@ private function loadClasses(): void
foreach ($classNamesCache as $classNameCache) {
try {
$this->reflectionProvider->getClass($classNameCache);
} catch (ClassNotFoundException) {
} catch (ClassNotFoundException|ShouldNotHappenException) {
}
}
}
Expand Down
20 changes: 4 additions & 16 deletions src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
use Rector\PHPStan\NodeVisitor\ExprScopeFromStmtNodeVisitor;
use Rector\PHPStan\NodeVisitor\WrappedNodeRestoringNodeVisitor;
use Rector\Util\Reflection\PrivatesAccessor;
use Throwable;
use Webmozart\Assert\Assert;

/**
Expand All @@ -79,11 +78,6 @@ final class PHPStanNodeScopeResolver

private bool $hasUnreachableStatementNode = false;

/**
* @var string
*/
private const PHPSTAN_INTERNAL_ERROR_MESSAGE = 'Internal error.';

/**
* @param ScopeResolverNodeVisitorInterface[] $nodeVisitors
*/
Expand Down Expand Up @@ -234,10 +228,7 @@ private function nodeScopeResolverProcessNodes(
): void {
try {
$this->nodeScopeResolver->processNodes($stmts, $mutatingScope, $nodeCallback);
} catch (Throwable $throwable) {
if ($throwable->getMessage() !== self::PHPSTAN_INTERNAL_ERROR_MESSAGE) {
throw $throwable;
}
} catch (\PHPStan\ShouldNotHappenException) {
}
}

Expand Down Expand Up @@ -392,13 +383,10 @@ private function resolveClassOrInterfaceScope(

try {
return $mutatingScope->enterClass($classReflection);
} catch (Throwable $throwable) {
if ($throwable->getMessage() !== self::PHPSTAN_INTERNAL_ERROR_MESSAGE) {
throw $throwable;
}

return $mutatingScope;
} catch (\PHPStan\ShouldNotHappenException) {
}

return $mutatingScope;
}

private function resolveClassName(Class_ | Interface_ | Trait_| Enum_ $classLike): string
Expand Down

0 comments on commit db213ee

Please sign in to comment.