drevops / phpcs-standard
DrevOps PHP_CodeSniffer rules: enforce snake_case for variables and parameters.
Installs: 711
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:phpcodesniffer-standard
pkg:composer/drevops/phpcs-standard
Requires
- php: >=8.3
- dealerdirect/phpcodesniffer-composer-installer: ^1
- squizlabs/php_codesniffer: ^3.10
Requires (Dev)
- alexskrypnyk/phpunit-helpers: ^0.13.0
- drupal/coder: ^8.3
- ergebnis/composer-normalize: ^2.42
- phpstan/phpstan: ^2
- phpunit/phpunit: ^12
- rector/rector: ^2
README
DrevOps PHP_CodeSniffer Standard
PHP_CodeSniffer standard enforcing snake_case naming for local variables and function/method parameters. Class properties are intentionally excluded.
Installation
composer require --dev drevops/phpcs-standard
The standard is automatically registered via phpcodesniffer-composer-installer.
Verify: vendor/bin/phpcs -i (should list DrevOps)
Usage
# Check code vendor/bin/phpcs --standard=DrevOps path/to/code # Auto-fix vendor/bin/phpcbf --standard=DrevOps path/to/code
Configuration
Create phpcs.xml:
<?xml version="1.0"?> <ruleset name="Project Standards"> <rule ref="DrevOps"/> <file>src</file> <file>tests</file> </ruleset>
Use individual sniffs:
<ruleset name="Custom Standards"> <rule ref="DrevOps.NamingConventions.LocalVariableSnakeCase"/> <rule ref="DrevOps.NamingConventions.ParameterSnakeCase"/> </ruleset>
LocalVariableSnakeCase
Enforces snake_case for local variables inside functions/methods.
function processOrder() { $order_id = 1; // ✓ Valid $orderId = 1; // ✗ Error: VariableNotSnakeCase }
Excludes:
- Function/method parameters (handled by
ParameterSnakeCase) - Class properties (not enforced)
- Reserved variables (
$this,$_GET,$_POST, etc.)
Error code
DrevOps.NamingConventions.LocalVariableSnakeCase.NotSnakeCase
Ignore
// phpcs:ignore DrevOps.NamingConventions.LocalVariableSnakeCase.NotSnakeCase $myVariable = 'value';
ParameterSnakeCase
Enforces snake_case for function/method parameters.
function processOrder($order_id, $user_data) { // ✓ Valid function processOrder($orderId, $userData) { // ✗ Error: ParameterNotSnakeCase
Excludes:
- Parameters inherited from interfaces/parent classes
- Parameters in interface/abstract method declarations
- Class properties (including promoted constructor properties)
Error code
DrevOps.NamingConventions.ParameterSnakeCase.NotSnakeCase
Ignore
// phpcs:ignore DrevOps.NamingConventions.ParameterSnakeCase.NotSnakeCase function process($legacyParam) {}
Development
composer install # Install dependencies composer test # Run tests composer test-coverage # Run tests with coverage composer lint # Check code standards composer lint-fix # Fix code standards
License
GPL-3.0-or-later
This repository was created using the Scaffold project template
