Skip to content

Commit

Permalink
Prevent ShouldNotHappenException in filter_* extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Mar 1, 2024
1 parent 4b978ba commit b63665c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Type/Php/FilterFunctionReturnTypeHelper.php
Expand Up @@ -40,6 +40,8 @@ final class FilterFunctionReturnTypeHelper
/** All validation filters match 0x100. */
private const VALIDATION_FILTER_BITMASK = 0x100;

private const UNKNOWN_CONSTANT = -9999999;

private ConstantStringType $flagsString;

/** @var array<int, Type>|null */
Expand Down Expand Up @@ -240,7 +242,7 @@ private function getConstant(string $constantName): int
$constant = $this->reflectionProvider->getConstant(new Node\Name($constantName), null);
$valueType = $constant->getValueType();
if (!$valueType instanceof ConstantIntegerType) {
throw new ShouldNotHappenException(sprintf('Constant %s does not have integer type.', $constantName));
return self::UNKNOWN_CONSTANT;
}

return $valueType->getValue();
Expand Down

0 comments on commit b63665c

Please sign in to comment.