matches($other); } return $other instanceof self || $other instanceof MixedType; } public function inferGenericsFrom(Type $other, Generics $generics): Generics { return $generics; } public function canCast(mixed $value): bool { return is_scalar($value) || $value instanceof Stringable; } public function cast(mixed $value): bool|string|int|float { assert($this->canCast($value)); if ($value instanceof Stringable) { return (string)$value; } return $value; // @phpstan-ignore return.type (must be scalar) } public function errorMessage(): ErrorMessage { return MessageBuilder::newError('Value {source_value} is not a valid scalar.')->build(); } public function nativeType(): UnionType { return new UnionType( new NativeIntegerType(), new NativeFloatType(), new NativeStringType(), new NativeBooleanType(), ); } public function toString(): string { return 'scalar'; } }