src/ChrisKonnertz/DeepLy/ResponseBag/TranslationBag.php
public function verifyResponseContent($responseContent)
    {
        // Let the original method of the abstract base class do some basic checks
        parent::verifyResponseContent($responseContent);

        if (! property_exists($responseContent, 'source_lang')) {
            throw new BagException(
                'DeepLy API call resulted in a malformed result - source_lang attribute is missing', 210
            );
        }
        if ($responseContent->source_lang === '') {
            throw new BagException('DeepL could not auto-detect the source language of the text', 211);
        }
        if (! property_exists($responseContent, 'target_lang')) {
            throw new BagException(
                'DeepLy API call resulted in a malformed result - target_lang attribute is missing', 220
            );
        }

        if (! property_exists($responseContent, 'translations')) {
            throw new BagException(
                'DeepLy API call resulted in a malformed result - translations are missing', 230
            );
        }
        if (! is_array($responseContent->translations)) {
            throw new BagException(
                'DeepLy API call resulted in a malformed result - translations are not an array', 231
            );
        }

        if (sizeof($responseContent->translations) > 0) {
            foreach ($responseContent->translations as $index => $translation) {
                if (! property_exists($translation, 'beams')) {
                    throw new BagException(
                        'DeepLy API call resulted in a malformed result - beams are missing for translation '.$index,
                        240
                    );
                }
                if (! is_array($translation->beams)) {
                    throw new BagException(
                        'DeepLy API call resulted in a malformed result - beams are not an array in translation '.
                        $index,
                        241
                    );
                }
                if (sizeof($translation->beams) == 0) {
                    throw new BagException(
                        'DeepLy API call resulted in a malformed result - beams array is empty in translation '.$index,
                        242
                    );
                }

                foreach ($translation->beams as $beamIndex => $beam) {
                    if (! property_exists($beam, 'postprocessed_sentence')) {
                        throw new BagException(
                            'DeepLy API call resulted in a malformed result - '.
                            'postprocessed_sentence property is missing in beam '.$index,
                            250
                        );
                    }
                }
            }
        }
    }
public function verifyResponseContent($responseContent)
    {
        // Let the original method of the abstract base class do some basic checks
        parent::verifyResponseContent($responseContent);

        if (! property_exists($responseContent, 'source_lang')) {
            throw new BagException(
                'DeepLy API call resulted in a malformed result - source_lang attribute is missing', 210
            );
        }
        if ($responseContent->source_lang === '') {
            throw new BagException('DeepL could not auto-detect the source language of the text', 211);
        }
        if (! property_exists($responseContent, 'target_lang')) {
            throw new BagException(
                'DeepLy API call resulted in a malformed result - target_lang attribute is missing', 220
            );
        }

        if (! property_exists($responseContent, 'translations')) {
            throw new BagException(
                'DeepLy API call resulted in a malformed result - translations are missing', 230
            );
        }
        if (! is_array($responseContent->translations)) {
            throw new BagException(
                'DeepLy API call resulted in a malformed result - translations are not an array', 231
            );
        }

        if (sizeof($responseContent->translations) > 0) {
            foreach ($responseContent->translations as $index => $translation) {
                if (! property_exists($translation, 'beams')) {
                    throw new BagException(
                        'DeepLy API call resulted in a malformed result - beams are missing for translation '.$index,
                        240
                    );
                }
                if (! is_array($translation->beams)) {
                    throw new BagException(
                        'DeepLy API call resulted in a malformed result - beams are not an array in translation '.
                        $index,
                        241
                    );
                }
                if (sizeof($translation->beams) == 0) {
                    throw new BagException(
                        'DeepLy API call resulted in a malformed result - beams array is empty in translation '.$index,
                        242
                    );
                }

                foreach ($translation->beams as $beamIndex => $beam) {
                    if (! property_exists($beam, 'postprocessed_sentence')) {
                        throw new BagException(
                            'DeepLy API call resulted in a malformed result - '.
                            'postprocessed_sentence property is missing in beam '.$index,
                            250
                        );
                    }
                }
            }
        }
    }
Verifies that the given response content (usually a \stdClass built by json_decode())
is a valid result from an API call to the DeepL API.
This method will not return true/false but throw an exception if something is invalid.
Especially it will throw an exception if the API was not able to auto-detected the source language
(if no language code was given).

@param mixed|null $responseContent The response content (payload) of a translation API call
@throws BagException
@return void