From 2796f8dd8fd5156abd8f19f4ecab2be14248782c Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 3 Oct 2022 14:03:43 +0200 Subject: [PATCH] There's no valid use-case to implement Scope or FunctionReflection --- src/Rules/Api/ApiClassImplementsRule.php | 3 +++ tests/PHPStan/Rules/Api/ApiClassImplementsRuleTest.php | 10 ++++++++++ .../Rules/Api/data/class-implements-out-of-phpstan.php | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/Rules/Api/ApiClassImplementsRule.php b/src/Rules/Api/ApiClassImplementsRule.php index 805d9fca1f..e0eaef73f7 100644 --- a/src/Rules/Api/ApiClassImplementsRule.php +++ b/src/Rules/Api/ApiClassImplementsRule.php @@ -5,6 +5,7 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use PHPStan\Analyser\Scope; +use PHPStan\Reflection\FunctionReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleError; @@ -69,6 +70,8 @@ private function checkName(Scope $scope, Node\Name $name): array if (in_array($implementedClassReflection->getName(), [ Type::class, ReflectionProvider::class, + Scope::class, + FunctionReflection::class, ], true)) { return [$ruleError]; } diff --git a/tests/PHPStan/Rules/Api/ApiClassImplementsRuleTest.php b/tests/PHPStan/Rules/Api/ApiClassImplementsRuleTest.php index 0468d7f2d0..34e92778cf 100644 --- a/tests/PHPStan/Rules/Api/ApiClassImplementsRuleTest.php +++ b/tests/PHPStan/Rules/Api/ApiClassImplementsRuleTest.php @@ -45,6 +45,16 @@ public function testRuleOutOfPhpStan(): void 322, $tip, ], + [ + 'Implementing PHPStan\Analyser\Scope is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', + 327, + $tip, + ], + [ + 'Implementing PHPStan\Reflection\FunctionReflection is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', + 332, + $tip, + ], ]); } diff --git a/tests/PHPStan/Rules/Api/data/class-implements-out-of-phpstan.php b/tests/PHPStan/Rules/Api/data/class-implements-out-of-phpstan.php index 835cab59d4..9a9cf6b2d8 100644 --- a/tests/PHPStan/Rules/Api/data/class-implements-out-of-phpstan.php +++ b/tests/PHPStan/Rules/Api/data/class-implements-out-of-phpstan.php @@ -323,3 +323,13 @@ abstract class Dolor implements ReflectionProvider { } + +abstract class MyScope implements Scope +{ + +} + +abstract class MyFunctionReflection implements FunctionReflection +{ + +}