Yoast Code Style
PHP
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Yoast
.gitattributes
.gitignore
.phpcs.xml.dist
.travis.yml
LICENSE
README.md
composer.json
phpmd.xml
phpunit.xml.dist

README.md

Yoast Coding Standards

Yoast Coding Standards (YoastCS) is a project with rulesets for code style and quality tools to be used in Yoast projects.

Installation

Standalone

Standards are provided as Composer package and can be installed with:

composer create-project yoast/yoastcs:dev-master

Composer will automatically install dependencies, register standards paths, and set default PHP Code Sniffer standard to Yoast.

As dependency

To include standards as part of a project require them as development dependencies:

composer require yoast/yoastcs:dev-master --dev

Note that Composer won't run configuration scripts in this scenario and the root project needs to take care of it.

PHP Code Sniffer

Set of PHP Code Sniffer rules.

Based on WordPress Coding Standards project, implementing official WordPress PHP Coding Standards.

Severity levels:

  • error level issues are considered mandatory to fix in Yoast projects and enforced in continuous integration
  • warning level issues are considered recommended to fix

Command line

"vendor/bin/phpcs" --extensions=php /path/to/folder/

PhpStorm

Refer to Using PHP Code Sniffer Tool in PhpStorm documentation.

After installation Yoast standard will be available as a choice in PHP Code Sniffer Validation inspection.

PHP Mess Detector

Set of PHP Mess Detector rules.

Original ruleset, produced for Yoast projects, taking under consideration typical WordPress practices and current state of code base.

All issues are considered informational for code development and maintenance.

Command line

"vendor/bin/phpmd" /path/to/folder/ text phpmd.xml

PhpStorm

Refer to Using PHP Mess Detector in PhpStorm documentation.

After installation add phpmd.xml file from project as custom ruleset in PHP Mess Detector Validation inspection settings.