{"id":45800,"date":"2017-02-10T15:47:57","date_gmt":"2017-02-10T10:17:57","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=45800"},"modified":"2017-02-12T19:21:23","modified_gmt":"2017-02-12T13:51:23","slug":"how-to-install-and-setup-drupal-code-sniffer","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-install-and-setup-drupal-code-sniffer\/","title":{"rendered":"How to Install and Setup Drupal Code Sniffer?"},"content":{"rendered":"<p><strong>About Drupal Coder<\/strong><\/p>\n<p>Coder checks <a title=\"Drupal development and consulting\" href=\"http:\/\/www.tothenew.com\/wcm\/drupal-development-consulting-services\">Drupal<\/a>\u00a0code against <a href=\"http:\/\/drupal.org\/coding-standards\" target=\"_blank\" rel=\"nofollow\">Drupal coding standards<\/a> and other best practices. It can also fix coding standard violations for you with the phpcs and phpcbf command from PHP_CodeSniffer<\/p>\n<p><strong>Installing and setup Drupal coder<\/strong><\/p>\n<p>Here&#8217;s a step-by-step guide:<\/p>\n<p>Follow the steps below to install coder<\/p>\n<ul>\n<li>Open a Terminal window<\/li>\n<li>Go to home directory<br \/>\nCd ~<\/li>\n<li>Clone the latest code version using git<br \/>\ngit clone &#8211;branch 8.x-2.x<br \/>\ncd coder<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45842 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog1.png\" alt=\"\" width=\"878\" height=\"143\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog1.png 878w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog1-300x48.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog1-624x101.png 624w\" sizes=\"(max-width: 878px) 100vw, 878px\" \/><\/li>\n<li>Install dependencies using composer<br \/>\ncomposer install<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45841 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog2.png\" alt=\"\" width=\"811\" height=\"489\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog2.png 811w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog2-300x180.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog2-624x376.png 624w\" sizes=\"(max-width: 811px) 100vw, 811px\" \/><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45840 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog3.png\" alt=\"\" width=\"954\" height=\"686\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog3.png 954w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog3-300x215.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog3-624x448.png 624w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/li>\n<li>Create a symlink for the phpcs and phpcbf command<br \/>\nsudo ln -s ~\/coder\/vendor\/bin\/phpcs \/usr\/bin\/phpcs<br \/>\nsudo ln -s ~\/coder\/vendor\/bin\/phpcbf \/usr\/bin\/phpcf<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45839 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog4.png\" alt=\"\" width=\"757\" height=\"79\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog4.png 757w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog4-300x31.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog4-624x65.png 624w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><\/li>\n<li>Register the Drupal and Drupal Practice Standard with PHPCS<br \/>\nphpcs &#8211;config-set installed_paths ~\/coder\/coder_sniffer<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45838 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog5.png\" alt=\"\" width=\"857\" height=\"38\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog5.png 857w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog5-300x13.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog5-624x27.png 624w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><\/li>\n<\/ul>\n<p><strong>How to use<\/strong><\/p>\n<ul>\n<li>To check the file for coding standard<br \/>\nphpcs &#8211;standard=DrupalPractice &lt;\/path\/to\/example.module&gt;<\/li>\n<li>To check the complete directory recursively for coding standards<br \/>\nphpcs &#8211;standard=DrupalPractice &lt;path to directory&gt;<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45837 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog6.png\" alt=\"\" width=\"1117\" height=\"441\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog6.png 1117w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog6-300x118.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog6-1024x404.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog6-624x246.png 624w\" sizes=\"(max-width: 1117px) 100vw, 1117px\" \/><\/li>\n<\/ul>\n<p>Some issue could be resolved automatically by phpcbf<\/p>\n<ul>\n<li>To fix error in file<br \/>\nphpcbf &#8211;standard=Drupal &lt;path to file with file name&gt;<\/li>\n<li>To fix error in the complete directory<br \/>\nphpcbf &#8211;standard=Drupal &lt;path to directory&gt;<img decoding=\"async\" loading=\"lazy\" class=\"alignleft wp-image-45836 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog7.png\" alt=\"blog7\" width=\"1121\" height=\"111\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog7.png 1121w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog7-300x29.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog7-1024x101.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/blog7-624x61.png 624w\" sizes=\"(max-width: 1121px) 100vw, 1121px\" \/><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>About Drupal Coder Coder checks Drupal\u00a0code against Drupal coding standards and other best practices. It can also fix coding standard violations for you with the phpcs and phpcbf command from PHP_CodeSniffer Installing and setup Drupal coder Here&#8217;s a step-by-step guide: Follow the steps below to install coder Open a Terminal window Go to home directory [&hellip;]<\/p>\n","protected":false},"author":1009,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"aside","meta":{"iawp_total_views":42},"categories":[3602],"tags":[4416,4419,4862,8],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/45800"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1009"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=45800"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/45800\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=45800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=45800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=45800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}