Skip to content

Commit 51d21a8

Browse files
cs278ondrejmirtes
authored andcommitted
Only treat constants as deprecated on PHP≥7.3
1 parent a122cf1 commit 51d21a8

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

src/Rules/Deprecations/FetchingDeprecatedConstRule.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ class FetchingDeprecatedConstRule implements \PHPStan\Rules\Rule
1717
private $reflectionProvider;
1818

1919
/** @var array<string,string> */
20-
private $deprecatedConstants = [
21-
'FILTER_FLAG_SCHEME_REQUIRED' => 'Use of constant %s is deprecated since PHP 7.3.',
22-
'FILTER_FLAG_HOST_REQUIRED' => 'Use of constant %s is deprecated since PHP 7.3.',
23-
];
20+
private $deprecatedConstants = [];
2421

2522
public function __construct(ReflectionProvider $reflectionProvider)
2623
{
2724
$this->reflectionProvider = $reflectionProvider;
25+
26+
// phpcs:ignore SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed
27+
if (PHP_VERSION_ID >= 70300) {
28+
$this->deprecatedConstants['FILTER_FLAG_SCHEME_REQUIRED'] = 'Use of constant %s is deprecated since PHP 7.3.';
29+
$this->deprecatedConstants['FILTER_FLAG_HOST_REQUIRED'] = 'Use of constant %s is deprecated since PHP 7.3.';
30+
}
2831
}
2932

3033
public function getNodeType(): string

tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php

+30-26
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,39 @@ public function testFetchingDeprecatedConst(): void
1919
$this->markTestSkipped('Required constants are not available, PHP≥8?');
2020
}
2121

22+
$expectedErrors = [];
23+
24+
if (PHP_VERSION_ID >= 70300) {
25+
$expectedErrors[] = [
26+
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
27+
5,
28+
];
29+
$expectedErrors[] = [
30+
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
31+
6,
32+
];
33+
$expectedErrors[] = [
34+
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
35+
7,
36+
];
37+
$expectedErrors[] = [
38+
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
39+
8,
40+
];
41+
$expectedErrors[] = [
42+
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
43+
37,
44+
];
45+
$expectedErrors[] = [
46+
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
47+
38,
48+
];
49+
}
50+
2251
require_once __DIR__ . '/data/fetching-deprecated-const-definition.php';
2352
$this->analyse(
2453
[__DIR__ . '/data/fetching-deprecated-const.php'],
25-
[
26-
[
27-
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
28-
5,
29-
],
30-
[
31-
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
32-
6,
33-
],
34-
[
35-
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
36-
7,
37-
],
38-
[
39-
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
40-
8,
41-
],
42-
[
43-
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
44-
37,
45-
],
46-
[
47-
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
48-
38,
49-
],
50-
]
54+
$expectedErrors
5155
);
5256
}
5357

0 commit comments

Comments
 (0)