Skip to content
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

How to deal with usage in templates (like Twig)? #88

Open
ruudk opened this issue Sep 14, 2024 · 2 comments
Open

How to deal with usage in templates (like Twig)? #88

ruudk opened this issue Sep 14, 2024 · 2 comments

Comments

@ruudk
Copy link

ruudk commented Sep 14, 2024

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.

@janedbal
Copy link
Member

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?

@ruudk
Copy link
Author

ruudk commented Sep 14, 2024

Looking at what the EntrypointProvider does, it just mimics a call to something. Interesting, I'll play with that in the future 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants