PHP

PHP

By DeepSource

Dead code found after return PHP-W1074

Anti-pattern
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.

Examples

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