How to deal with usage in templates (like Twig)?
Currently, the extension is unaware of usage in templates (like Twig).
I'm working on TwigStan. TwigStan is a separate tool that invokes PHPStan (it's not an extension). It compiles Twig templates to PHP and then cleans them up. It then executes PHPStan.
I was thinking: if TwigStan runs PHPStan with dead-code-detector extension enabled, we could export the MethodCallCollector to a JSON file. This data has all the method calls from the Twig templates to entities / methods.
Then, when normally running PHPStan on the whole project, we could include the data from JSON with the other MethodCallCollector.
Now, dead-code-detector has a full picture about calls in PHP and in Twig.
The downside of this approach is obviously that the dead-code-detector extension has a dependency on the TwigStan run.
But I think it could be fine to only run dead-code-detector on CI, after TwigStan was completed.
It compiles Twig templates to PHP and then cleans them up. It then executes PHPStan.
If your "methods called in twig" can be exported to some json, then it should be easy to create some TwigEntrypointProvider that reads that and marks such methods as used, no?
Looking at what the EntrypointProvider does, it just mimics a call to something. Interesting, I'll play with that in the future 😊