Skip to content

WPTechnix Coding Standard - This standard is built upon PSR-12, enhanced with the comprehensive Slevomat Coding Standard.

License

Notifications You must be signed in to change notification settings

WPTechnix/wptechnix-coding-standard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPTechnix Coding Standard

Latest Stable Version License

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.

About

WPTechnix Coding Standard - This standard is built upon PSR-12, enhanced with the comprehensive Slevomat Coding Standard.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published