From 67c466612a46318b390fb78c97f4befe135fafbc Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 1 Nov 2021 17:25:40 +0700 Subject: [PATCH] [Php70][Visibility] Avoid error Argument #1 ($scope) must be of type PHPStan\Analyser\Scope, null given --- .../StaticCall/StaticCallOnNonStaticToInstanceCallRector.php | 3 +++ .../Rector/ClassMethod/ChangeMethodVisibilityRector.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/rules/Php70/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php b/rules/Php70/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php index f0e9e45f2cb..92b07591223 100644 --- a/rules/Php70/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php +++ b/rules/Php70/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php @@ -158,6 +158,9 @@ private function shouldSkip(string $methodName, string $className, StaticCall $s } $scope = $staticCall->getAttribute(AttributeKey::SCOPE); + if (! $scope instanceof \PHPStan\Analyser\Scope) { + return true; + } $parentClassName = $this->parentClassScopeResolver->resolveParentClassName($scope); return $className === $parentClassName; diff --git a/rules/Visibility/Rector/ClassMethod/ChangeMethodVisibilityRector.php b/rules/Visibility/Rector/ClassMethod/ChangeMethodVisibilityRector.php index 6d22804a9ac..b4e7e8b7472 100644 --- a/rules/Visibility/Rector/ClassMethod/ChangeMethodVisibilityRector.php +++ b/rules/Visibility/Rector/ClassMethod/ChangeMethodVisibilityRector.php @@ -98,6 +98,9 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $scope = $node->getAttribute(AttributeKey::SCOPE); + if (! $scope instanceof \PHPStan\Analyser\Scope) { + return true; + } $parentClassName = $this->parentClassScopeResolver->resolveParentClassName($scope); if ($parentClassName === null) {