Skip to content

Style guide for writing consistent PHP code for WordPress projects.

License

Notifications You must be signed in to change notification settings

PragmaticWebLimited/php-coding-standards

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pragmatic PHP Coding Standards

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.

About

Style guide for writing consistent PHP code for WordPress projects.

Resources

License

Stars

Watchers

Forks

Packages

No packages published