ApiPlatform\Core\Serializer\AbstractItemNormalizer::validateType PHP Method

validateType() protected method

Validates the type of the value. Allows using integers as floats for JSON formats.
protected validateType ( string $attribute, Symfony\Component\PropertyInfo\Type $type, mixed $value, string $format = null )
$attribute string
$type Symfony\Component\PropertyInfo\Type
$value mixed
$format string
    protected function validateType(string $attribute, Type $type, $value, string $format = null)
    {
        $builtinType = $type->getBuiltinType();
        if (Type::BUILTIN_TYPE_FLOAT === $builtinType && false !== strpos($format, 'json')) {
            $isValid = is_float($value) || is_int($value);
        } else {
            $isValid = call_user_func('is_' . $builtinType, $value);
        }
        if (!$isValid) {
            throw new InvalidArgumentException(sprintf('The type of the "%s" attribute must be "%s", "%s" given.', $attribute, $builtinType, gettype($value)));
        }
    }