Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.1.x' into 1.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 13, 2024
2 parents e9ea332 + d457b73 commit 8342041
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
19 changes: 0 additions & 19 deletions src/Rules/Deprecations/FetchingDeprecatedConstRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use function sprintf;
use const PHP_VERSION_ID;

/**
* @implements Rule<ConstFetch>
Expand All @@ -23,19 +22,10 @@ class FetchingDeprecatedConstRule implements Rule
/** @var DeprecatedScopeHelper */
private $deprecatedScopeHelper;

/** @var array<string,string> */
private $deprecatedConstants = [];

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

// 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 Expand Up @@ -64,15 +54,6 @@ public function processNode(Node $node, Scope $scope): array
];
}

if (isset($this->deprecatedConstants[$constantReflection->getName()])) {
return [
RuleErrorBuilder::message(sprintf(
$this->deprecatedConstants[$constantReflection->getName()],
$constantReflection->getName()
))->identifier('constant.deprecated')->build(),
];
}

return [];
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ public function testFetchingDeprecatedConst(): void

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

0 comments on commit 8342041

Please sign in to comment.