Installing and checking Drupal coding standards using PHP CodeSniffer consists of the following steps at high level.
- Install PHP CodeSniffer
- Install Coder
- Register Drupal standards in PHP Codesniffer
- Run the sniffs
Installing PHP code sniffer :
1- composer global require drupal/coder
You can check the location of the installation path by below command
composer global show -P
if you are in a windows machine then you need to update the below path in environment variable as a PATH key,
PATH : C:\Users\dharmendra.singh\AppData\Roaming\Composer\vendor\bin
and reopen the terminal to apply changes.
Install the below
composer global require drupal/coder dealerdirect/phpcodesniffer-composer-installer
And Manually set installed paths :
phpcs --config-set installed_paths C:/Users/dharmendra.singh/AppData/Roaming/Composer/vendor/drupal/coder/coder_sniffer
Installation is Done You can verify this has worked or not
phpcs -i
The above command should include DrupalPractice and Drupal in the installed coding standards list.
Ref :
How to Run :
PHP Code Standard with Drupal :
phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml batch_example
PHP Code Standard with Drupal Practice:
phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml NonHcpRegistrationForm.php
PHP Code Beautify & Formate :
phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml batch_example
Comments
Post a Comment