drevops/phpcs-standard

DrevOps PHP_CodeSniffer rules: enforce snake_case for variables and parameters.

Fund package maintenance!
drevops
Patreon

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

0.2.0 2025-11-01 11:12 UTC

This package is auto-updated.

Last update: 2025-11-01 11:15:27 UTC


README

DrevOps PHP_CodeSniffer Standard logo

DrevOps PHP_CodeSniffer Standard

GitHub Issues GitHub Pull Requests Test PHP codecov GitHub release (latest by date) LICENSE Renovate

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