Automattic\WooCommerce\Vendor\GraphQL\Type\Definition

IntType::serializepublicWC 1.0

Method of the class: IntType{}

No Hooks.

Returns

null. Nothing (null).

Usage

$IntType = new IntType();
$IntType->serialize( $value ): int;
$value(required)
.

IntType::serialize() code WC 10.9.1

public function serialize($value): int
{
    // Fast path for 90+% of cases:
    if (is_int($value) && $value <= self::MAX_INT && $value >= self::MIN_INT) {
        return $value;
    }

    $float = is_numeric($value) || is_bool($value)
        ? (float) $value
        : null;

    if ($float === null || floor($float) !== $float) {
        $notInt = Utils::printSafe($value);
        throw new SerializationError("Int cannot represent non-integer value: {$notInt}");
    }

    if ($float > self::MAX_INT || $float < self::MIN_INT) {
        $outOfRangeInt = Utils::printSafe($value);
        throw new SerializationError("Int cannot represent non 32-bit signed integer value: {$outOfRangeInt}");
    }

    return (int) $float;
}