Skip to content

Commit a122cf1

Browse files
cs278ondrejmirtes
authored andcommitted
Separate reflection provided deprecations
1 parent 4d18903 commit a122cf1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/Rules/Deprecations/FetchingDeprecatedConstRule.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PhpParser\Node;
66
use PhpParser\Node\Expr\ConstFetch;
77
use PHPStan\Analyser\Scope;
8-
use PHPStan\Reflection\GlobalConstantReflection;
98
use PHPStan\Reflection\ReflectionProvider;
109

1110
/**
@@ -44,21 +43,23 @@ public function processNode(Node $node, Scope $scope): array
4443
}
4544

4645
$constantReflection = $this->reflectionProvider->getConstant($node->name, $scope);
46+
$defaultMessage = 'Use of constant %s is deprecated.';
4747

48-
if ($this->isDeprecated($constantReflection)) {
48+
if ($constantReflection->isDeprecated()->yes()) {
4949
return [sprintf(
50-
$this->deprecatedConstants[$constantReflection->getName()] ?? 'Use of constant %s is deprecated.',
50+
$constantReflection->getDeprecatedDescription() ?? $defaultMessage,
5151
$constantReflection->getName()
5252
)];
5353
}
5454

55-
return [];
56-
}
55+
if (isset($this->deprecatedConstants[$constantReflection->getName()])) {
56+
return [sprintf(
57+
$this->deprecatedConstants[$constantReflection->getName()] ?? $defaultMessage,
58+
$constantReflection->getName()
59+
)];
60+
}
5761

58-
private function isDeprecated(GlobalConstantReflection $constantReflection): bool
59-
{
60-
return $constantReflection->isDeprecated()->yes()
61-
|| isset($this->deprecatedConstants[$constantReflection->getName()]);
62+
return [];
6263
}
6364

6465
}

0 commit comments

Comments
 (0)