Download the PHP package 26b/php-pre-commit without Composer
On this page you can find all versions of the php package 26b/php-pre-commit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download 26b/php-pre-commit
More information about 26b/php-pre-commit
Files in 26b/php-pre-commit
Package php-pre-commit
Short Description Pre-commit git hook for enforcing php standards.
License MIT
Informations about the package php-pre-commit
php-pre-commit
Pre-commit git hook for enforcing php standards.
Currently uses PHP_CodeSniffer (PHPCS) and corrects .php staged files according to a phpcs config file (usually a phpcs.xml).
Install via the composer command:
In order for the hooks to be moved into the .git/hooks folder add the following to the project's composer.json:
With composer install or composer update the pre-commit hook will be moved into .git/hooks.
If you want to skip the pre-commit execution, you can add the argument --no-verify to git commit.
[!IMPORTANT] This package does not require PHPCS because it is up to you whether you want to use a local or global
phpcs. Localphpcstakes precedence when the pre-commit runs. You can require them in the following way:
Use Cases
Local PHPCS
If you intend to use different sets of standards in different repositories we advise you to install php_codesniffer locally, this will make sure that there will be no conflicts when configuring phpcs --config-set ... later on. In case you choose the local approach make sure to correct the PHPCS path on the examples below.
Usually it would be something like changing all phpcs references to ./vendor/bin/phpcs (or any other local path).
WordPress
Setup WordPress Standards (Manual)
First we need to clone the WordPress standards repository. It should be placed in a directory that phpcs can access. We placed ours in the home directory wpcs directory in root. Clone the repository into the wpcs folder via:
Secondly, we need to tell phpcs where these standards are.
Finally, in order to check that phpcs recognises and uses the standards, we can check it like this:
The output should resemble this, with the WordPress standards. If they are missing, phpcs might not be recognising the path. Check its paths via:
Alternative (Automatic)
As an alternative you can use PHP_CodeSniffer Standards Composer Installer Plugin which helps to automatically link the wanted standards to phpcs. Be aware that it requires phpcs locally and so our pre-commit hook will use that phpcs. We can then require this package and WPCS in the following manner:
Or add them to the composer.json:
And add scripts, to configure phpcs correctly upon composer install, like this:
Laravel
Automatic Setup
Here, you can also use PHP_CodeSniffer Standards Composer Installer Plugin to automatically link the Laravel standards to phpcs. Again, make sure phpcs is installed locally and so our pre-commit. We just need to require emielmolenaar/phpcs-laravel package and we are done:
Finally, add the same scripts to configure phpcs correctly upon composer install:
Manual Setup
A Laravel's coding standard repository that is being updated consistently is emielmolenaar/phpcs-laravel. We will now proceed to the configuration (very similar to the WordPress configuration). First clone emielmolenaar/phpcs-laravel repository:
Again, tell to phpcs where the standards are.
Once more, make sure phpcs recognises and uses the installed standards:
The --config-show will give the following output:
Troubleshooting
- If the script is not executable, run the following, where the path is to the composer executable. (If installed globally it should be in
~/.composer/vendor/bin, otherwise it's in the folder that containscomposer.json.)