PHPackages                             phpcsstandards/phpcsdevtools - 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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. phpcsstandards/phpcsdevtools

ActivePhpcodesniffer-standard[Debugging &amp; Profiling](/categories/debugging)

phpcsstandards/phpcsdevtools
============================

Tools for PHP\_CodeSniffer sniff developers.

1.2.3(11mo ago)16964.3k↓31.7%6[4 PRs](https://github.com/PHPCSStandards/PHPCSDevTools/pulls)20LGPL-3.0-or-laterPHPPHP &gt;=5.4CI passing

Since Feb 12Pushed 1mo ago5 watchersCompare

[ Source](https://github.com/PHPCSStandards/PHPCSDevTools)[ Packagist](https://packagist.org/packages/phpcsstandards/phpcsdevtools)[ Docs](https://phpcsstandards.github.io/PHPCSDevTools/)[ GitHub Sponsors](https://github.com/PHPCSStandards)[ GitHub Sponsors](https://github.com/jrfnl)[ RSS](/packages/phpcsstandards-phpcsdevtools/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (8)Dependencies (9)Versions (17)Used By (20)

PHPCSDevTools for developers of PHP\_CodeSniffer sniffs
=======================================================

[](#phpcsdevtools-for-developers-of-php_codesniffer-sniffs)

[![Latest Stable Version](https://camo.githubusercontent.com/9cb490e3f25dcfac128a4d3074446f770a72d7fd0f290b88f09cd0d077c42ebf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70687063737374616e64617264732f7068706373646576746f6f6c733f6c6162656c3d737461626c65)](https://packagist.org/packages/phpcsstandards/phpcsdevtools)[![Release Date of the Latest Version](https://camo.githubusercontent.com/9c10d0223afaaefee1721b8810754e3923ba028ec03a38adecfb70fac9a5fe92/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f50485043535374616e64617264732f5048504353446576546f6f6c732e7376673f6d61784167653d31383030)](https://github.com/PHPCSStandards/PHPCSDevTools/releases)[![Changelog](https://camo.githubusercontent.com/5269c9fe91c342e209e60bcf02857c66785373a7bca001a2655e0fa6c63403d9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f50485043535374616e64617264732f5048504353446576546f6f6c733f6c6162656c3d4368616e67656c6f6726736f72743d73656d766572)](https://github.com/PHPCSStandards/PHPCSDevTools/blob/stable/CHANGELOG.md)🚧 [![Latest Unstable Version](https://camo.githubusercontent.com/36aaf6b5002a9c809356c5cef488554c466dd55b6d898f792039151ad2f2ee3c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f756e737461626c652d6465762d2d646576656c6f702d6536383731382e7376673f6d61784167653d32343139323030)](https://packagist.org/packages/phpcsstandards/phpcsdevtools#dev-develop)[![Last Commit to Unstable](https://camo.githubusercontent.com/02aacb63f6e7431915f6464a61eef486e9c0b4a27a88b0275154ff7a1333ba54/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f50485043535374616e64617264732f5048504353446576546f6f6c732f646576656c6f702e737667)](https://github.com/PHPCSStandards/PHPCSDevTools/commits/develop)

[![Minimum PHP Version](https://camo.githubusercontent.com/c6a4e6fc68010e7f5e5a4e6ce5430849b511034edc73f97d68f987e02ed388cd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f70687063737374616e64617264732f7068706373646576746f6f6c732f7068702e737667)](https://packagist.org/packages/phpcsstandards/phpcsdevtools)[![Build Status CS](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/cs.yml/badge.svg)](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/cs.yml)[![Build Status Test](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/test.yml/badge.svg)](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/test.yml)[![Tested on PHP 5.4 to nightly](https://camo.githubusercontent.com/b679ce5e8a3fccfe4aa9140f29ed102553d80a8586f81f73e749feda03ffb0bb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7465737465642532306f6e2d504850253230352e34253230253743253230352e35253230253743253230352e36253230253743253230372e30253230253743253230372e31253230253743253230372e32253230253743253230372e33253230253743253230372e34253230253743253230382e30253230253743253230382e31253230253743253230382e32253230253743253230382e33253230253743253230382e34253230253743253230382e352532302537432532306e696768746c792d627269676874677265656e2e7376673f6d61784167653d32343139323030)](https://github.com/PHPCSStandards/PHPCSDevTools/actions?query=workflow%3ATest)

[![License: LGPLv3](https://camo.githubusercontent.com/2add0cd7279bede301c48bbb1bb6d1fb7589d61f01672c2d74326fa56b5be075/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f50485043535374616e64617264732f5048504353446576546f6f6c73)](https://github.com/PHPCSStandards/PHPCSDevTools/blob/stable/LICENSE)[![Awesome](https://camo.githubusercontent.com/e3718252e9cb9d236e13f891808bc5861337368a897129bbdcb34f1c89ce1d77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617765736f6d652533462d796573212d627269676874677265656e2e737667)](https://camo.githubusercontent.com/e3718252e9cb9d236e13f891808bc5861337368a897129bbdcb34f1c89ce1d77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617765736f6d652533462d796573212d627269676874677265656e2e737667)

This is a set of tools to assist developers of sniffs for [PHP CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer).

- [Installation](#installation)
    - [Composer Project-based Installation](#composer-project-based-installation)
    - [Composer Global Installation](#composer-global-installation)
    - [Stand-alone Installation](#stand-alone-installation)
- [Features](#features)
    - [Checking whether all sniffs in a PHPCS standard are feature complete](#checking-whether-all-sniffs-in-a-phpcs-standard-are-feature-complete)
    - [Sniff Debugging](#sniff-debugging)
    - [Documentation XSD Validation](#documentation-xsd-validation)
- [Contributing](#contributing)
- [License](#license)

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

[](#installation)

### Composer Project-based Installation

[](#composer-project-based-installation)

Run the following from the root of your project:

```
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --dev phpcsstandards/phpcsdevtools:^1.0
```

### Composer Global Installation

[](#composer-global-installation)

If you work on several different sniff repos, you may want to install this toolset globally:

```
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --dev phpcsstandards/phpcsdevtools:^1.0
```

Composer will automatically install dependencies and register the PHPCSDebug standard with PHP\_CodeSniffer using the [Composer PHPCS plugin](https://github.com/PHPCSStandards/composer-installer).

### Stand-alone Installation

[](#stand-alone-installation)

- Install [PHP CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) via [your preferred method](https://github.com/PHPCSStandards/PHP_CodeSniffer#installation).
- Register the path to PHPCS in your system `$PATH` environment variable to make the `phpcs` command available from anywhere in your file system.
- Download the [latest PHPCSDevTools release](https://github.com/PHPCSStandards/PHPCSDevTools/releases) and unzip/untar it into an arbitrary directory. You can also choose to clone this repository using git.
- Add the path to the directory in which you placed your copy of the PHPCSDevTools repo to the PHP CodeSniffer configuration using the below command: ```
    phpcs --config-set installed_paths /path/to/PHPCSDevTools
    ```

    ⚠️ **Warning**: The `installed_paths` command overwrites any previously set `installed_paths`. If you have previously set `installed_paths` for other external standards, run `phpcs --config-show` first and then run the `installed_paths` command with all the paths you need separated by commas, i.e.: ```
    phpcs --config-set installed_paths /path/1,/path/2,/path/3
    ```

Features
--------

[](#features)

### Checking whether all sniffs in a PHPCS standard are feature complete

[](#checking-whether-all-sniffs-in-a-phpcs-standard-are-feature-complete)

You can now check whether each and every sniff in your standard is accompanied by a documentation XML file (warning) as well as unit test files (error). The tool will also verify that there are no documentation or test files in your standard which are not associated with a sniff ("orphaned" files).

To use the tool, run it from the root of your standards repo like so:

```
# When installed as a project dependency:
vendor/bin/phpcs-check-feature-completeness

# When installed globally with Composer:
phpcs-check-feature-completeness

# When installed as a git clone or otherwise:
php -f "path/to/PHPCSDevTools/bin/phpcs-check-feature-completeness"
```

If all is good, you will see the following messages:

```
All # sniffs are accompanied by unit tests and documentation.
No orphaned documentation or test files found.

```

If there are files missing, you will see errors/warnings for each missing file, like so:

```
WARNING: Documentation missing for path/to/project/StandardName/Sniffs/Category/SniffNameSniff.php.
ERROR: Unit tests missing for path/to/project/StandardName/Sniffs/Category/SniffNameSniff.php.

```

If orphaned files are found you will receive a warning for each orphaned file found, like so:

```
WARNING: Orphaned documentation file found path/to/project/StandardName/Docs/Category/NonExistantSniffStandard.xml.
WARNING: Orphaned test file found path/to/project/StandardName/Test/Category/NonExistantSniffUnitTest.inc.

```

For the fastest results, it is recommended to pass the name of the subdirectory where your standard is located to the script, like so:

```
phpcs-check-feature-completeness ./StandardName
```

#### Options

[](#options)

```
directories      One or more specific directories to examine.
                      Defaults to the directory from which the script is run.
-q, --quiet           Turn off warnings for missing documentation and orphaned
                      files.
                      Equivalent to running with "--no-docs --no-orphans".
--exclude= Comma-delimited list of (relative) directories to
                      exclude from the scan.
                      Defaults to excluding the /vendor/ directory.
--no-docs             Disable missing documentation check.
--no-orphans          Disable orphaned files check.
--no-progress         Disable progress in console output.
--colors              Enable colors in console output.
                      (disables auto detection of color support).
--no-colors           Disable colors in console output.
-v                    Verbose mode.
-h, --help            Print this help.
-V, --version         Display the current version of this script.

```

### Sniff Debugging

[](#sniff-debugging)

Once this project is installed, you will see a new `PHPCSDebug` ruleset in the list of installed standards when you run `phpcs -i`.

For now, this standard only contains one sniff: `PHPCSDebug.Debug.TokenList`. This sniff will display compact, but detailed information about the tokens found in a (test case) file.

This sniff is compatible with PHPCS 3.1.0+.

Typical usage:

- Set up a test case file for a new sniff you intend to write.
- Run PHPCS over the test case file using this standard to see a list of the tokens found in the file:

```
phpcs ./SniffNameUnitTest.inc --standard=PHPCSDebug
```

- Or use it together with the new sniff you are developing:

```
phpcs ./SniffNameUnitTest.inc --standard=YourStandard,PHPCSDebug --sniffs=YourStandard.Category.NewSniffName,PHPCSDebug.Debug.TokenList
```

The output will look something along the lines of:

```
Ptr | Ln | Col  | Cond | ( #) | Token Type                 | [len]: Content
-------------------------------------------------------------------------
  0 | L1 | C  1 | CC 0 | ( 0) | T_OPEN_TAG                 | [  5]:
