From e67abb509876c5e77e8d7570ffa71957b1014c43 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Wed, 2 Dec 2026 08:29:58 +0000 Subject: [PATCH] Test the data provider ignore extension with MissingImplementedMethodReturnTypehintRule too PHPStan reports missing return types of methods with a body in MissingImplementedMethodReturnTypehintRule since https://github.com/phpstan/phpstan-src/pull/7283. Amp-Thread-ID: https://ampcode.com/threads/T-01a22c96-9e21-771f-9a29-4627539ba301 --- ...ataProviderReturnTypeIgnoreExtensionTest.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/Type/PHPUnit/DataProviderReturnTypeIgnoreExtensionTest.php b/tests/Type/PHPUnit/DataProviderReturnTypeIgnoreExtensionTest.php index 5335fc0c..e2f7e1d4 100644 --- a/tests/Type/PHPUnit/DataProviderReturnTypeIgnoreExtensionTest.php +++ b/tests/Type/PHPUnit/DataProviderReturnTypeIgnoreExtensionTest.php @@ -2,21 +2,32 @@ namespace PHPStan\Type\PHPUnit; +use PHPStan\Rules\Methods\MissingImplementedMethodReturnTypehintRule; use PHPStan\Rules\Methods\MissingMethodReturnTypehintRule; use PHPStan\Rules\Rule; +use PHPStan\Testing\CompositeRule; use PHPStan\Testing\RuleTestCase; use function array_merge; +use function class_exists; /** - * @extends RuleTestCase + * @extends RuleTestCase */ class DataProviderReturnTypeIgnoreExtensionTest extends RuleTestCase { protected function getRule(): Rule { /** @phpstan-ignore phpstanApi.classConstant */ - $rule = self::getContainer()->getByType(MissingMethodReturnTypehintRule::class); + $rules = [self::getContainer()->getByType(MissingMethodReturnTypehintRule::class)]; - return $rule; + // newer PHPStan versions report missing return types of methods with a body in a separate rule + // @phpstan-ignore phpstanApi.classConstant + if (class_exists(MissingImplementedMethodReturnTypehintRule::class)) { + /** @phpstan-ignore phpstanApi.classConstant */ + $rules[] = self::getContainer()->getByType(MissingImplementedMethodReturnTypehintRule::class); + } + + // @phpstan-ignore argument.type + return new CompositeRule($rules); } public function testRule(): void