PHP

PHP

Made by DeepSource

Dead code found after return PHP-W1074

Anti-pattern
Major
Autofix

The return keyword ends the function execution. If return is used outside of a function, it stops PHP code in the file from running. Therefore, any code after return is considered as dead code as it won't be executed ever and can be safely removed.

Bad practice

function getSlug(string $title): string {
    $array = explode(' ', strtolower($title));

    return implode('-', $array);
    unset($array); // invalid: this code will never executed
}

Recommended

Make sure there's no code after return statement:

function getSlug(string $title): string {
    $array = explode(' ', strtolower($title));

    return implode('-', $array);
}

References