phpstan-symfony
phpstan-symfony copied to clipboard
Add Twig template exists rule
Fixes #257
I would use the Twig environment using a loader, then it auto picks up all namespaces.
@ruudk, I've updated this to use a loader, but I'm not loving it. Because twig is a private service, the loader would need to look something like:
use App\Kernel;
use App\Kernel;
use Symfony\Component\Dotenv\Dotenv;
require __DIR__ . '/../vendor/autoload.php';
(new Dotenv())->bootEnv(__DIR__ . '/../.env');
$kernel = new Kernel('test', (bool) $_SERVER['APP_DEBUG']);
$kernel->boot();
return $kernel->getContainer()->get('test.service_container')->get('twig');
Yes. Downside is that now you are using the test environment.
In TwigStan I came up with this solution: https://github.com/twigstan/twigstan/blob/90e1792a68dc0cd9471ce87a1e1f0145467299f9/twig-loader-symfony.php.dist#L18-L26