Skip to content

Commit ba0e3be

Browse files
committed
NamedArgumentsRule - report only on PHP 8.0+
1 parent 42e9c24 commit ba0e3be

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

build/PHPStan/Build/NamedArgumentsRule.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node;
66
use PHPStan\Analyser\ArgumentsNormalizer;
77
use PHPStan\Analyser\Scope;
8+
use PHPStan\Php\PhpVersion;
89
use PHPStan\Reflection\ExtendedParametersAcceptor;
910
use PHPStan\Reflection\ReflectionProvider;
1011
use PHPStan\Rules\IdentifierRuleError;
@@ -22,7 +23,10 @@
2223
final class NamedArgumentsRule implements Rule
2324
{
2425

25-
public function __construct(private ReflectionProvider $reflectionProvider)
26+
public function __construct(
27+
private ReflectionProvider $reflectionProvider,
28+
private PhpVersion $phpVersion,
29+
)
2630
{
2731
}
2832

@@ -33,6 +37,10 @@ public function getNodeType(): string
3337

3438
public function processNode(Node $node, Scope $scope): array
3539
{
40+
if (!$this->phpVersion->supportsNamedArguments()) {
41+
return [];
42+
}
43+
3644
if ($node->isFirstClassCallable()) {
3745
return [];
3846
}

tests/PHPStan/Build/NamedArgumentsRuleTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\Build;
44

5+
use PHPStan\Php\PhpVersion;
56
use PHPStan\Rules\Rule;
67
use PHPStan\Testing\RuleTestCase;
78
use const PHP_VERSION_ID;
@@ -14,7 +15,7 @@ class NamedArgumentsRuleTest extends RuleTestCase
1415

1516
protected function getRule(): Rule
1617
{
17-
return new NamedArgumentsRule($this->createReflectionProvider());
18+
return new NamedArgumentsRule($this->createReflectionProvider(), new PhpVersion(PHP_VERSION_ID));
1819
}
1920

2021
public function testRule(): void
@@ -41,6 +42,10 @@ public function testRule(): void
4142

4243
public function testNoFix(): void
4344
{
45+
if (PHP_VERSION_ID < 80000) {
46+
$this->markTestSkipped('Test requires PHP 8.0.');
47+
}
48+
4449
$this->fix(
4550
__DIR__ . '/data/named-arguments-no-errors.php',
4651
__DIR__ . '/data/named-arguments-no-errors.php',
@@ -49,6 +54,10 @@ public function testNoFix(): void
4954

5055
public function testFix(): void
5156
{
57+
if (PHP_VERSION_ID < 80000) {
58+
$this->markTestSkipped('Test requires PHP 8.0.');
59+
}
60+
5261
$this->fix(
5362
__DIR__ . '/data/named-arguments.php',
5463
__DIR__ . '/data/named-arguments.php.fixed',

0 commit comments

Comments
 (0)