We are using phpstan to detect and fix some common errors. This tool works fine with plain PHP files or classes, but not with ctp files. This is our phpstan.neon config file:
parameters:
fileExtensions:
- php
- ctp
But if we analyze a ctp file, we get errors like this:
After some more research, it looks that phpstan doesn’t work well with that kind of annotations: https://github.com/phpstan/phpstan/issues/351. Anayway, thanks for the response; it is useful for editors.
I wouldn’t suggest trying to use phpstan for .ctp files. The template files are basically php code fragments which are included inside View class. So by themselves they don’t have enough context available for phpstan to do it’s job. You’ll have to go about adding annotations like /** @var FooType $bar */ throughout the template files.