Skip to content

drevops/phpcs-standard

Repository files navigation

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

About

PHP CodeSniffer Standard for snake_case variables

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Languages