Getting PHP lint / PhpStorm inspect errors every day from command line

1.1k views Asked by At

Attempting to run a form of PHP linting from the command line, daily.

I've tried SonarLint - lovely in PhpStorm, but sadly they've apparently stopped supporting command line commands.

I tried to get PHPLint and php -l but I'm no php guru and was struggling with composer files.

Finally I looked at PhpStorm inspect - I can get it to create a directory of 99 types of errors, it seems, but then I'd have to either write a tool to grep the files and look /count errors, warnings to see if they're going up / down daily, or check it in the IDE, neither of which are particularly appealing.

There must be a tool that produces a nice simple output that I can incorporate as part of a build pipeline, graphing errors/warnings either daily or after each build?

2

There are 2 answers

2
Martin Zeitler On

Try PHPStan (PHP Static Analysis Tool), which supports CLI execution. This is also installed with composer (which is pretty much the default); most PHP IDE support composer out-of-the-box. Likely you won't find that many packages that won't be installed alike that, unless manually dropping them into an include path (this just won't give you the auto-loader capabilities).

1
Dmitrii On

You actually can run PhpStorm inspections from command line: https://www.jetbrains.com/help/phpstorm/command-line-code-inspector.html