From 6372b90b19d034087c2a58486cd94ecf8cb2993b Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 16 May 2024 12:51:40 +0000 Subject: [PATCH] Updated Rector to commit db213ee986c942d58e397b3713564349541e8de5 https://github.com/rectorphp/rector-src/commit/db213ee986c942d58e397b3713564349541e8de5 [PHPStan] Handle PHPStan internal ShouldNotHappenException on FamilyRelationsAnalyzer and PHPStanNodeScopeResolver (#5885) --- src/Application/VersionResolver.php | 4 ++-- .../Reflection/FamilyRelationsAnalyzer.php | 3 ++- .../PHPStan/Scope/PHPStanNodeScopeResolver.php | 17 +++-------------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 37f3fcc8200..ca4a6cfdd6c 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '6a5f6c53f3637b23b4488cab81ec90a0d1bef053'; + public const PACKAGE_VERSION = 'db213ee986c942d58e397b3713564349541e8de5'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-05-16 18:42:05'; + public const RELEASE_DATE = '2024-05-16 19:48:22'; /** * @var int */ diff --git a/src/FamilyTree/Reflection/FamilyRelationsAnalyzer.php b/src/FamilyTree/Reflection/FamilyRelationsAnalyzer.php index 0d837adafe8..61b543d829f 100644 --- a/src/FamilyTree/Reflection/FamilyRelationsAnalyzer.php +++ b/src/FamilyTree/Reflection/FamilyRelationsAnalyzer.php @@ -9,6 +9,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; @@ -123,7 +124,7 @@ private function loadClasses() : void foreach ($classNamesCache as $classNameCache) { try { $this->reflectionProvider->getClass($classNameCache); - } catch (ClassNotFoundException $exception) { + } catch (ClassNotFoundException|ShouldNotHappenException $exception) { } } } diff --git a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php index 696bac3a4fe..a5e84742eb9 100644 --- a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php +++ b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php @@ -60,7 +60,6 @@ use Rector\PHPStan\NodeVisitor\ExprScopeFromStmtNodeVisitor; use Rector\PHPStan\NodeVisitor\WrappedNodeRestoringNodeVisitor; use Rector\Util\Reflection\PrivatesAccessor; -use Throwable; use RectorPrefix202405\Webmozart\Assert\Assert; /** * @inspired by https://github.com/silverstripe/silverstripe-upgrader/blob/532182b23e854d02e0b27e68ebc394f436de0682/src/UpgradeRule/PHP/Visitor/PHPStanScopeVisitor.php @@ -111,10 +110,6 @@ final class PHPStanNodeScopeResolver * @var bool */ private $hasUnreachableStatementNode = \false; - /** - * @var string - */ - private const PHPSTAN_INTERNAL_ERROR_MESSAGE = 'Internal error.'; /** * @param ScopeResolverNodeVisitorInterface[] $nodeVisitors */ @@ -236,10 +231,7 @@ private function nodeScopeResolverProcessNodes(array $stmts, MutatingScope $muta { try { $this->nodeScopeResolver->processNodes($stmts, $mutatingScope, $nodeCallback); - } catch (Throwable $throwable) { - if ($throwable->getMessage() !== self::PHPSTAN_INTERNAL_ERROR_MESSAGE) { - throw $throwable; - } + } catch (\PHPStan\ShouldNotHappenException $exception) { } } private function processCallike(CallLike $callLike, MutatingScope $mutatingScope) : void @@ -368,12 +360,9 @@ private function resolveClassOrInterfaceScope($classLike, MutatingScope $mutatin $this->privatesAccessor->setPrivateProperty($context, 'classReflection', null); try { return $mutatingScope->enterClass($classReflection); - } catch (Throwable $throwable) { - if ($throwable->getMessage() !== self::PHPSTAN_INTERNAL_ERROR_MESSAGE) { - throw $throwable; - } - return $mutatingScope; + } catch (\PHPStan\ShouldNotHappenException $exception) { } + return $mutatingScope; } /** * @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Interface_|\PhpParser\Node\Stmt\Trait_|\PhpParser\Node\Stmt\Enum_ $classLike