src/Viserio/Component/Parser/Command/XliffLintCommand.php
protected function validate(string $content, ?string $file = null): array
    {
        // Avoid: Warning DOMDocument::loadXML(): Empty string supplied as input
        if (\trim($content) === '') {
            return ['file' => $file, 'valid' => true];
        }

        \libxml_use_internal_errors(true);

        $document = new DOMDocument();
        $document->loadXML($content);

        $errors         = [];
        $targetLanguage = $this->getTargetLanguageFromFile($document);

        if ($targetLanguage !== null) {
            $expectedFileExtension = \sprintf('%s.xlf', \str_replace('-', '_', $targetLanguage));
            $realFileExtension     = \explode('.', \basename($file), 2)[1] ?? '';

            if ($expectedFileExtension !== $realFileExtension) {
                $errors[] = [
                    'line'    => -1,
                    'column'  => -1,
                    'message' => \sprintf('There is a mismatch between the file extension [%s] and the [%s] value used in the "target-language" attribute of the file.', $realFileExtension, $targetLanguage),
                ];
            }
        }

        foreach (XliffUtils::validateSchema($document) as $xmlError) {
            $errors[] = [
                'line'    => $xmlError['line'],
                'column'  => $xmlError['column'],
                'message' => $xmlError['message'],
            ];
        }

        return ['file' => $file, 'valid' => 0 === \count($errors), 'messages' => $errors];
    }
protected function validate(string $content, ?string $file = null): array
    {
        // Avoid: Warning DOMDocument::loadXML(): Empty string supplied as input
        if (\trim($content) === '') {
            return ['file' => $file, 'valid' => true];
        }

        \libxml_use_internal_errors(true);

        $document = new DOMDocument();
        $document->loadXML($content);

        $errors         = [];
        $targetLanguage = $this->getTargetLanguageFromFile($document);

        if ($targetLanguage !== null) {
            $expectedFileExtension = \sprintf('%s.xlf', \str_replace('-', '_', $targetLanguage));
            $realFileExtension     = \explode('.', \basename($file), 2)[1] ?? '';

            if ($expectedFileExtension !== $realFileExtension) {
                $errors[] = [
                    'line'    => -1,
                    'column'  => -1,
                    'message' => \sprintf('There is a mismatch between the file extension [%s] and the [%s] value used in the "target-language" attribute of the file.', $realFileExtension, $targetLanguage),
                ];
            }
        }

        foreach (XliffUtils::validateSchema($document) as $xmlError) {
            $errors[] = [
                'line'    => $xmlError['line'],
                'column'  => $xmlError['column'],
                'message' => $xmlError['message'],
            ];
        }

        return ['file' => $file, 'valid' => 0 === \count($errors), 'messages' => $errors];
    }
{@inheritdoc}