Naming Method

ID

php.naming_method

Severity

info

Remediation Complexity

trivial

Remediation Risk

medium

Remediation Effort

low

Resource

Naming Convention

Language

Php

Tags

convention, naming_convention

Description

Reports a method or free function whose name does not follow the camelCase convention: the name must start with a lowercase letter and contain only letters and digits. PSR-1 mandates camelCase for class methods, and the rule applies the same convention to free functions so a codebase keeps a single, predictable naming style.

Rationale

Consistent method naming makes code easier to read and lets tools, IDEs and contributors form correct expectations about every call site. PSR-1 fixes camelCase as the convention for method names; a name such as GetUser or get_user breaks that expectation and signals either a copy-paste from another language or an accidental rename. Magic methods (construct, toString, …​) are reserved by the engine and keep their __ prefix, so they are never flagged. PHPUnit test methods are also exempt — snake_case test naming is a deliberate convention — when the enclosing class is a test class (name ends in Test/Tests or extends a *TestCase), the method name starts with test/provider/data_provider, or the method carries a [Test] or [DataProvider] attribute.

<?php
class UserService
{
    public function __construct() {}   // OK — magic method, reserved name

    public function LoadUser() {}       // FLAW — starts with an uppercase letter

    public function load_user() {}      // FLAW — uses snake_case

    public function loadUser() {}       // OK — camelCase
}

function fetchUsers() {}                // OK — camelCase free function

Remediation

Rename the method or function to camelCase: lowercase the first letter and remove any underscores, joining the words with an internal capital (load_user becomes loadUser). The accepted pattern is configurable through the methodNamePattern property.