From 48eb91bb8a6a1fb5cae8242ab52558f1f46b7763 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 26 Aug 2025 08:59:17 +0200 Subject: [PATCH 1/2] fix build --- .../CallToMethodStatementWithoutSideEffectsRuleTest.php | 4 ---- .../CallToStaticMethodStatementWithoutSideEffectsRuleTest.php | 4 ---- 2 files changed, 8 deletions(-) diff --git a/tests/PHPStan/Rules/Methods/CallToMethodStatementWithoutSideEffectsRuleTest.php b/tests/PHPStan/Rules/Methods/CallToMethodStatementWithoutSideEffectsRuleTest.php index a160bfcea7..4275f0c4f1 100644 --- a/tests/PHPStan/Rules/Methods/CallToMethodStatementWithoutSideEffectsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallToMethodStatementWithoutSideEffectsRuleTest.php @@ -26,10 +26,6 @@ public function testRule(): void 'Call to method DateTimeImmutable::modify() on a separate line has no effect.', 15, ], - [ - 'Call to static method DateTimeImmutable::createFromFormat() on a separate line has no effect.', - 16, - ], [ 'Call to method Exception::getCode() on a separate line has no effect.', 21, diff --git a/tests/PHPStan/Rules/Methods/CallToStaticMethodStatementWithoutSideEffectsRuleTest.php b/tests/PHPStan/Rules/Methods/CallToStaticMethodStatementWithoutSideEffectsRuleTest.php index bec56ff7d6..f8e37e9cc8 100644 --- a/tests/PHPStan/Rules/Methods/CallToStaticMethodStatementWithoutSideEffectsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallToStaticMethodStatementWithoutSideEffectsRuleTest.php @@ -24,10 +24,6 @@ protected function getRule(): Rule public function testRule(): void { $this->analyse([__DIR__ . '/data/static-method-call-statement-no-side-effects.php'], [ - [ - 'Call to static method DateTimeImmutable::createFromFormat() on a separate line has no effect.', - 12, - ], [ 'Call to method DateTime::format() on a separate line has no effect.', 23, From 3e856e39421dea0826f388c4583b3860a7e6053f Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 26 Aug 2025 09:19:42 +0200 Subject: [PATCH 2/2] fix --- ...hodStatementWithoutSideEffectsRuleTest.php | 29 +++++++++++++++++++ ...hodStatementWithoutSideEffectsRuleTest.php | 17 +++++++++++ 2 files changed, 46 insertions(+) diff --git a/tests/PHPStan/Rules/Methods/CallToMethodStatementWithoutSideEffectsRuleTest.php b/tests/PHPStan/Rules/Methods/CallToMethodStatementWithoutSideEffectsRuleTest.php index 4275f0c4f1..3959c73891 100644 --- a/tests/PHPStan/Rules/Methods/CallToMethodStatementWithoutSideEffectsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallToMethodStatementWithoutSideEffectsRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_merge; use const PHP_VERSION_ID; @@ -19,6 +20,7 @@ protected function getRule(): Rule return new CallToMethodStatementWithoutSideEffectsRule(new RuleLevelHelper(self::createReflectionProvider(), true, false, true, false, false, false, true)); } + #[RequiresPhp('>= 8.0')] public function testRule(): void { $this->analyse([__DIR__ . '/data/method-call-statement-no-side-effects.php'], [ @@ -41,6 +43,33 @@ public function testRule(): void ]); } + #[RequiresPhp('< 8')] + public function testRulePhp7(): void + { + $this->analyse([__DIR__ . '/data/method-call-statement-no-side-effects.php'], [ + [ + 'Call to method DateTimeImmutable::modify() on a separate line has no effect.', + 15, + ], + [ + 'Call to static method DateTimeImmutable::createFromFormat() on a separate line has no effect.', + 16, + ], + [ + 'Call to method Exception::getCode() on a separate line has no effect.', + 21, + ], + [ + 'Call to method MethodCallStatementNoSideEffects\Bar::doPure() on a separate line has no effect.', + 63, + ], + [ + 'Call to method MethodCallStatementNoSideEffects\Bar::doPureWithThrowsVoid() on a separate line has no effect.', + 64, + ], + ]); + } + public function testNullsafe(): void { $this->analyse([__DIR__ . '/data/nullsafe-method-call-statement-no-side-effects.php'], [ diff --git a/tests/PHPStan/Rules/Methods/CallToStaticMethodStatementWithoutSideEffectsRuleTest.php b/tests/PHPStan/Rules/Methods/CallToStaticMethodStatementWithoutSideEffectsRuleTest.php index f8e37e9cc8..4c7b064056 100644 --- a/tests/PHPStan/Rules/Methods/CallToStaticMethodStatementWithoutSideEffectsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallToStaticMethodStatementWithoutSideEffectsRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -21,6 +22,7 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.0')] public function testRule(): void { $this->analyse([__DIR__ . '/data/static-method-call-statement-no-side-effects.php'], [ @@ -31,6 +33,21 @@ public function testRule(): void ]); } + #[RequiresPhp('< 8')] + public function testRulePhp7(): void + { + $this->analyse([__DIR__ . '/data/static-method-call-statement-no-side-effects.php'], [ + [ + 'Call to static method DateTimeImmutable::createFromFormat() on a separate line has no effect.', + 12, + ], + [ + 'Call to method DateTime::format() on a separate line has no effect.', + 23, + ], + ]); + } + public function testPhpDoc(): void { $this->analyse([__DIR__ . '/data/static-method-call-statement-no-side-effects-phpdoc.php'], [