Naming Placeholder Identifier
ID |
php.naming_placeholder_identifier |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Php |
Tags |
naming |
Description
Reports identifiers whose name is a meaningless placeholder such as foo, bar, baz,
qux, tmp, temp, obj, stuff or thing. Function and method names, parameters,
foreach value variables, bare-variable assignment targets and class names are all checked.
The match is case-insensitive but exact, so $dataSource is not flagged. A binding named after
its declared type (Data $data) is exempt. The placeholder list is configurable through the
placeholderNames property.
Rationale
Placeholder names are artefacts of throwaway prototyping. They tell the reader nothing about
what the value holds or what the function does, forcing a trip to the implementation to
recover intent. A name like $tmp or foo() that survives into committed code is a small
but constant tax on every future reader. Naming the thing after its role makes the code
self-documenting.
<?php
function foo($bar) // FLAW - function name and parameter are placeholders
{
$tmp = compute(); // FLAW - placeholder local
return $tmp;
}
function totalDue($invoice) // OK - intent-revealing names
{
$balance = compute(); // OK
return $balance;
}
function consume(Data $data) {} // OK - parameter named after its declared type
Remediation
Rename the identifier to describe what it represents — the value’s role, the function’s
effect, the type’s responsibility. A binding named after its declared type (Data $data)
is acceptable. Adjust the placeholderNames property to match project conventions.