By Gaurav Agrawal 2017
Configuring PHPCodesniffer for Drupal
7,8 in windows
+
By Gaurav Agrawal 2017
Install PEAR on Windows
Steps:
1) DownloadPEARPHARfile firstfrom: http://pear.php.net/go-pear.phar
Note:Don’t copypaste,save it as textfile andthenchange itsextensionto.phar
2) Save `go-pear file` fromabove pathandsave in PHP folderof xampp/wamp/devdesktop:(orwamp)
ex:C:ProgramFiles(x86)DevDesktopphp5_6
3) Opena commandprompt withadministrative access/permission(Allprograms –> accessoriesand
right-clickcommandpromptandselect“runas administrator”)
4) Nowgo to your PHPinstallationdirectory,install PEARnow,runfollowingcommandtoinstall PEAR:
`php go-pear.phar`
5) Nextyou will have toselectsystemforinstall type (systemisbydefaultselected,soyoucan hitenter
to continue.) (Hitenterfordefault settings)
6) Nownextstepwill askyoufor PHPwhichPEARis goingto use. (Hitenterfordefault settings)
Note:(Hitenterfor defaultsettingswhereverapplicable)
By Gaurav Agrawal 2017
7) On thislaststepyou needtoregistersome environmentvariableinyoursystem, whichcanbe done
by runningPEAR_ENV.regfile.
Install PHPCodeSniffer (PHPCS) on Windows
We have PHPPEAR isinstalledand nowitstime toinstall PHPCodeSnifferwhichisone of the Package of
PEAR.
1) Opencommandpromptwithadministrativeaccess.
2) Move to yourPHP installationdirectory.
3) Start installationof PHPCodeSnifferbyrunningfollowingcommand.
Pear install PHP_Codesniffer-2.9.1
Note: Install 2.9.1 version of codesniffer
Once installationisdone,youcanexecute phpcs-i incommandpromptto see versionof installedPHP
CodeSniffer.
So far whatwe have done isinstallationof PEARandPHP Code Sniffer onwindowsmachine.
By Gaurav Agrawal 2017
Download Coder Module for Drupal 7 or 8
2. Download the Coder module
Note:Downloadthe 8.x branch, evenif youintendtouse iton Drupal 7.
You can downloaditinany 'normal' folder,butnotina Drupal project.
cd /folder/where/i/want/coder
‘drush dl coder’ or downloadmanually.
It shoulddownloadthe latestversionwhichis8.x - if itdoesn'tthenadd --selecttothe drushcommand
and choose the 8.x branch.
3. Add Drupal standards to PHP Code Sniffer
Tell phpcsto use the Drupal standardsfromthe downloadedCodermodule:
phpcs --config-setinstalled_paths/folder/where/i/want/coder/coder/coder_sniffer
Ex: phpcs --config-setinstalled_pathsC:Userscodercoder_sniffer
At thispointyouhave PHP Code Sniffer setupwithDrupal codingstandards.
Run phpcs –i, drupal standardsare addednow. (Drupal andDrupalPractice)
Check Drupal bestpractices
You can use it fromcommandline byrunning:
phpcs --standard=Drupalextensions=php,module,inc,install,test,profile,theme,css,info,txt,md
file/to/check
Example:-
By Gaurav Agrawal 2017
Automaticallyfix codingstandards
phpcbf --standard=Drupal--extensions=php,module,inc,install,test,profile,theme,css,info,txt,md
/file/to/drupal/example_module
For more operationsvisit:
https://www.drupal.org/node/1587138
References:
http://www.xpertdeveloper.com/2014/07/install-php-codesniffer-on-windows-machine/

Drupal 7,8 Coder and PHPcodesniffer installation guide

  • 1.
    By Gaurav Agrawal2017 Configuring PHPCodesniffer for Drupal 7,8 in windows +
  • 2.
    By Gaurav Agrawal2017 Install PEAR on Windows Steps: 1) DownloadPEARPHARfile firstfrom: http://pear.php.net/go-pear.phar Note:Don’t copypaste,save it as textfile andthenchange itsextensionto.phar 2) Save `go-pear file` fromabove pathandsave in PHP folderof xampp/wamp/devdesktop:(orwamp) ex:C:ProgramFiles(x86)DevDesktopphp5_6 3) Opena commandprompt withadministrative access/permission(Allprograms –> accessoriesand right-clickcommandpromptandselect“runas administrator”) 4) Nowgo to your PHPinstallationdirectory,install PEARnow,runfollowingcommandtoinstall PEAR: `php go-pear.phar` 5) Nextyou will have toselectsystemforinstall type (systemisbydefaultselected,soyoucan hitenter to continue.) (Hitenterfordefault settings) 6) Nownextstepwill askyoufor PHPwhichPEARis goingto use. (Hitenterfordefault settings) Note:(Hitenterfor defaultsettingswhereverapplicable)
  • 3.
    By Gaurav Agrawal2017 7) On thislaststepyou needtoregistersome environmentvariableinyoursystem, whichcanbe done by runningPEAR_ENV.regfile. Install PHPCodeSniffer (PHPCS) on Windows We have PHPPEAR isinstalledand nowitstime toinstall PHPCodeSnifferwhichisone of the Package of PEAR. 1) Opencommandpromptwithadministrativeaccess. 2) Move to yourPHP installationdirectory. 3) Start installationof PHPCodeSnifferbyrunningfollowingcommand. Pear install PHP_Codesniffer-2.9.1 Note: Install 2.9.1 version of codesniffer Once installationisdone,youcanexecute phpcs-i incommandpromptto see versionof installedPHP CodeSniffer. So far whatwe have done isinstallationof PEARandPHP Code Sniffer onwindowsmachine.
  • 4.
    By Gaurav Agrawal2017 Download Coder Module for Drupal 7 or 8 2. Download the Coder module Note:Downloadthe 8.x branch, evenif youintendtouse iton Drupal 7. You can downloaditinany 'normal' folder,butnotina Drupal project. cd /folder/where/i/want/coder ‘drush dl coder’ or downloadmanually. It shoulddownloadthe latestversionwhichis8.x - if itdoesn'tthenadd --selecttothe drushcommand and choose the 8.x branch. 3. Add Drupal standards to PHP Code Sniffer Tell phpcsto use the Drupal standardsfromthe downloadedCodermodule: phpcs --config-setinstalled_paths/folder/where/i/want/coder/coder/coder_sniffer Ex: phpcs --config-setinstalled_pathsC:Userscodercoder_sniffer At thispointyouhave PHP Code Sniffer setupwithDrupal codingstandards. Run phpcs –i, drupal standardsare addednow. (Drupal andDrupalPractice) Check Drupal bestpractices You can use it fromcommandline byrunning: phpcs --standard=Drupalextensions=php,module,inc,install,test,profile,theme,css,info,txt,md file/to/check Example:-
  • 5.
    By Gaurav Agrawal2017 Automaticallyfix codingstandards phpcbf --standard=Drupal--extensions=php,module,inc,install,test,profile,theme,css,info,txt,md /file/to/drupal/example_module For more operationsvisit: https://www.drupal.org/node/1587138 References: http://www.xpertdeveloper.com/2014/07/install-php-codesniffer-on-windows-machine/