This package contains the building techniques (=code style) used in WordPress projects.
This package provides a ruleset for PHP_CodeSniffer that extends the ruleset for Timber, which is composed of the WordPress coding standard with some added exceptions. The deviations from the WordPress coding standard are:
- Class filenames should adhere to PSR-4.
- Classnames should use StudlyCaps.
- Lines should be 100 chars long maximum (triggers warning),
- Lines should in no case exceed 120 characters (triggers error).
- Allow
/
as word delimiter in hook names. - Allow short array syntax (
[]
).
Install Composer to add this package to your project.
Install the package using composer:
composer require --dev achttienvijftien/building-techniques
After the installation, the phpcs
and phpcbf
scripts are available in the vendor/bin
folder.
We recommend also installing phpcodesniffer-composer-installer to automatically register the coding standard with PHP_CodeSniffer:
composer require --dev dealerdirect/phpcodesniffer-composer-installer
Now, the coding standard should be available for use when running phpcs
. You can check the installed coding standards by running:
./vendor/bin/phpcs -i
The list should contain 1815BuildingTechniques
.
To run PHP_CodeSniffer with the appropriate coding standard:
./vendor/bin/phpcs --standard=1815BuildingTechniques path/to/file-or-directory
To fix code style violations that can be corrected automatically:
./vendor/bin/phpcbf --standard=1815BuildingTechniques path/to/file-or-directory
Composer scripts for phpcs
and phpcbf
can be added to composer.json for convenience.
{
"scripts": {
"format": "phpcbf --standard=1815BuildingTechniques --report-summary --report-source",
"lint": "phpcs --standard=1815BuildingTechniques"
}
}
Please refer to the Wiki for guides on integrating PHP_Codesniffer with IDEs like PhpStorm.