Skip to content

Commit 709f1d0

Browse files
authored
Constants deprecation depends on PHP version in comment
1 parent 67f9420 commit 709f1d0

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/Reflection/BetterReflection/BetterReflectionProvider.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,17 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
373373
if ($resolvedPhpDoc->isDeprecated() && $resolvedPhpDoc->getDeprecatedTag() !== null) {
374374
$deprecatedMessage = $resolvedPhpDoc->getDeprecatedTag()->getMessage();
375375

376-
// filter raw version number messages like in
377-
// https://github.com/JetBrains/phpstorm-stubs/blob/9608c953230b08f07b703ecfe459cc58d5421437/filter/filter.php#L478
378-
if (Strings::match($deprecatedMessage ?? '', '#^\d+\.\d+(\.\d+)?$#') === null) {
376+
$matches = Strings::match($deprecatedMessage ?? '', '#^(\d+)\.(\d+)(?:\.(\d+))?$#');
377+
if ($matches !== null) {
378+
$major = $matches[1];
379+
$minor = $matches[2];
380+
$patch = $matches[3] ?? 0;
381+
$versionId = sprintf('%d%02d%02d', $major, $minor, $patch);
382+
383+
$isDeprecated = TrinaryLogic::createFromBoolean($this->phpVersion->getVersionId() >= $versionId);
384+
} else {
385+
// filter raw version number messages like in
386+
// https://github.com/JetBrains/phpstorm-stubs/blob/9608c953230b08f07b703ecfe459cc58d5421437/filter/filter.php#L478
379387
$deprecatedDescription = $deprecatedMessage;
380388
}
381389
}

tests/PHPStan/Reflection/Constant/RuntimeConstantReflectionTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ class RuntimeConstantReflectionTest extends PHPStanTestCase
1212

1313
public function dataDeprecatedConstants(): iterable
1414
{
15-
if (PHP_VERSION_ID >= 80100) {
16-
yield [
17-
new Name('\FILTER_SANITIZE_STRING'),
18-
TrinaryLogic::createYes(),
19-
null,
20-
];
21-
}
15+
yield [
16+
new Name('\FILTER_SANITIZE_STRING'),
17+
PHP_VERSION_ID >= 80100 ? TrinaryLogic::createYes() : TrinaryLogic::createNo(),
18+
null,
19+
];
20+
2221
yield [
2322
new Name('\CURLOPT_FTP_SSL'),
2423
TrinaryLogic::createYes(),

0 commit comments

Comments
 (0)