src/Viserio/Bridge/Twig/Command/LintCommand.php
protected function validate(string $template, string $file): array
    {
        $realLoader = $this->environment->getLoader();

        try {
            $temporaryLoader = new ArrayLoader([$file => $template]);

            $this->environment->setLoader($temporaryLoader);
            $nodeTree = $this->environment->parse($this->environment->tokenize(new Source($template, $file)));

            $this->environment->compile($nodeTree);
            $this->environment->setLoader($realLoader);
        } catch (Error $exception) {
            $this->environment->setLoader($realLoader);

            return [
                'template'  => $template,
                'file'      => $file,
                'valid'     => false,
                'exception' => $exception,
            ];
        }

        return [
            'template' => $template,
            'file'     => $file,
            'valid'    => true,
        ];
    }
protected function validate(string $template, string $file): array
    {
        $realLoader = $this->environment->getLoader();

        try {
            $temporaryLoader = new ArrayLoader([$file => $template]);

            $this->environment->setLoader($temporaryLoader);
            $nodeTree = $this->environment->parse($this->environment->tokenize(new Source($template, $file)));

            $this->environment->compile($nodeTree);
            $this->environment->setLoader($realLoader);
        } catch (Error $exception) {
            $this->environment->setLoader($realLoader);

            return [
                'template'  => $template,
                'file'      => $file,
                'valid'     => false,
                'exception' => $exception,
            ];
        }

        return [
            'template' => $template,
            'file'     => $file,
            'valid'    => true,
        ];
    }
Validate the template.

@param string $template twig template
@param string $file

@return array