pragmaticweb/php-coding-standards

Style guide for writing consistent PHP code for WordPress projects.

Installs: 575

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 4

Forks: 0

Open Issues: 1

Type:phpcodesniffer-standard

0.0.1 2020-04-08 13:23 UTC

This package is auto-updated.

Last update: 2024-10-08 23:55:41 UTC


README

A project by Pragmatic.

Version 0.0.1 License: GPL 3.0 only

Style guide for writing consistent PHP code for WordPress projects.

Installation

Our PHP coding standards are enforced via php_codesniffer and can be installed using the PHP package manager composer.

$ composer require pragmaticweb/php-coding-standards --dev

Usage

Basic usage

When installed using composer, our coding standards are ready to be used by running:

$ vendor/bin/phpcs --standard="Pragmatic" ./my-plugin ./my-file.php

Configuration file

In order to make it easier to modify our standards to better fit your project, you can create a phpcs.xml.dist file which could contain something like this:

	<?xml version="1.0"?>
	<ruleset name="MyProjectCodingStandard">

		<description>My Project coding standard.</description>

		<file>./my-plugin</file>
		<file>./my-file.php</file>

		<config name="text_domain" value="my-project"/>

		<rule ref="Pragmatic" />

	</ruleset>

Using a config file, allows you to only run vendor/bin/phpcs to check the code style.

For more advanced usage, please refer to the PHP Codesniffer docs.

Included rules

WordPress Coding Standard

We're pretty much using WordPress coding standards at this point with some exclusions (see ruleset.xml).

See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.

PHPcompatibilityWP

It allows to analyse code for compatibility with higher and lower versions of PHP. The default target version is PHP 7.0+.

Target version can be changed via custom phpcs.xml.

See https://github.com/PHPCompatibility/PHPCompatibilityWP

PSR2

See https://github.com/php-fig-rectified/psr2r-sniffer

Contributing

The Pragmatic coding standards is what enables our engineers to work together and write consistent PHP code.

Pull requests are welcome but will need to be reviewed by the members of our team.

Please open an issue first to discuss what you would like to change and, if our team agrees with it, then we could look into merging them.