Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/Reflection/BetterReflection/BetterReflectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
use PHPStan\TrinaryLogic;
use PHPStan\Type\FileTypeMapper;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\IntegerRangeType;
use PHPStan\Type\Type;
use PHPStan\Type\VerbosityLevel;
use function array_key_exists;
use function array_key_first;
use function array_map;
Expand All @@ -76,7 +78,7 @@
/** @var ClassReflection[] */
private static array $anonymousClasses = [];

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

/**
Expand Down Expand Up @@ -372,8 +374,19 @@
throw new ConstantNotFoundException((string) $nameNode);
}

if (array_key_exists($constantName, $this->cachedConstants)) {
return $this->cachedConstants[$constantName];
$phpVersionType = null;
$versionKey = 'current_version';
if ($namespaceAnswerer instanceof Scope) {
$phpVersionType = $namespaceAnswerer->getPhpVersion()->getType();
$versionKey = $phpVersionType->describe(VerbosityLevel::cache());
}

if (!array_key_exists($versionKey, $this->cachedConstants)) {
$this->cachedConstants[$versionKey] = [];
}

if (array_key_exists($constantName, $this->cachedConstants[$versionKey])) {
return $this->cachedConstants[$versionKey][$constantName];
}

$constantReflection = $this->reflector->reflectConstant($constantName);
Expand All @@ -399,20 +412,24 @@
$patch = $matches[3] ?? 0;
$versionId = sprintf('%d%02d%02d', $major, $minor, $patch);

$isDeprecated = $this->phpVersion->getVersionId() >= $versionId;
if ($phpVersionType !== null) {
$isDeprecated = IntegerRangeType::fromInterval((int) $versionId, null)->isSuperTypeOf($phpVersionType)->yes();

Check warning on line 416 in src/Reflection/BetterReflection/BetterReflectionProvider.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $patch = $matches[3] ?? 0; $versionId = sprintf('%d%02d%02d', $major, $minor, $patch); if ($phpVersionType !== null) { - $isDeprecated = IntegerRangeType::fromInterval((int) $versionId, null)->isSuperTypeOf($phpVersionType)->yes(); + $isDeprecated = !IntegerRangeType::fromInterval((int) $versionId, null)->isSuperTypeOf($phpVersionType)->no(); } else { $isDeprecated = $this->phpVersion->getVersionId() >= $versionId; }

Check warning on line 416 in src/Reflection/BetterReflection/BetterReflectionProvider.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ $patch = $matches[3] ?? 0; $versionId = sprintf('%d%02d%02d', $major, $minor, $patch); if ($phpVersionType !== null) { - $isDeprecated = IntegerRangeType::fromInterval((int) $versionId, null)->isSuperTypeOf($phpVersionType)->yes(); + $isDeprecated = $phpVersionType->isSuperTypeOf(IntegerRangeType::fromInterval((int) $versionId, null))->yes(); } else { $isDeprecated = $this->phpVersion->getVersionId() >= $versionId; }

Check warning on line 416 in src/Reflection/BetterReflection/BetterReflectionProvider.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $patch = $matches[3] ?? 0; $versionId = sprintf('%d%02d%02d', $major, $minor, $patch); if ($phpVersionType !== null) { - $isDeprecated = IntegerRangeType::fromInterval((int) $versionId, null)->isSuperTypeOf($phpVersionType)->yes(); + $isDeprecated = !IntegerRangeType::fromInterval((int) $versionId, null)->isSuperTypeOf($phpVersionType)->no(); } else { $isDeprecated = $this->phpVersion->getVersionId() >= $versionId; }

Check warning on line 416 in src/Reflection/BetterReflection/BetterReflectionProvider.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ $patch = $matches[3] ?? 0; $versionId = sprintf('%d%02d%02d', $major, $minor, $patch); if ($phpVersionType !== null) { - $isDeprecated = IntegerRangeType::fromInterval((int) $versionId, null)->isSuperTypeOf($phpVersionType)->yes(); + $isDeprecated = $phpVersionType->isSuperTypeOf(IntegerRangeType::fromInterval((int) $versionId, null))->yes(); } else { $isDeprecated = $this->phpVersion->getVersionId() >= $versionId; }
} else {
$isDeprecated = $this->phpVersion->getVersionId() >= $versionId;
}
} else {
// filter raw version number messages like in
// https://github.com/JetBrains/phpstorm-stubs/blob/9608c953230b08f07b703ecfe459cc58d5421437/filter/filter.php#L478
$deprecatedDescription = $deprecatedMessage;
}
} elseif (!$isDeprecated) {
$isDeprecated = $constantReflection->isDeprecated();
}
}

if (!$isDeprecated) {
} elseif (!$isDeprecated) {
$isDeprecated = $constantReflection->isDeprecated();
}

return $this->cachedConstants[$constantName] = new RuntimeConstantReflection(
return $this->cachedConstants[$versionKey][$constantName] = new RuntimeConstantReflection(
$constantName,
$constantValueType,
$fileName,
Expand Down
Loading