src/ChrisKonnertz/DeepLy/Protocol/JsonRpcProtocol.php
protected function validateResponseData($responseData)
    {
        if (! $responseData instanceof \stdClass) {
            throw new ProtocolException('DeepLy API call did not return JSON that describes a \stdClass object');
        }

        if (! property_exists($responseData, 'jsonrpc')) {
            throw new ProtocolException('
                The given response data does not seem to be come from a JSON RPC request - it has no "jsonrpc" property'
            );
        }
        if ($responseData->jsonrpc !== self::PROTOCOL_VERSION) {
            throw new ProtocolException(
                'The version of the JSON RPC response does not match the expected version '.self::PROTOCOL_VERSION
            );
        }

        if (property_exists($responseData, 'error')) {
            if ($responseData->error instanceof \stdClass and property_exists($responseData->error, 'message')) {
                $message = 'DeepLy API call resulted in this error: '.$responseData->error->message;

                // Note: According to the specs the error object can include a data property,
                // but the DeepL API (usually) does not seem to add it. We will completely ignore it.
                if (property_exists($responseData->error, 'code') and is_int($responseData->error->code)) {
                    // Note: The meanings of the codes are defined in the protocol specification
                    throw new ProtocolException($message, $responseData->error->code);
                } else {
                    throw new ProtocolException($message);
                }
            } else {
                throw new ProtocolException('DeepLy API call resulted in an unknown error');
            }
        }

        if ($this->validateId) {
            if (! property_exists($responseData, 'id')) {
                throw new ProtocolException('DeepLy API call resulted in a malformed result - ID property is missing');
            }
            if ($responseData->id !== self::$lastId) {
                throw new ProtocolException('DeepLy API call resulted in an invalid result - ID is not '.self::$lastId);
            }
        }

        if (! property_exists($responseData, 'result')) {
            throw new ProtocolException(
                'DeepLy API call resulted in a malformed result - inner result property is missing'
            );
        }
        if (! $responseData->result instanceof \stdClass) {
            // If we try to translate an empty string the API responses with a malformed generic error response.
            // Due to the nature of the response we do not know for sure what has caused it.
            throw new ProtocolException(
                'DeepLy API call resulted in a malformed result - inner result property is not a \stdClass. '.
                'A possible cause is that the API could not translate the text, for example if it is an empty string'
            );
        }
    }
protected function validateResponseData($responseData)
    {
        if (! $responseData instanceof \stdClass) {
            throw new ProtocolException('DeepLy API call did not return JSON that describes a \stdClass object');
        }

        if (! property_exists($responseData, 'jsonrpc')) {
            throw new ProtocolException('
                The given response data does not seem to be come from a JSON RPC request - it has no "jsonrpc" property'
            );
        }
        if ($responseData->jsonrpc !== self::PROTOCOL_VERSION) {
            throw new ProtocolException(
                'The version of the JSON RPC response does not match the expected version '.self::PROTOCOL_VERSION
            );
        }

        if (property_exists($responseData, 'error')) {
            if ($responseData->error instanceof \stdClass and property_exists($responseData->error, 'message')) {
                $message = 'DeepLy API call resulted in this error: '.$responseData->error->message;

                // Note: According to the specs the error object can include a data property,
                // but the DeepL API (usually) does not seem to add it. We will completely ignore it.
                if (property_exists($responseData->error, 'code') and is_int($responseData->error->code)) {
                    // Note: The meanings of the codes are defined in the protocol specification
                    throw new ProtocolException($message, $responseData->error->code);
                } else {
                    throw new ProtocolException($message);
                }
            } else {
                throw new ProtocolException('DeepLy API call resulted in an unknown error');
            }
        }

        if ($this->validateId) {
            if (! property_exists($responseData, 'id')) {
                throw new ProtocolException('DeepLy API call resulted in a malformed result - ID property is missing');
            }
            if ($responseData->id !== self::$lastId) {
                throw new ProtocolException('DeepLy API call resulted in an invalid result - ID is not '.self::$lastId);
            }
        }

        if (! property_exists($responseData, 'result')) {
            throw new ProtocolException(
                'DeepLy API call resulted in a malformed result - inner result property is missing'
            );
        }
        if (! $responseData->result instanceof \stdClass) {
            // If we try to translate an empty string the API responses with a malformed generic error response.
            // Due to the nature of the response we do not know for sure what has caused it.
            throw new ProtocolException(
                'DeepLy API call resulted in a malformed result - inner result property is not a \stdClass. '.
                'A possible cause is that the API could not translate the text, for example if it is an empty string'
            );
        }
    }
Validates that the response data (usually a \stdClass object built by json_decode)
is valid response data from an API call to the DeepL API using the JSON RPC protocol.

@param mixed $responseData The response data, usually a \stdClass object
@throws ProtocolException