2017 © Pedro Peláez
 

library php-code-quality

A set of PHP code quality tools

image

tripomatic/php-code-quality

A set of PHP code quality tools

  • Tuesday, June 16, 2015
  • by JanJakes
  • Repository
  • 13 Watchers
  • 3 Stars
  • 420 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Tripomatic\PhpCodeQuality

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)

  1. If both composer.json and composer.lock are versioned it checks whether they are in sync.
  2. All changed or added PHP files are checked for syntax errors with php -l.
  3. All changed or added PHP files are chekced for coding style with PHP-CS-Fixer. This check requires coding style definition file .php_cs in the repository root.

Installation

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)

Automatic setup with Composer

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)

Other

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)

License

Tripomatic\PhpCodeQuality is licensed under MIT., (*13)

The Versions

16/06 2015

dev-master

9999999-dev https://github.com/tripomatic/php-code-quality

A set of PHP code quality tools

  Sources   Download

MIT

The Requires

 

by Jan Jakes

php code quality