PHP_CodeSniffer won't run: "PHP_CodeSniffer: phpcs: 'php' is not recognized as an internal or external command, operable program or batch file."

PHP_CodeSniffer path:

C:\Users\[MY_USERNAME]\AppData\Roaming\Composer\vendor\bin\phpcs.bat

If I run this batch file from cmd.exe it works fine. Yet if I click "Validate" next to the phpcs path, I get the message "Can not run PHP_CodeSniffer". I went into my PHP CLI interpreter settings and was able to validate the path to my PHP executable, so I don't know what the issue is.

2 comments
Comment actions Permalink

On a hunch, I went into Terminal and entered 'which php', it said it could not find it and outputted the PATH variable. Indeed, the PHP directory was missing from PATH, but I know I configured it. I went into Settings > Tools > Terminal. Shell path was set to C:\Program Files\Git\bin\bash.exe (Git Bash). I ran Git Bash externally and 'which php' worked. I went back to my Terminal settings, took a look at Environment Variables which was empty. I clicked the browse icon and brought up the Environment Variables dialog. "Include system environment variables" was checked. I scrolled through the system env variables until I found Path, copied the value, pasted it into a text editor (it was too long to see everything in PhpStorm) and saw that PHP was not there. I went into Windows System Properties > Environment Variables and checked the system path there. PHP is in my system path! What gives?!

0
Comment actions Permalink

OK, figured it out. Per a suggestion in this discussion (https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000684650-Windows-Terminal-PATH-is-missing-environment-variables), I closed PhpStorm, restarted Toolbox, reopened my project from Toolbox and everything was fixed. PHP was showing in my system Path variable, running Terminal and 'which php' worked, and PHP_CodeSniffer runs. So weird! Someone ought to file a bug report, assuming that hasn't already been done (I'm too busy to search the bug tracker right now).

0

Please sign in to leave a comment.