Skip to content

Commit a048c66

Browse files
committed
Constants isDeprecation() depends on Scope->getPhpVersion()
1 parent d08d0c2 commit a048c66

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/Reflection/BetterReflection/BetterReflectionProvider.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
use PHPStan\TrinaryLogic;
5454
use PHPStan\Type\FileTypeMapper;
5555
use PHPStan\Type\Generic\TemplateTypeMap;
56+
use PHPStan\Type\IntegerRangeType;
5657
use PHPStan\Type\Type;
58+
use PHPStan\Type\VerbosityLevel;
5759
use function array_key_exists;
5860
use function array_key_first;
5961
use function array_map;
@@ -372,8 +374,15 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
372374
throw new ConstantNotFoundException((string) $nameNode);
373375
}
374376

375-
if (array_key_exists($constantName, $this->cachedConstants)) {
376-
return $this->cachedConstants[$constantName];
377+
$phpVersionType = null;
378+
$cacheKey = $constantName;
379+
if ($namespaceAnswerer instanceof Scope) {
380+
$phpVersionType = $namespaceAnswerer->getPhpVersion()->getType();
381+
$cacheKey = $constantName . '-' . $phpVersionType->describe(VerbosityLevel::cache());
382+
}
383+
384+
if (array_key_exists($cacheKey, $this->cachedConstants)) {
385+
return $this->cachedConstants[$cacheKey];
377386
}
378387

379388
$constantReflection = $this->reflector->reflectConstant($constantName);
@@ -399,7 +408,11 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
399408
$patch = $matches[3] ?? 0;
400409
$versionId = sprintf('%d%02d%02d', $major, $minor, $patch);
401410

402-
$isDeprecated = $this->phpVersion->getVersionId() >= $versionId;
411+
if ($phpVersionType !== null) {
412+
$isDeprecated = IntegerRangeType::fromInterval((int) $versionId, null)->isSuperTypeOf($phpVersionType)->yes();
413+
} else {
414+
$isDeprecated = $this->phpVersion->getVersionId() >= $versionId;
415+
}
403416
} else {
404417
// filter raw version number messages like in
405418
// https://github.com/JetBrains/phpstorm-stubs/blob/9608c953230b08f07b703ecfe459cc58d5421437/filter/filter.php#L478
@@ -412,7 +425,7 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
412425
$isDeprecated = $constantReflection->isDeprecated();
413426
}
414427

415-
return $this->cachedConstants[$constantName] = new RuntimeConstantReflection(
428+
return $this->cachedConstants[$cacheKey] = new RuntimeConstantReflection(
416429
$constantName,
417430
$constantValueType,
418431
$fileName,

0 commit comments

Comments
 (0)