Skip to content

Commit 76f47dd

Browse files
claudepacheondrejmirtes
authored andcommitted
Remove the PHP version constraint from the #[\NoDiscard] attribute rules.
1 parent c7301f6 commit 76f47dd

7 files changed

Lines changed: 2 additions & 34 deletions

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ Recent work on PHP 8.5 support shows the pattern:
282282
- **Parser support**: Update nikic/php-parser dependency, handle new AST node types
283283
- **NodeScopeResolver**: Handle new syntax (pipe operator, clone-with, void cast)
284284
- **Type system**: New type representations if needed
285-
- **Rules**: Version-gated rules (e.g. deprecated casts only reported on PHP 8.5+, `#[NoDiscard]` only on PHP 8.5+)
285+
- **Rules**: Version-gated rules (e.g. deprecated casts only reported on PHP 8.5+)
286286
- **InitializerExprTypeResolver**: Support new constant expression forms (casts, first-class callables, static closures in initializers)
287287
- **Reflection**: Support new attributes, property features (asymmetric visibility on static properties, `#[Override]` on properties)
288288
- **PhpVersion**: Add detection methods like `supportsPropertyHooks()`, `supportsPipeOperator()`, etc.

‎src/Rules/Functions/CallToFunctionStatementWithNoDiscardRule.php‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\DependencyInjection\RegisteredRule;
8-
use PHPStan\Php\PhpVersion;
98
use PHPStan\Reflection\ReflectionProvider;
109
use PHPStan\Rules\Rule;
1110
use PHPStan\Rules\RuleErrorBuilder;
@@ -22,7 +21,6 @@ final class CallToFunctionStatementWithNoDiscardRule implements Rule
2221

2322
public function __construct(
2423
private ReflectionProvider $reflectionProvider,
25-
private PhpVersion $phpVersion,
2624
)
2725
{
2826
}
@@ -61,10 +59,6 @@ public function processNode(Node $node, Scope $scope): array
6159
return [];
6260
}
6361

64-
if (!$this->phpVersion->supportsNoDiscardAttribute()) {
65-
return [];
66-
}
67-
6862
if ($funcCall->name instanceof Node\Name) {
6963
if (!$this->reflectionProvider->hasFunction($funcCall->name, $scope)) {
7064
return [];

‎src/Rules/Methods/CallToMethodStatementWithNoDiscardRule.php‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPStan\Analyser\NullsafeOperatorHelper;
77
use PHPStan\Analyser\Scope;
88
use PHPStan\DependencyInjection\RegisteredRule;
9-
use PHPStan\Php\PhpVersion;
109
use PHPStan\Rules\Rule;
1110
use PHPStan\Rules\RuleErrorBuilder;
1211
use PHPStan\Rules\RuleLevelHelper;
@@ -23,7 +22,6 @@ final class CallToMethodStatementWithNoDiscardRule implements Rule
2322

2423
public function __construct(
2524
private RuleLevelHelper $ruleLevelHelper,
26-
private PhpVersion $phpVersion,
2725
)
2826
{
2927
}
@@ -67,10 +65,6 @@ public function processNode(Node $node, Scope $scope): array
6765
return [];
6866
}
6967

70-
if (!$this->phpVersion->supportsNoDiscardAttribute()) {
71-
return [];
72-
}
73-
7468
$methodName = $methodCall->name->toString();
7569
$typeResult = $this->ruleLevelHelper->findTypeToCheck(
7670
$scope,

‎src/Rules/Methods/CallToStaticMethodStatementWithNoDiscardRule.php‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPStan\Analyser\NullsafeOperatorHelper;
77
use PHPStan\Analyser\Scope;
88
use PHPStan\DependencyInjection\RegisteredRule;
9-
use PHPStan\Php\PhpVersion;
109
use PHPStan\Reflection\ReflectionProvider;
1110
use PHPStan\Rules\Rule;
1211
use PHPStan\Rules\RuleErrorBuilder;
@@ -26,7 +25,6 @@ final class CallToStaticMethodStatementWithNoDiscardRule implements Rule
2625
public function __construct(
2726
private RuleLevelHelper $ruleLevelHelper,
2827
private ReflectionProvider $reflectionProvider,
29-
private PhpVersion $phpVersion,
3028
)
3129
{
3230
}
@@ -68,10 +66,6 @@ public function processNode(Node $node, Scope $scope): array
6866
return [];
6967
}
7068

71-
if (!$this->phpVersion->supportsNoDiscardAttribute()) {
72-
return [];
73-
}
74-
7569
$methodName = $methodCall->name->toString();
7670
if ($methodCall->class instanceof Node\Name) {
7771
$className = $scope->resolveName($methodCall->class);

‎tests/PHPStan/Rules/Functions/CallToFunctionStatementWithNoDiscardRuleTest.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
namespace PHPStan\Rules\Functions;
44

5-
use PHPStan\Php\PhpVersion;
65
use PHPStan\Rules\Rule;
76
use PHPStan\Testing\RuleTestCase;
8-
use PHPUnit\Framework\Attributes\RequiresPhp;
9-
use const PHP_VERSION_ID;
107

118
/**
129
* @extends RuleTestCase<CallToFunctionStatementWithNoDiscardRule>
@@ -16,10 +13,9 @@ class CallToFunctionStatementWithNoDiscardRuleTest extends RuleTestCase
1613

1714
protected function getRule(): Rule
1815
{
19-
return new CallToFunctionStatementWithNoDiscardRule(self::createReflectionProvider(), new PhpVersion(PHP_VERSION_ID));
16+
return new CallToFunctionStatementWithNoDiscardRule(self::createReflectionProvider());
2017
}
2118

22-
#[RequiresPhp('>= 8.5.0')]
2319
public function testRule(): void
2420
{
2521
$this->analyse([__DIR__ . '/data/function-call-statement-result-discarded.php'], [

‎tests/PHPStan/Rules/Methods/CallToMethodStatementWithNoDiscardRuleTest.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
namespace PHPStan\Rules\Methods;
44

5-
use PHPStan\Php\PhpVersion;
65
use PHPStan\Rules\Rule;
76
use PHPStan\Rules\RuleLevelHelper;
87
use PHPStan\Testing\RuleTestCase;
9-
use PHPUnit\Framework\Attributes\RequiresPhp;
10-
use const PHP_VERSION_ID;
118

129
/**
1310
* @extends RuleTestCase<CallToMethodStatementWithNoDiscardRule>
@@ -28,11 +25,9 @@ protected function getRule(): Rule
2825
checkBenevolentUnionTypes: false,
2926
discoveringSymbolsTip: true,
3027
),
31-
new PhpVersion(PHP_VERSION_ID),
3228
);
3329
}
3430

35-
#[RequiresPhp('>= 8.5.0')]
3631
public function testRule(): void
3732
{
3833
$this->analyse([__DIR__ . '/data/method-call-statement-result-discarded.php'], [

‎tests/PHPStan/Rules/Methods/CallToStaticMethodStatementWithNoDiscardRuleTest.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
namespace PHPStan\Rules\Methods;
44

5-
use PHPStan\Php\PhpVersion;
65
use PHPStan\Rules\Rule;
76
use PHPStan\Rules\RuleLevelHelper;
87
use PHPStan\Testing\RuleTestCase;
9-
use PHPUnit\Framework\Attributes\RequiresPhp;
10-
use const PHP_VERSION_ID;
118

129
/**
1310
* @extends RuleTestCase<CallToStaticMethodStatementWithNoDiscardRule>
@@ -30,11 +27,9 @@ protected function getRule(): Rule
3027
discoveringSymbolsTip: true,
3128
),
3229
$reflectionProvider,
33-
new PhpVersion(PHP_VERSION_ID),
3430
);
3531
}
3632

37-
#[RequiresPhp('>= 8.5.0')]
3833
public function testRule(): void
3934
{
4035
$this->analyse([__DIR__ . '/data/static-method-call-statement-result-discarded.php'], [

0 commit comments

Comments
 (0)