PHP

PHP

Made by DeepSource

Empty block of code found PHP-W1085

Anti-pattern
Major
Autofix

An empty block is considered as dead code as it doesn't do anything. The issue is raised when loops, conditionals, or other statements contains empty body which implies some piece of code is missing.

It is advised to remove the empty block since keeping them in the codebase wastes computation time and memory.

// Bad practice
foreach ($users as $user) {
}

if ($isUserActive) {
}

// Recommended
foreach ($users as $user) {
    echo $user->getName();
}

if ($isUserActive) {
    echo $user->getName();
}