Skip to content

Commit ea26c30

Browse files
phpstan-botclaude
authored andcommitted
Combine FILTER_THROW_ON_FAILURE constant availability with the flag check
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b063d41 commit ea26c30

1 file changed

Lines changed: 3 additions & 28 deletions

File tree

‎src/Type/Php/FilterFunctionReturnTypeHelper.php‎

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -517,35 +517,10 @@ public function hasFlag(string $flagName, ?Type $flagsType): TrinaryLogic
517517

518518
public function hasThrowOnFailureFlag(?Type $flagsType, PhpVersions $phpVersions): TrinaryLogic
519519
{
520-
$hasConstant = $phpVersions->hasFilterThrowOnFailureConstant();
521-
if ($hasConstant->no()) {
522-
return TrinaryLogic::createNo();
523-
}
524-
525-
$hasFlag = $this->hasFlag('FILTER_THROW_ON_FAILURE', $flagsType);
526-
527520
// Flag values are resolved from the runtime. Before PHP 8.5, FILTER_FLAG_GLOBAL_RANGE used the bit
528-
// that PHP 8.5 assigned to FILTER_THROW_ON_FAILURE, so on such runtime a set bit may mean either flag.
529-
// When the analysed code definitely runs on PHP 8.5+, the bit can only mean FILTER_THROW_ON_FAILURE.
530-
if ($hasConstant->maybe() && $this->isThrowOnFailureFlagAmbiguous()) {
531-
return $hasFlag->and(TrinaryLogic::createMaybe());
532-
}
533-
534-
return $hasFlag;
535-
}
536-
537-
/**
538-
* True when PHPStan runs on PHP < 8.5: FILTER_FLAG_GLOBAL_RANGE then has its runtime value 0x10000000,
539-
* while FILTER_THROW_ON_FAILURE does not exist at runtime and is read from stubs with the PHP 8.5 value,
540-
* which is also 0x10000000. On PHP 8.5+ runtime FILTER_FLAG_GLOBAL_RANGE is 0x20000000, so they differ.
541-
*/
542-
private function isThrowOnFailureFlagAmbiguous(): bool
543-
{
544-
if (!$this->reflectionProvider->hasConstant(new Node\Name\FullyQualified('FILTER_FLAG_GLOBAL_RANGE'), null)) {
545-
return false;
546-
}
547-
548-
return $this->getConstant('FILTER_THROW_ON_FAILURE') === $this->getConstant('FILTER_FLAG_GLOBAL_RANGE');
521+
// that PHP 8.5 assigned to FILTER_THROW_ON_FAILURE, so a set bit only definitely means
522+
// FILTER_THROW_ON_FAILURE when the analysed code definitely runs on PHP 8.5+.
523+
return $phpVersions->hasFilterThrowOnFailureConstant()->and($this->hasFlag('FILTER_THROW_ON_FAILURE', $flagsType));
549524
}
550525

551526
private function getFlagsValue(Type $exprType): Type

0 commit comments

Comments
 (0)