-
Notifications
You must be signed in to change notification settings - Fork 96
Add Twig template exists rule #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d0a7ea1
to
396dc78
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the Twig environment using a loader, then it auto picks up all namespaces.
ba45518
to
9b97b95
Compare
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can avoid the if/else and write
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dunno if the error strategy need to depends on the PHPStan Level.
For instance, maybe existingTemplate|nonExistingTemplate
should only be reported at level 7 or more.
In the same way unions/maybe are reported on level 7 for classic rules.
0f833b0
to
270c2ee
Compare
Fixes #257