The post How to Add Yii2 Coding Standards in PHP_CodeSniffer appeared first on PixelsPress.
]]>Yii2 Coding Standards have the ruleset of PHP_CodeSniffer. The ruleset is a set of sniffs that looks for things that are wrong and tells you about them so that you can fix them. So if we go to GitHub and look up the Yii2 Coding Standards and navigate to the Yii2 directory, we find the ruleset having a bunch of instructions for PHP_CodeSniffer to follow. Now ruleset tells PHP_CodeSniffer what to do.
To get this ruleset on your computer you have to use git so I am assuming that you have already installed git on your computer and we will install it as a standalone set so you can use it globally. Now copy & paste the following command which cloned the master branch and we will put it in yii2cs directory on our computer. In my case, I am on my D Drive and I have a special directory in my D Drive called utilities so I will change my directory by using the window command cd and navigate to utilities folder i.e.
cd utilities
and clone them.
git clone -b master git://github.com/yiisoft/yii2-coding-standards.git yii2cs
Now we have to tell PHP_CodeSniffer to go and look at this ruleset and to do that we will run a command phpcs and set some configuration with –config-set specifically, we want you to point at a new path with installed_paths and the path where we cloned it i.e.
phpcs --config-set installed_paths "D:\utilities\yii2cs"
After run above command, we will get the following output.
Config value "installed_paths" updated successfully;
Now if we type the following command and hit enter.
phpcs -i
We will see that we have the Yii2 Coding Standards available via the command line on PHP_CodeSniffer.
The post How to Add Yii2 Coding Standards in PHP_CodeSniffer appeared first on PixelsPress.
]]>The post How to Add WordPress Coding Standards in PHP_CodeSniffer appeared first on PixelsPress.
]]>WordPress Coding Standards have the ruleset of PHP_CodeSniffer. The ruleset is a set of sniffs that looks for things that are wrong and tells you about them so that you can fix them. So if we go to GitHub and look up the WordPress Coding Standards and navigate to it, we find the ruleset having a bunch of instructions for PHP_CodeSniffer to follow. Now ruleset tells PHP_CodeSniffer what to do.
To get this ruleset on your computer you have to use git so I am assuming that you have already installed git on your computer and we will install it as a standalone set so you can use it globally. Now copy & paste the following command which cloned the master branch and we will put it in wpcs directory on our computer. In my case, I am on my D Drive and I have a special directory in my D Drive called utilities so I will change my directory by using the window command cd and navigate to utilities folder i.e.
cd utilities
and clone them.
git clone -b master https://github.com/WordPress/WordPress-Coding-Standards.git wpcs
Now we have to tell PHP_CodeSniffer to go and look at this ruleset and to do that we will run a command phpcs and set some configuration with –config-set specifically, we want you to point at a new path with installed_paths and the path where we cloned it i.e.
phpcs --config-set installed_paths "D:\utilities\wpcs"
After run above command, we will get the following output.
Config value "installed_paths" updated successfully;
Now if we type the following command and hit enter.
phpcs -i
We will see that we have all of the WordPress Coding Standards available via the command line on PHP_CodeSniffer.
The post How to Add WordPress Coding Standards in PHP_CodeSniffer appeared first on PixelsPress.
]]>The post How to Install PHP_CodeSniffer Using Composer appeared first on PixelsPress.
]]>Before starting, you should know what PHP_CodeSniffer or PHPCS is. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent. PHPCS is a short form of it.
In my point of view using a composer to manage PHP_CodeSniffer is a wise choice. After all, the composer is just a tool for dependency management in PHP i.e. it allows you to add and manage script libraries and packages as dependencies in your project, in order to reduce development time and have the ability to take advantage of third-party code.
If you don’t have composer installed on your computer then hop over to getcomposer.org.
The easiest way to get Composer set up on your machine by using Installer. So download and run Composer-Setup.exe. It will install the latest Composer version and set up your PATH so that you can call composer
from any directory in your command line.
To make sure the installation completed successfully, run the following command:
composer help
Now move on to next step actually installing PHP_CodeSniffer.
To install PHP_CodeSniffer, use the following command, drop it to your command line, hit enter and let compose go out grab PHP_CodeSniffer, and added to your path.
composer global require "squizlabs/php_codesniffer=*"
If you want to know the path of PHP_CodeSniffer in your PC. then use the following command in windows
where.exe phpcs
On Mac, you can use the following command
which phpcs
If you want to know your current PHP_CodeSniffe version, then you can use the following command
phpcs --version
If you want to know current installed coding standards, then use the following command
phpcs -i
You have learned how to install PHP_CodeSniffer using Composer on Windows.
The post How to Install PHP_CodeSniffer Using Composer appeared first on PixelsPress.
]]>