wptechnix / coding-standard
The official PHP coding standard for WPTechnix projects.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:phpcodesniffer-standard
pkg:composer/wptechnix/coding-standard
Requires
- php: ^8.0
- slevomat/coding-standard: ^8.0
- squizlabs/php_codesniffer: ^3.7
README
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.
Core Philosophy
- 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.
Installation
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-installer
Verify Installation
After installation, you can verify that the WPTechnix standard is available by running:
./vendor/bin/phpcs -i
You should see WPTechnix listed among the installed coding standards.
Usage
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>
Running the Linter
You can now run PHP_CodeSniffer from the command line to check your code against the WPTechnix standard.
Check for Violations
To check for any coding standard violations, run:
./vendor/bin/phpcs
Automatically Fix Violations
To automatically fix the violations that can be fixed, run PHP Code Beautifier and Fixer (phpcbf):
./vendor/bin/phpcbf
Versioning
This project adheres to Semantic Versioning.
Contributing
Contributions are welcome! Please feel free to open an issue or submit a pull request for any improvements or bug fixes.
License
The WPTechnix Coding Standard is open-source software licensed under the MIT license.