PHPackages                             26b/php-pre-commit - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. 26b/php-pre-commit

ActiveScripts[Utility &amp; Helpers](/categories/utility)

26b/php-pre-commit
==================

Pre-commit git hook for enforcing php standards.

0.2.1(3y ago)819.9k↓36.6%1[5 issues](https://github.com/26B/php-pre-commit/issues)[1 PRs](https://github.com/26B/php-pre-commit/pulls)2MITShell

Since Mar 29Pushed 1y ago2 watchersCompare

[ Source](https://github.com/26B/php-pre-commit)[ Packagist](https://packagist.org/packages/26b/php-pre-commit)[ RSS](/packages/26b-php-pre-commit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)DependenciesVersions (10)Used By (2)

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:

```
composer require --dev 26b/php-pre-commit
```

In order for the hooks to be moved into the `.git/hooks` folder add the following to the project's `composer.json`:

```
"scripts": {
    "post-install-cmd": "php-pre-commit",
    "post-update-cmd": "php-pre-commit"
}
```

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`. Local `phpcs` takes precedence when the pre-commit runs. You can require them in the following way:

```
# Local
composer require --dev squizlabs/php_codesniffer
# Or global
composer global require squizlabs/php_codesniffer
```

Use Cases
---------

[](#use-cases)

### Local PHPCS

[](#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

[](#wordpress)

#### Setup WordPress Standards (Manual)

[](#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:

```
git clone git@github.com:WordPress/WordPress-Coding-Standards.git --depth=1 --branch 3.1.0 ~/wpcs
```

Secondly, we need to tell `phpcs` where these standards are.

```
phpcs --config-set installed_paths /full/path/to/wpcs
```

Finally, in order to check that `phpcs` recognises and uses the standards, we can check it like this:

```
$ phpcs -i
The installed coding standards are PEAR, Zend, PSR2, Squiz, PSR1, PSR12, WordPress, WordPress-Extra, WordPress-Docs and WordPress-Core
```

The output should resemble this, with the WordPress standards. If they are missing, `phpcs` might not be recognising the path. Check its paths via:

```
$ phpcs --config-show
Using config file: /full/path/to/global/composer/vendor/squizlabs/php_codesniffer/CodeSniffer.conf

default_standard: WordPress-Extra
installed_paths:  /full/path/to/wpcs
```

#### Alternative (Automatic)

[](#alternative-automatic)

As an alternative you can use [PHP\_CodeSniffer Standards Composer Installer Plugin](https://github.com/Dealerdirect/phpcodesniffer-composer-installer) 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:

```
composer require --dev dealerdirect/phpcodesniffer-composer-installer wp-coding-standards/wpcs
```

Or add them to the composer.json:

```
"require-dev": {
    "dealerdirect/phpcodesniffer-composer-installer": "*",
    "wp-coding-standards/wpcs": "*"
}
```

And add scripts, to configure `phpcs` correctly upon `composer install`, like this:

```
"scripts": {
    "install-codestandards": [
        "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"
    ],
    "post-install-cmd": [
        "php-pre-commit",
        "@install-codestandards"
    ]
}
```

### Laravel

[](#laravel)

#### Automatic Setup

[](#automatic-setup)

Here, you can also use [PHP\_CodeSniffer Standards Composer Installer Plugin](https://github.com/Dealerdirect/phpcodesniffer-composer-installer) 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](https://github.com/emielmolenaar/phpcs-laravel) package and we are done:

```
composer require --dev emielmolenaar/phpcs-laravel
```

Finally, add the same scripts to configure `phpcs` correctly upon `composer install`:

```
"scripts": {
    "install-codestandards": [
        "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"
    ],
    "post-install-cmd": [
        "php-pre-commit",
        "@install-codestandards"
    ]
}
```

#### Manual Setup

[](#manual-setup)

A Laravel's coding standard repository that is being updated consistently is [emielmolenaar/phpcs-laravel](https://github.com/emielmolenaar/phpcs-laravel). We will now proceed to the configuration (very similar to the *WordPress configuration*). First clone [emielmolenaar/phpcs-laravel](https://github.com/emielmolenaar/phpcs-laravel) repository:

```
git clone https://github.com/emielmolenaar/phpcs-laravel.git --branch 2.0
```

Again, tell to `phpcs` where the standards are.

```
phpcs --config-set installed_paths /full/path/to/phpcs-laravel
```

Once more, make sure `phpcs` recognises and uses the installed standards:

```
$ phpcs -i
The installed coding standards are PEAR, Zend, PSR2, MySource, Squiz, PSR1, PSR12 and phpcs-laravel
```

The `--config-show` will give the following output:

```
$ phpcs --config-show
Using config file: /full/path/to/composer/vendor/squizlabs/php_codesniffer/CodeSniffer.conf

installed_paths: /full/path/to/phpcs-laravel
```

Troubleshooting
---------------

[](#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 contains `composer.json`.)

    ```
    chmod +x vendor/bin/php-pre-commit
    ```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 51.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~71 days

Recently: every ~121 days

Total

8

Last Release

1376d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc0c08557826dcb44e27c826ddf975f9a5edc020e76eda58e9f4a720b4c407c3?d=identicon)[xipasduarte](/maintainers/xipasduarte)

![](https://www.gravatar.com/avatar/bf28212c731e8709d4dec48e4a3f4afb623242afd6cff7b03151039158a28122?d=identicon)[goncaloasimoes](/maintainers/goncaloasimoes)

---

Top Contributors

[![azathcat](https://avatars.githubusercontent.com/u/32324608?v=4)](https://github.com/azathcat "azathcat (24 commits)")[![xipasduarte](https://avatars.githubusercontent.com/u/123991?v=4)](https://github.com/xipasduarte "xipasduarte (19 commits)")[![gh0stwin](https://avatars.githubusercontent.com/u/30176075?v=4)](https://github.com/gh0stwin "gh0stwin (4 commits)")

---

Tags

gitlintingphpphpcsstandards

### Embed Badge

![Health badge](/badges/26b-php-pre-commit/health.svg)

```
[![Health](https://phpackages.com/badges/26b-php-pre-commit/health.svg)](https://phpackages.com/packages/26b-php-pre-commit)
```

###  Alternatives

[wisembly/totem

Changeset calculator between data states

7735.9k](/packages/wisembly-totem)[kjdev/brotli

A compression/decompression with Brotli

1951.1k](/packages/kjdev-brotli)[jeffreyvanrossum/wp-settings

Handy wrapper to make creating WordPress settings pages a breeze.

902.6k1](/packages/jeffreyvanrossum-wp-settings)[daandelange/simplestats

Very minimal visitor analytics for your kirby website.

711.8k](/packages/daandelange-simplestats)[ffi/var-dumper

List of symfony/var-dumper casters with FFI support

2010.7k4](/packages/ffi-var-dumper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
