This package provides the official PHP coding standard for WPTechnix projects.
It is built upon the widely-accepted PSR-12 standard and is enhanced with a comprehensive, modern ruleset from Slevomat Coding Standard. The goal is to enforce a strict, consistent, and modern coding style across all projects, promoting readability and maintainability.
- PSR-12 Compliant: Strictly follows PSR-12 as a baseline, ensuring broad interoperability.
- Modern PHP: Leverages Slevomat Coding Standard for modern PHP features, strict type hinting, and dead code detection.
- Opinionated for Consistency: Provides a consistent set of opinionated rules (e.g., requiring trailing commas in multi-line arrays/arguments, disallowing Yoda conditions) to eliminate style debates.
- Easy to Use: Packaged for easy installation and integration into any project via Composer.
You can install this coding standard as a development dependency in your project using Composer.
The dealerdirect/phpcodesniffer-composer-installer plugin is also required to automatically register the WPTechnix standard with PHP_CodeSniffer.
composer require --dev wptechnix/coding-standard dealerdirect/phpcodesniffer-composer-installerAfter installation, you can verify that the WPTechnix standard is available by running:
./vendor/bin/phpcs -iYou should see WPTechnix listed among the installed coding standards.
Once the package is installed, create a phpcs.xml.dist file in the root of your project to configure PHP_CodeSniffer.
This is the recommended base configuration:
<?xml version="1.0"?>
<ruleset name="MyProject">
<description>The coding standard for MyProject.</description>
<!--
|--------------------------------------------------------------------------
| Scan these paths
|--------------------------------------------------------------------------
-->
<file>src</file>
<file>tests</file>
<!-- You can add more <file> or <directory> tags here -->
<!--
|--------------------------------------------------------------------------
| Exclude these paths
|--------------------------------------------------------------------------
-->
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<!--
|--------------------------------------------------------------------------
| Use the WPTechnix standard
|--------------------------------------------------------------------------
-->
<rule ref="WPTechnix"/>
</ruleset>You can now run PHP_CodeSniffer from the command line to check your code against the WPTechnix standard.
To check for any coding standard violations, run:
./vendor/bin/phpcsTo automatically fix the violations that can be fixed, run PHP Code Beautifier and Fixer (phpcbf):
./vendor/bin/phpcbfThis project adheres to Semantic Versioning.
Contributions are welcome! Please feel free to open an issue or submit a pull request for any improvements or bug fixes.
The WPTechnix Coding Standard is open-source software licensed under the MIT license.