A comprehensive PHP_CodeSniffer ruleset that extends WordPress Coding Standards with ByteEver-specific conventions for modern PHP development.
- ๐ฏ WordPress-First: Built on top of WordPress Coding Standards (WPCS) 3.1.0
- ๐ PHP Compatibility: Supports PHP 7.4 - 8.5 with PHPCompatibility checks
- โก Performance: Configured for parallel processing with 8 threads
- ๐จ Sensible Defaults: Pre-configured with practical exclusions for real-world development
- ๐ Tab Indentation: Enforces consistent tab-based indentation
- ๐ง Customizable: Easy to extend and override rules per project
- WordPress: Complete WordPress coding standards
- WordPress-Extra: Additional WordPress-specific rules
- WordPress-Docs: Documentation standards
- PHPCompatibilityWP: WordPress-specific PHP compatibility checks
- Tab-based indentation (1 tab = 1 indent level)
- Space inside parentheses for better readability
- Relaxed file naming requirements
- Allowance for shorthand array syntax
[] - Sensible exclusions for database queries and nonce verification
- Comment and doc comment tokens ignored in indentation checks
Install via Composer:
composer require byteever/byteever-sniffsThe package will automatically:
- Install PHP_CodeSniffer and required dependencies
- Register the
ByteEver-Defaultstandard - Set it as the default standard for your project
vendor/bin/phpcs .composer run phpcsvendor/bin/phpcs --standard=ByteEver-Default path/to/filesFor better IDE integration, create a .phpcs.xml.dist file in your project root:
<?xml version="1.0"?>
<ruleset name="Project Coding Standards">
<description>Project-specific coding standards based on ByteEver defaults.</description>
<!-- Scan these directories -->
<file>src/</file>
<file>inc/</file>
<!-- Exclude these paths -->
<exclude-pattern>vendor/</exclude-pattern>
<exclude-pattern>node_modules/</exclude-pattern>
<exclude-pattern>*.min.js</exclude-pattern>
<!-- Configuration -->
<config name="minimum_supported_wp_version" value="6.2" />
<config name="testVersion" value="7.4-8.5" />
<!-- Use ByteEver standards -->
<rule ref="ByteEver-Default" />
<!-- Project-specific customizations -->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="your-text-domain"/>
</property>
</properties>
</rule>
</ruleset>Add to your CI workflow:
# GitHub Actions example
- name: PHP CodeSniffer
run: composer run phpcs- Minimum: PHP 7.4
- Maximum: PHP 8.5
- Compatibility: Uses PHPCompatibilityWP for WordPress-specific compatibility checks
- WordPress Coding Standards (with sensible exclusions)
- Tab indentation (1 tab per indent level)
- Space inside parentheses for readability
- Superfluous whitespace detection
- PHP compatibility checking for WordPress
The following rules are excluded for practical development:
- File naming conventions (WordPress.Files.FileName)
- Nonce verification requirements
- Direct database query restrictions
- Global variable override prohibitions
- Some documentation capitalization requirements
Create a phpcs.xml.dist file to override or add rules:
<rule ref="ByteEver-Default">
<!-- Enable a rule that's disabled by default -->
<exclude name="WordPress.Files.FileName" />
</rule>
<!-- Add custom exclusions -->
<rule ref="WordPress.Security.NonceVerification.Missing">
<exclude-pattern>admin/ajax-handlers/*</exclude-pattern>
</rule>Disable rules for specific code blocks:
// phpcs:disable WordPress.Security.NonceVerification.Missing
if ( isset( $_POST['data'] ) ) {
// Process data without nonce check
}
// phpcs:enable WordPress.Security.NonceVerification.Missing- PHP 7.4 or higher
- Composer
- PHP_CodeSniffer 3.9.0 or higher
dealerdirect/phpcodesniffer-composer-installer: ^1.0phpcompatibility/phpcompatibility-wp: ^2.1wp-coding-standards/wpcs: ^3.1.0
- Fork the repository
- Create a feature branch
- Make your changes
- Test with
composer run phpcs - Submit a pull request
GPL-3.0-only
Sultan Nasir Uddin
Email: sultan@byteever.com
Organization: ByteEver
Part of the ByteEver development toolkit for WordPress and PHP projects.