PHPackages                             manoj-malviya/php\_codesniffer - 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. manoj-malviya/php\_codesniffer

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

manoj-malviya/php\_codesniffer
==============================

PHP\_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.

2.4.0(10y ago)0202BSD-3-ClausePHPPHP &gt;=5.1.2

Since Nov 9Pushed 9y ago1 watchersCompare

[ Source](https://github.com/manoj-malviya/PHP_CodeSniffer)[ Packagist](https://packagist.org/packages/manoj-malviya/php_codesniffer)[ Docs](http://www.squizlabs.com/php-codesniffer)[ RSS](/packages/manoj-malviya-php-codesniffer/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (36)Used By (0)

First, we need a development dependency specified to install phpcs. It looks something like this:

```
{
    "require-dev": {
        "manoj-malviya/php_codesniffer": "^2.4"
    }
}

```

Install Scripts
---------------

[](#install-scripts)

Composer has a handy schema entry called scripts. It supports a script hook post-install-cmd. We will use this to install a git pre-commit hook. Adding to our example above:

```
{
    "require-dev": [
        "manoj-malviya/php_codesniffer": "^2.4"
    ],
    "scripts": {
        "post-install-cmd": [
            "bash contrib/setup.sh"
        ]
    }
}

```

This will run a bash script called setup.sh when the command composer install is run.

Setup the Git Pre-commit Hook
-----------------------------

[](#setup-the-git-pre-commit-hook)

In our setup.sh, we will need to copy a pre-commit script into the .git/hooks directory:

```
#!/bin/sh

cp contrib/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

```

This will copy our pre-commit script from the contrib directory to the hooks section of the special git directory and make it executable.

Create the Pre-commit Hook
--------------------------

[](#create-the-pre-commit-hook)

Whenever a contributing developer attempts to commit their code, it will run our pre-commit script. Now all we need to do is run the code sniffer rules on relavent files specific to this commit:

```
#!/bin/sh

PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`

# Determine if a file list is passed
if [ "$#" -eq 1 ]
then
    oIFS=$IFS
    IFS='
    '
    SFILES="$1"
    IFS=$oIFS
fi
SFILES=${SFILES:-$STAGED_FILES_CMD}

echo "Checking PHP Lint..."
for FILE in $SFILES
do
    php -l -d display_errors=0 $PROJECT/$FILE
    if [ $? != 0 ]
    then
        echo "Fix the error before commit."
        exit 1
    fi
    FILES="$FILES $PROJECT/$FILE"
done

if [ "$FILES" != "" ]
then
    echo "Running Code Sniffer..."
    ./vendor/bin/phpcs --standard=PSR1 --encoding=utf-8 -n -p $FILES
    if [ $? != 0 ]
    then
        echo "Fix the error before commit."
        exit 1
    fi
fi

exit $?

```

This script will get the staged files of the commit, run a php lint check (always nice), and apply the code sniffer rules to the staged files.

If there is a code standards violation, the phpcs process will return a non-zero exit status which will tell git to abort the commit.

Bringing it all together
------------------------

[](#bringing-it-all-together)

With all of these things in place, the workflow is as follows:

Developer runs composer install. PHP Code Sniffer is installed via a dev dependency. The post-install command automatically copies the pre-commit hook into the developer’s local git hooks. When the developer commits code, the pre-commit hook fires and checks the staged files for coding standards violations and lint checks. This is a relatively simple setup that can save pull request code reviews a significant amount of time preventing back-and-forth on simple things such as mixed tabs/spaces, bracket placement, etc.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 94.6% 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 ~32 days

Recently: every ~53 days

Total

35

Last Release

3861d ago

Major Versions

1.5.3 → 2.0.0a22014-05-01

1.5.4 → 2.0.0RC12014-08-06

1.5.5 → 2.0.0RC22014-09-25

1.5.x-dev → 2.0.02014-12-05

2.4.0 → 3.0.x-dev2015-11-27

PHP version history (2 changes)1.4.2PHP &gt;=5.1.2

3.0.x-devPHP &gt;=5.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2450823?v=4)[Manoj](/maintainers/manoj-malviya)[@manoj-malviya](https://github.com/manoj-malviya)

---

Top Contributors

[![gsherwood](https://avatars.githubusercontent.com/u/185976?v=4)](https://github.com/gsherwood "gsherwood (3288 commits)")[![klausi](https://avatars.githubusercontent.com/u/213229?v=4)](https://github.com/klausi "klausi (21 commits)")[![andygrunwald](https://avatars.githubusercontent.com/u/320064?v=4)](https://github.com/andygrunwald "andygrunwald (18 commits)")[![jrfnl](https://avatars.githubusercontent.com/u/663378?v=4)](https://github.com/jrfnl "jrfnl (15 commits)")[![photodude](https://avatars.githubusercontent.com/u/10253980?v=4)](https://github.com/photodude "photodude (13 commits)")[![manoj-girnar](https://avatars.githubusercontent.com/u/239952487?v=4)](https://github.com/manoj-girnar "manoj-girnar (11 commits)")[![sebastianbergmann](https://avatars.githubusercontent.com/u/25218?v=4)](https://github.com/sebastianbergmann "sebastianbergmann (9 commits)")[![kukulich](https://avatars.githubusercontent.com/u/260445?v=4)](https://github.com/kukulich "kukulich (8 commits)")[![wimg](https://avatars.githubusercontent.com/u/313511?v=4)](https://github.com/wimg "wimg (7 commits)")[![blerou](https://avatars.githubusercontent.com/u/52151?v=4)](https://github.com/blerou "blerou (6 commits)")[![aboks](https://avatars.githubusercontent.com/u/815524?v=4)](https://github.com/aboks "aboks (6 commits)")[![kdebisschop](https://avatars.githubusercontent.com/u/1213025?v=4)](https://github.com/kdebisschop "kdebisschop (6 commits)")[![pfrenssen](https://avatars.githubusercontent.com/u/442924?v=4)](https://github.com/pfrenssen "pfrenssen (5 commits)")[![deviantintegral](https://avatars.githubusercontent.com/u/255023?v=4)](https://github.com/deviantintegral "deviantintegral (5 commits)")[![westonruter](https://avatars.githubusercontent.com/u/134745?v=4)](https://github.com/westonruter "westonruter (5 commits)")[![ktomk](https://avatars.githubusercontent.com/u/352517?v=4)](https://github.com/ktomk "ktomk (4 commits)")[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (4 commits)")[![robocoder](https://avatars.githubusercontent.com/u/922051?v=4)](https://github.com/robocoder "robocoder (4 commits)")[![andrei-propertyguru](https://avatars.githubusercontent.com/u/12060611?v=4)](https://github.com/andrei-propertyguru "andrei-propertyguru (4 commits)")[![illusori](https://avatars.githubusercontent.com/u/360670?v=4)](https://github.com/illusori "illusori (4 commits)")

---

Tags

standardsphpcs

### Embed Badge

![Health badge](/badges/manoj-malviya-php-codesniffer/health.svg)

```
[![Health](https://phpackages.com/badges/manoj-malviya-php-codesniffer/health.svg)](https://phpackages.com/packages/manoj-malviya-php-codesniffer)
```

###  Alternatives

[wp-coding-standards/wpcs

PHP\_CodeSniffer rules (sniffs) to enforce WordPress coding conventions

2.8k45.9M2.0k](/packages/wp-coding-standards-wpcs)[dealerdirect/phpcodesniffer-composer-installer

PHP\_CodeSniffer Standards Composer Installer Plugin

598170.6M2.2k](/packages/dealerdirect-phpcodesniffer-composer-installer)[phpcompatibility/phpcompatibility-wp

A ruleset for PHP\_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.

22132.9M706](/packages/phpcompatibility-phpcompatibility-wp)[phpcsstandards/phpcsextra

A collection of sniffs and standards for use with PHP\_CodeSniffer.

10327.7M59](/packages/phpcsstandards-phpcsextra)[acquia/coding-standards

PHP\_CodeSniffer rules (sniffs) for Acquia coding standards

204.9M33](/packages/acquia-coding-standards)[rarst/phpcs-cognitive-complexity

Cognitive complexity implementation for PHP\_CodeSniffer

28126.4k2](/packages/rarst-phpcs-cognitive-complexity)

PHPackages © 2026

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