From 37ae358a8a71825252e2209d61a59596a3e2808d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 25 Oct 2022 16:11:54 +0200 Subject: [PATCH] cover ExtendedMethodReflection by bc-promise --- src/Reflection/Assertions.php | 3 +++ src/Reflection/ExtendedMethodReflection.php | 2 ++ src/Rules/Api/ApiClassImplementsRule.php | 9 +------- src/Rules/Api/ApiInterfaceExtendsRule.php | 6 +---- src/Rules/Api/BcUncoveredInterface.php | 22 +++++++++++++++++++ .../Rules/Api/ApiClassImplementsRuleTest.php | 15 ++++++++----- .../Rules/Api/ApiInterfaceExtendsRuleTest.php | 11 +++++++--- .../data/class-implements-out-of-phpstan.php | 7 ++++-- .../data/interface-extends-out-of-phpstan.php | 6 +++++ 9 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 src/Rules/Api/BcUncoveredInterface.php diff --git a/src/Reflection/Assertions.php b/src/Reflection/Assertions.php index 739d29939d..6adb97136c 100644 --- a/src/Reflection/Assertions.php +++ b/src/Reflection/Assertions.php @@ -10,6 +10,9 @@ use function array_merge; use function count; +/** + * @api + */ class Assertions { diff --git a/src/Reflection/ExtendedMethodReflection.php b/src/Reflection/ExtendedMethodReflection.php index e78785fabc..abf9c7b3e2 100644 --- a/src/Reflection/ExtendedMethodReflection.php +++ b/src/Reflection/ExtendedMethodReflection.php @@ -14,6 +14,8 @@ * and its methods in their code. * * Methods on ExtendedMethodReflection are subject to change. + * + * @api */ interface ExtendedMethodReflection extends MethodReflection { diff --git a/src/Rules/Api/ApiClassImplementsRule.php b/src/Rules/Api/ApiClassImplementsRule.php index e0eaef73f7..b160f92796 100644 --- a/src/Rules/Api/ApiClassImplementsRule.php +++ b/src/Rules/Api/ApiClassImplementsRule.php @@ -5,12 +5,10 @@ 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; use PHPStan\Rules\RuleErrorBuilder; -use PHPStan\Type\Type; use function array_merge; use function count; use function in_array; @@ -67,12 +65,7 @@ private function checkName(Scope $scope, Node\Name $name): array 'https://github.com/phpstan/phpstan/discussions', ))->build(); - if (in_array($implementedClassReflection->getName(), [ - Type::class, - ReflectionProvider::class, - Scope::class, - FunctionReflection::class, - ], true)) { + if (in_array($implementedClassReflection->getName(), BcUncoveredInterface::CLASSES, true)) { return [$ruleError]; } diff --git a/src/Rules/Api/ApiInterfaceExtendsRule.php b/src/Rules/Api/ApiInterfaceExtendsRule.php index d409b4ff72..e8074c3797 100644 --- a/src/Rules/Api/ApiInterfaceExtendsRule.php +++ b/src/Rules/Api/ApiInterfaceExtendsRule.php @@ -9,7 +9,6 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleError; use PHPStan\Rules\RuleErrorBuilder; -use PHPStan\Type\Type; use function array_merge; use function count; use function in_array; @@ -66,10 +65,7 @@ private function checkName(Scope $scope, Node\Name $name): array 'https://github.com/phpstan/phpstan/discussions', ))->build(); - if (in_array($extendedInterfaceReflection->getName(), [ - Type::class, - ReflectionProvider::class, - ], true)) { + if (in_array($extendedInterfaceReflection->getName(), BcUncoveredInterface::CLASSES, true)) { return [$ruleError]; } diff --git a/src/Rules/Api/BcUncoveredInterface.php b/src/Rules/Api/BcUncoveredInterface.php new file mode 100644 index 0000000000..137f9199c3 --- /dev/null +++ b/src/Rules/Api/BcUncoveredInterface.php @@ -0,0 +1,22 @@ +analyse([__DIR__ . '/data/class-implements-out-of-phpstan.php'], [ [ 'Implementing PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', - 18, + 19, $tip, ], [ 'Implementing PHPStan\Type\Type is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', - 52, + 53, $tip, ], [ 'Implementing PHPStan\Reflection\ReflectionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', - 327, + 328, $tip, ], [ 'Implementing PHPStan\Analyser\Scope is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', - 332, + 333, $tip, ], [ 'Implementing PHPStan\Reflection\FunctionReflection is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', - 337, + 338, + $tip, + ], + [ + 'Implementing PHPStan\Reflection\ExtendedMethodReflection is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', + 342, $tip, ], ]); diff --git a/tests/PHPStan/Rules/Api/ApiInterfaceExtendsRuleTest.php b/tests/PHPStan/Rules/Api/ApiInterfaceExtendsRuleTest.php index 2b14437482..770c59da3a 100644 --- a/tests/PHPStan/Rules/Api/ApiInterfaceExtendsRuleTest.php +++ b/tests/PHPStan/Rules/Api/ApiInterfaceExtendsRuleTest.php @@ -32,17 +32,22 @@ public function testRuleOutOfPhpStan(): void $this->analyse([__DIR__ . '/data/interface-extends-out-of-phpstan.php'], [ [ 'Extending PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', - 9, + 10, $tip, ], [ 'Extending PHPStan\Type\Type is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', - 19, + 20, $tip, ], [ 'Extending PHPStan\Reflection\ReflectionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', - 24, + 25, + $tip, + ], + [ + 'Extending PHPStan\Reflection\ExtendedMethodReflection is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.', + 30, $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 f152846171..20ab02c458 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 @@ -6,6 +6,7 @@ use PHPStan\Analyser\Scope; use PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider; use PHPStan\Reflection\ClassMemberAccessAnswerer; +use PHPStan\Reflection\ExtendedMethodReflection; use PHPStan\Reflection\FunctionReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\DynamicFunctionThrowTypeExtension; @@ -335,6 +336,8 @@ abstract class MyScope implements Scope } abstract class MyFunctionReflection implements FunctionReflection -{ +{} -} + +abstract class MyMethodReflection implements ExtendedMethodReflection +{} diff --git a/tests/PHPStan/Rules/Api/data/interface-extends-out-of-phpstan.php b/tests/PHPStan/Rules/Api/data/interface-extends-out-of-phpstan.php index fa995f5b09..c3d4b48e09 100644 --- a/tests/PHPStan/Rules/Api/data/interface-extends-out-of-phpstan.php +++ b/tests/PHPStan/Rules/Api/data/interface-extends-out-of-phpstan.php @@ -3,6 +3,7 @@ namespace App\InterfaceExtends; use PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider; +use PHPStan\Reflection\ExtendedMethodReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\DynamicFunctionThrowTypeExtension; @@ -25,3 +26,8 @@ interface Dolor extends ReflectionProvider { } + +interface Ipsum extends ExtendedMethodReflection +{ + +}