Skip to content

Instantly share code, notes, and snippets.

@klederson
Last active January 12, 2023 00:07
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save klederson/ca43a0f7f5b2478c1d44 to your computer and use it in GitHub Desktop.
Save klederson/ca43a0f7f5b2478c1d44 to your computer and use it in GitHub Desktop.
How to setup PHP CodeSniffer into PHP Storm with Mac OSX

Good Practices

PHP CodeSniffer into PHP Storm

Install PHPCS in mac

sudo cp /private/etc/php.ini.default /private/etc/php.ini;
sudo php /usr/lib/php/install-pear-nozlib.phar;
pear config-set php_ini /private/etc/php.ini;
pecl config-set php_ini /private/etc/php.ini;
sudo pear upgrade-all;
sudo pear install PHP_CodeSniffer;

Do not forget to add /usr/lib/php/pear/ to your include_path

Configure PHPCS into PHP Storm

Settings > Languages & Frameworks > PHP > CodeSniffer

put the path for phpcs (locate it with which phpcs in your terminal) and validate it, apply and we're done.

Settings > Editor > Inspections > PHP > PHP Code Sniffer validation

Enable it and search in the screen for Coding Standard and pick PSR2

Example http://gielberkers.com/setup-php-codesniffer-phpstorm-osx/

@asrar7787
Copy link

For anyone having errors with phpcs autoloader on mac os x high sierra, do in terminal:

echo 'include_path = ".:'pear config-get php_dir'"' | sudo tee -a /etc/php.ini

This assumes you are using native php which came with high sierra.

@asrar7787
Copy link

I was facing another error when running phpcs in terminal on zsh:
mac os x phpcs command not found

This can be resolved by getting the bin path for phpcs, by running below command in terminal:
pear config-get bin_dir

This shows something like
/usr/local/opt/php@7.0/bin

Then add an environment variable in ~/.zshrc. Simply add the following line in ~/.zshrc:
export PATH=/usr/local/opt/php@7.0/bin:$PATH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment