dev-master
9999999-dev https://github.com/tripomatic/php-code-qualityA set of PHP code quality tools
MIT
The Requires
by Jan Jakes
php code quality
A set of PHP code quality tools
A set of PHP code quality tools for VCS., (*1)
Tripomatic\PhpCodeQuality allows for automatic PHP code checking while commiting changes in VCS. At the moment Git and Mercurial are supported. The tool can perform the following pre-commit checks:, (*2)
composer.json
and composer.lock
are versioned it checks whether they are in sync.php -l
..php_cs
in the repository root.Install Tripomatic\PhpCodeQuality using Composer:, (*3)
$ composer require --dev tripomatic/php-code-quality
To setup automatic code checking before every commit add the following line to your pre-commit hook:, (*4)
php vendor/bin/php-code-quality check-staged-files
The tool automatically detects the repository type (Git, Mercurial) and checks the changes to be commited., (*5)
In Git these changes doesn't have to reflect the working tree so the actual changes are fetched to a temporary directory and the files are controlled there. The directory is automatically removed., (*6)
The pre-commit hooks can be also set-up automatically using Composer's scripts. For instance you can add the following lines to your composer.json
:, (*7)
"scripts": { "pre-install-cmd": "sh git/install-hooks.sh", "pre-update-cmd": "sh git/install-hooks.sh" }
And create a git/install-hooks.sh
file containing:, (*8)
#!/bin/sh ROOT="$(cd "$(dirname "$0")"/..; pwd -P)" echo "Installing GIT hooks" rm -rf ${ROOT}/.git/hooks ln -s ${ROOT}/git/hooks ${ROOT}/.git/hooks chmod +x ${ROOT}/.git/hooks/*
And finally, create a git/hooks
directory and a pre-commit
file in it containing:, (*9)
#!/bin/sh ROOT="$(cd "$(dirname "$0")"/../..; pwd -P)" php ${ROOT}/vendor/bin/php-code-quality check-staged-files
The git
directory can be added to the repository and that way the pre-commit code-checking hook will be automatically installed on any composer install
and composer update
., (*10)
In case you use tabs for indenting this package contains also an IndentWithTabsFixer
for PHP-CS-Fixer. Installing in the .php_cs
is easy:, (*11)
return Symfony\CS\Config\Config::create() ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) ->addCustomFixer(new Symfony\CS\Fixer\Contrib\IndentWithTabsFixer()) ->fixers([ '-indentation', # turn off the PSR-2 rule 'indent_with_tabs', ]);
A complete example can be the .php_cs
for this repository., (*12)
Tripomatic\PhpCodeQuality is licensed under MIT., (*13)
A set of PHP code quality tools
MIT
php code quality