Skip to content

Commit

Permalink
Only treat constants as deprecated on PHP≥7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
cs278 authored and ondrejmirtes committed Jan 12, 2020
1 parent a122cf1 commit 51d21a8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
11 changes: 7 additions & 4 deletions src/Rules/Deprecations/FetchingDeprecatedConstRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ class FetchingDeprecatedConstRule implements \PHPStan\Rules\Rule
private $reflectionProvider;

/** @var array<string,string> */
private $deprecatedConstants = [
'FILTER_FLAG_SCHEME_REQUIRED' => 'Use of constant %s is deprecated since PHP 7.3.',
'FILTER_FLAG_HOST_REQUIRED' => 'Use of constant %s is deprecated since PHP 7.3.',
];
private $deprecatedConstants = [];

public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;

// phpcs:ignore SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed
if (PHP_VERSION_ID >= 70300) {
$this->deprecatedConstants['FILTER_FLAG_SCHEME_REQUIRED'] = 'Use of constant %s is deprecated since PHP 7.3.';
$this->deprecatedConstants['FILTER_FLAG_HOST_REQUIRED'] = 'Use of constant %s is deprecated since PHP 7.3.';
}
}

public function getNodeType(): string
Expand Down
56 changes: 30 additions & 26 deletions tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,39 @@ public function testFetchingDeprecatedConst(): void
$this->markTestSkipped('Required constants are not available, PHP≥8?');
}

$expectedErrors = [];

if (PHP_VERSION_ID >= 70300) {
$expectedErrors[] = [
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
5,
];
$expectedErrors[] = [
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
6,
];
$expectedErrors[] = [
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
7,
];
$expectedErrors[] = [
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
8,
];
$expectedErrors[] = [
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
37,
];
$expectedErrors[] = [
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
38,
];
}

require_once __DIR__ . '/data/fetching-deprecated-const-definition.php';
$this->analyse(
[__DIR__ . '/data/fetching-deprecated-const.php'],
[
[
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
5,
],
[
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
6,
],
[
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
7,
],
[
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
8,
],
[
'Use of constant FILTER_FLAG_SCHEME_REQUIRED is deprecated since PHP 7.3.',
37,
],
[
'Use of constant FILTER_FLAG_HOST_REQUIRED is deprecated since PHP 7.3.',
38,
],
]
$expectedErrors
);
}

Expand Down

0 comments on commit 51d21a8

Please sign in to comment.