PHPackages                             chancedigital/wp-coding-standards - 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. chancedigital/wp-coding-standards

AbandonedArchivedPhpcodesniffer-standard[Utility &amp; Helpers](/categories/utility)

chancedigital/wp-coding-standards
=================================

Chance Digital coding standards

v0.4.0(7y ago)179GPL-3.0-or-laterPHPPHP &gt;=7.1

Since Aug 9Pushed 7y ago1 watchersCompare

[ Source](https://github.com/chancedigital/wp-coding-standards)[ Packagist](https://packagist.org/packages/chancedigital/wp-coding-standards)[ RSS](/packages/chancedigital-wp-coding-standards/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (5)Versions (12)Used By (0)

Chance Digital WordPress Coding Standards
=========================================

[](#chance-digital-wordpress-coding-standards)

[![](https://camo.githubusercontent.com/9ded712d816310894ef7a5cf5106e5387afe7b2fdddc95280577b0aff7398f25/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368616e63656469676974616c2f77702d636f64696e672d7374616e64617264732e737667)](https://packagist.org/packages/chancedigital/wp-coding-standards)[![Build Status](https://camo.githubusercontent.com/d8e802ff89a93292a509bd16cf701f162147901366b065887affa58a1dcdd31a/68747470733a2f2f7472617669732d63692e6f72672f6368616e63656469676974616c2f77702d636f64696e672d7374616e64617264732e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/d8e802ff89a93292a509bd16cf701f162147901366b065887affa58a1dcdd31a/68747470733a2f2f7472617669732d63692e6f72672f6368616e63656469676974616c2f77702d636f64696e672d7374616e64617264732e7376673f6272616e63683d6d6173746572)

This is a codified version of the Chance Digital PHP CodeSniffer rules. It began as a fork of the the [Human Made](https://github.com/chancedigital/wp-coding-standards) coding standards.

Setup
-----

[](#setup)

1. `composer require --dev chancedigital/wp-coding-standards`
2. Run the following command to run the standards checks:

```
vendor/bin/phpcs --standard=vendor/chancedigital/wp-coding-standards .

```

The final `.` here specifies the files you want to test; this is typically the current directory (`.`), but you can also selectively check files or directories by specifying them instead.

You can add this to your Travis YAML file as a test:

```
script:
	- phpunit
	- vendor/bin/phpcs --standard=vendor/chancedigital/wp-coding-standards .
```

### Excluding Files

[](#excluding-files)

This standard includes special support for a `.phpcsignore` file (in the future, this should be [built into phpcs itself](https://github.com/squizlabs/PHP_CodeSniffer/issues/1884)). Simply place a `.phpcsignore` file in your root directory (wherever you're going to run `phpcs` from).

The format of this file is similar to `.gitignore` and similar files: one pattern per line, comment lines should start with a `#`, and whitespace-only lines are ignored:

```
# Exclude our tests directory.
tests/

# Exclude any file ending with ".inc"
*\.inc

```

Note that the patterns should match [the PHP\_CodeSniffer style](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders): `*` is translated to `.*` for convenience, but all other characters work like a regular expression.

Patterns are relative to the directory that the `.phpcsignore` file lives in. On load, they are translated to absolute patterns: e.g. `*/tests/*` in `/your/dir/.phpcsignore` will become `/your/dir/.*/tests/.*` as a regular expression. **This differs from the regular PHP\_CodeSniffer practice.**

### Advanced/Extending

[](#advancedextending)

If you want to add further rules (such as WordPress.com VIP-specific rules), you can create your own custom standard file (e.g. `phpcs.ruleset.xml`):

```

```

You can then reference this file when running phpcs:

```
vendor/bin/phpcs --standard=phpcs.ruleset.xml .

```

#### Excluding/Disabling Checks

[](#excludingdisabling-checks)

You can also customise the rule to exclude elements if they aren't applicable to the project:

```

```

Rules can also be disabled inline. [phpcs rules can be disabled](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file) with a `// @codingStandardsIgnoreLine` comment.

To find out what these codes are, specify `-s` when running `phpcs`, and the code will be output as well. You can specify a full code, or a partial one to disable groups of errors.

Included Checks
---------------

[](#included-checks)

The phpcs standard is based upon the `WordPress-Extra` standard from [WordPress Coding Standards](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards), with [customisation and additions](ChanceDigital/ruleset.xml) to match our style guide.

Testing
-------

[](#testing)

### Running tests

[](#running-tests)

To run the tests locally, you'll need the source version of PHP CodeSniffer.

If you haven't already installed your Composer dependencies:

```
composer install --prefer-source
```

If you already have, and need to convert the phpcs directory to a source version:

```
rm -r vendor/squizlabs/php_codesniffer
composer install --prefer-source
composer dump-autoload
```

### Writing sniff tests

[](#writing-sniff-tests)

To add tests you should mirror the directory structure of the sniffs. For example a test for `ChanceDigital/Sniffs/Layout/OrderSniff.php` would require the following files:

```
ChanceDigital/Tests/Layout/OrderUnitTest.php # Unit test code
ChanceDigital/Tests/Layout/OrderUnitTest.inc # Code to be tested

```

Effectively you are replacing the suffix `Sniff.php` with `UnitTest.php`.

A basic unit test class looks like the following:

```
