See https://blog.acromedia.com/making-drupal-code-standards-work-for-you-with-phpstorm-phpcs-phpcbf
composer global require drupal/coder
$PATH variable in ~/.profile, ~/.bash_profile, ~/.bashrc or ~/.zshrc:export PATH="$PATH:$HOME/.config/composer/vendor/bin"
composer global require dealerdirect/phpcodesniffer-composer-installer
composer global require dealerdirect/phpcodesniffer-composer-installer
To manually register the Drupal and DrupalPractice Standard with PHPCS, you must set the installed paths:
phpcs --config-set installed_paths ~/.config/composer/vendor/drupal/coder/coder_sniffer
Above, the command should return Config value "installed_paths" updated successfully on console.
ln -s ~/.config/composer/vendor/drupal/coder/coder_sniffer/Drupal ~/.config/composer/vendor/squizlabs/php_codesniffer/src/Standards/Drupal
ln -s ~/.config/composer/vendor/drupal/coder/coder_sniffer/DrupalPractice ~/.config/composer/vendor/squizlabs/php_codesniffer/src/Standards/DrupalPractice
Go to Language & Framework > PHP > Quality Tools, set config PHPCodeSniffer to use this path: /home/rpayanm/.config/composer/vendor/squizlabs/php_codesniffer/bin/phpcs
Go to File > Settings > Editor > Inspections, in right side go to PHP/Quality tools/PHP Code Sniffer validation:
You can only set one standard at a time through the UI if you need both then edit the Project_Default.xml file in the .idea folder (.idea/inspectionProfiles/Project_Default.xml) of your project. Find the CODING_STANDARD option and change it to:
<option name="CODING_STANDARD" value="Drupal,DrupalPractice" />