PHPackages                             bitban/php-code-quality-tools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. bitban/php-code-quality-tools

ActiveLibrary[Testing &amp; Quality](/categories/testing)

bitban/php-code-quality-tools
=============================

PHP Code Quality Tools used in Bitban projects.

v0.9.16(7y ago)416.5k[4 issues](https://github.com/bitban/php-code-quality-tools/issues)1MITPHPCI failing

Since Jul 7Pushed 5y ago4 watchersCompare

[ Source](https://github.com/bitban/php-code-quality-tools)[ Packagist](https://packagist.org/packages/bitban/php-code-quality-tools)[ RSS](/packages/bitban-php-code-quality-tools/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (6)Versions (19)Used By (1)

PHP Code Quality Tools
======================

[](#php-code-quality-tools)

[![Latest Stable Version](https://camo.githubusercontent.com/0b6b0e22cec0c25694e63d730b02ca359c2cdb527d27b7763d80d20f343c6ba4/68747470733a2f2f706f7365722e707567782e6f72672f62697462616e2f7068702d636f64652d7175616c6974792d746f6f6c732f762f737461626c65)](https://packagist.org/packages/bitban/php-code-quality-tools)[![License](https://camo.githubusercontent.com/49ec91d4f73a6c3bacd0817152ece1430b5eacb88fbe14d6a29368adbc352fe8/68747470733a2f2f706f7365722e707567782e6f72672f62697462616e2f7068702d636f64652d7175616c6974792d746f6f6c732f6c6963656e7365)](https://packagist.org/packages/bitban/php-code-quality-tools)[![Build Status](https://camo.githubusercontent.com/1d7c8a7d08d7e796dc3aed32fdb93422b1c7acdabc0e62301cd2af9ce9bf3d8b/68747470733a2f2f7472617669732d63692e6f72672f62697462616e2f7068702d636f64652d7175616c6974792d746f6f6c732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bitban/php-code-quality-tools)[![Coverage Status](https://camo.githubusercontent.com/e441a858901ca30d8275b2459945f47262de3596655d5292081dd5cad34ee48f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f62697462616e2f7068702d636f64652d7175616c6974792d746f6f6c732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/bitban/php-code-quality-tools?branch=master)

These tools may be used to detect and fix some common errors before committing them to the code repository.

Check command reference section for more detailed information.

Installation
------------

[](#installation)

If you have not done this yet, add bin directory to composer.json:

`composer config bin-dir bin/`

It will add something like this to your composer.json file:

```
"config": {
    "bin-dir": "bin/"
}
```

For a better experience, we also suggest to configure post-install and post-update script:

```
"scripts": {
    "post-install-cmd": [
        "Bitban\\PhpCodeQualityTools\\Composer\\ScriptHandler::checkHooks"
    ],
    "post-update-cmd": [
        "Bitban\\PhpCodeQualityTools\\Composer\\ScriptHandler::checkHooks"
    ]
}
```

Then, require new dev dependency:

`composer require --dev "bitban/php-code-quality-tools:dev-master"`

After that, a new command is available from project's root path:

`bin/php-cqtools`

Command reference
-----------------

[](#command-reference)

### Check Git Hooks

[](#check-git-hooks)

Checks if Git hooks are installed for current project. If not, it gives a hint to install them, but does not take any action automatically.

`bin/php-cqtools hooks:check`

### Install Git Hooks

[](#install-git-hooks)

Installs Git hooks into .git/hooks/. If destination files already exist, the are backed up.

`bin/php-cqtools hooks:install`

Git hooks managed are:

- pre-commit
- post-checkout
- post-merge

#### pre-commit hook

[](#pre-commit-hook)

It calls code:validate command.

`bin/php-cqtools code:validate --only-commited-files`

#### post-checkout hook

[](#post-checkout-hook)

It checks whether composer.lock has changed or not. If so, launches `composer install` command.

`bin/php-cqtools hooks:post-checkout   []`

`projectPath` argument sets path to be processed. Default value is current project base path.

#### post-merge hook

[](#post-merge-hook)

It has the same behaviour than post-checkout hook.

`bin/php-cqtools hooks:post-merge []`

### Uninstall Git Hooks

[](#uninstall-git-hooks)

Removes Git hooks from destination path. If backup files exist, they are restored.

`bin/php-cqtools hooks:uninstall`

### Fix Code Style

[](#fix-code-style)

Fixes code style of files according to defined code style.

It may fix all project files or only files to be commited. This second option is very convinient to fix errors detected in pre-commit hook.

`bin/php-cqtools code:fix-codestyle [--dry-run] [--excluded-paths=EXCLUDED_PATHS] [--only-commited-files] [--custom-ruleset=CUSTOM_RULESET] []`

`projectPath` argument sets path to be processed. Default value is current project base path.

`--dry-run` option shows diffs without applying any changes to files. `--excluded-paths` option sets some paths not to be processed. `--only-commited-files` option processes only files scheduled to be commited. `--custom-ruleset` option sets phpcs custom ruleset to be used instead of default one

### Validate Code

[](#validate-code)

It performs several tasks:

- PHP files:
    - Check for syntax errors
    - Check that forbidden functions (i.e., var\_dump(), empty()) are not commited
    - Check whether multibyte string functions are being used
    - Check that code complies defined code style recommendations (errors cannot be commited, warnings may be)
    - Check that variable usage is right (i.e., use undefined variables, parameters not used, etc.)
- JSON files:
    - Check for syntax errors
- Composer related files:
    - Check that composer.json is not commited without composer.lock (checked only with --only-commited-files modifier)

`bin/php-cqtools code:validate [--excluded-paths=EXCLUDED_PATHS] [--only-commited-files] [--custom-ruleset=CUSTOM_RULESET] []`

`projectPath` argument sets path to be processed. Default value is current project base path.

`--excluded-paths` option sets some paths not to be processed. `--only-commited-files` option processes only files scheduled to be commited. `--custom-ruleset` option sets phpcs custom ruleset to be used instead of default one

Show debug information
----------------------

[](#show-debug-information)

Shows debug information about:

- Validation/fix tools installed, such as phpcs, jsonlint, phpcbf
- Project basepath
- Git hooks path
- Git hooks source path
- Commited files
- Excluded paths
- Project files

`bin/php-cqtools debug:show [--show-full-paths] [
