Empty Function Body
ID |
php.empty_function_body |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Php |
Tags |
code_smell, suspicious |
Description
Reports a function or method that is declared with a brace block but contains no
statements, for example function handle() { }. A comment-only body counts as empty
because comments carry no behaviour.
Abstract methods and interface methods are not reported: they legitimately have no body
(they end with ;, not a brace block). Empty constructors are handled by a separate rule
and are skipped here.
Rationale
An empty body is almost always an unfinished stub left behind during development, or dead code whose logic was removed but whose declaration survived. Either way a caller invokes something that silently does nothing, which is easy to mistake for working behaviour and hard to spot in review.
<?php
class Importer
{
public function process() // FLAW — declared but does nothing
{
}
public function run(array $rows): void // OK — has statements
{
foreach ($rows as $row) {
$this->process();
}
}
}
Remediation
Implement the intended behaviour, or remove the declaration if it is no longer needed. If
the empty body is a deliberate placeholder (for example a hook that subclasses override),
make the intent explicit with a short comment and consider marking the method abstract.