Skip to content

agtong/phpcs-git-pre-commit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPCS git pre-commit hook

About

Auto installed git pre-commit hook for running PHP Code Sniffer code checking to PSR12 coding standard compliance. It checks only files that are to be committed.

Inspired by Enforce code standards with composer, git hooks, and phpcs

Requirement

You need to have a docker service named php that is running php-fpm, eg. yiisoftware/yii2-php:7.4-fpm.

Installation

Install agtong/phpcs-git-pre-commit with composer require command:

composer require --dev "agtong/phpcs-git-pre-commit"

Or alternatively, include a dependency for agtong/phpcs-git-pre-commit in your composer.json file manually:

{
    "require-dev": {
        "agtong/phpcs-git-pre-commit": "dev-master"
    }
}

To enable code sniff, аdd to post-install-cmd and post-update-cmd in composer.json installation script:

"post-install-cmd": [
    "sh ./vendor/agtong/phpcs-git-pre-commit/src/setup.sh"
],
"post-update-cmd": [
    "sh ./vendor/agtong/phpcs-git-pre-commit/src/setup.sh"
]

Then run composer install or composer update. pre-commit hook will be installed or updated if it already exists.

Usage

Run git commit and pre-commit hook will check your committed files like if you run

docker-compose exec php /app/vendor/bin/phpcs --standard=PSR12 /path/to/file.php

Note: the tests directory is excluded form this check.

Contributing

Feel free to make pull requests!

About

Code sniffer git pre-commit hook. Composer installation.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 100.0%