public function coerce(Parameter $parameter, $value)
    {
        $schema = $parameter->getSchema();

        switch ($schema->getType()) {
            case Schema::TYPE_STRING:
                return (string)$value;
            case Schema::TYPE_BOOL:
                if (!is_scalar($value)) {
                    return $value;
                }
                $bool = $this->coerceBooleanValue($value);

                return $bool === null ? $value : $bool;
            case Schema::TYPE_NUMBER:
                if (!is_numeric($value)) {
                    return $value;
                }

                return ctype_digit($value) ? (int)$value : (float)$value;
            case Schema::TYPE_OBJECT:
                if (!is_array($value)) {
                    return $value == '' ? null : $value;
                }
                if (count($value) && is_numeric(key($value))) {
                    return $value;
                }

                return (object)$value;
            case Schema::TYPE_ARRAY:
                if (is_array($value) || !is_string($value)) {
                    return $value;
                }

                return $this->coerceArrayValue(
                    $parameter->getCollectionFormat() ? $parameter->getCollectionFormat() : 'csv',
                    $value
                );
            case Schema::TYPE_INT:
                if (!ctype_digit($value)) {
                    return $value;
                }

                return (integer)$value;
            case Schema::TYPE_NULL:
                if ($value !== '') {
                    return $value;
                }

                return null;
            default:
                return $value;
        }
    }