and($node->isLessThan(Node::value(0))); } public function matches(Type $other): bool { if ($other instanceof UnionType) { return $other->isMatchedBy($this); } if ($other instanceof ArrayKeyType) { return $other->isMatchedBy($this); } return $other instanceof self || $other instanceof NativeIntegerType || $other instanceof ScalarConcreteType || $other instanceof MixedType; } public function inferGenericsFrom(Type $other, Generics $generics): Generics { return $generics; } public function canCast(mixed $value): bool { return ! is_bool($value) && filter_var($value, FILTER_VALIDATE_INT) !== false && $value < 0; } public function cast(mixed $value): int { assert($this->canCast($value)); return (int)$value; // @phpstan-ignore-line } public function errorMessage(): ErrorMessage { return MessageBuilder::newError('Value {source_value} is not a valid negative integer.') ->withCode('invalid_negative_integer') ->build(); } public function nativeType(): NativeIntegerType { return NativeIntegerType::get(); } public function toString(): string { return 'negative-int'; } }