Skip to content

Files

Latest commit

 

History

History
38 lines (28 loc) · 1006 Bytes

Squiz.PHP.NonExecutableCode.md

File metadata and controls

38 lines (28 loc) · 1006 Bytes

Pattern: Unreachable code

Issue: -

Description

Unreachable code can never be executed because there exists no control flow path to the code from the rest of the program. It is generally considered undesirable for a number of reasons, including increased code size and increased time and effort for maintenance. Consider deleting unused code to resolve this issue.

Example

Example of incorrect code:

switch ($number) {
	case 1:
		return $number . $this->ordinals['first'];
		do_something(); // unreachable
		break; 		// unreachable
	case 2:
		return $number . $this->ordinals['second'];
		break; 		// unreachable
}

Example of correct code:

switch ($number) {
	case 1:
		return $number . $this->ordinals['first'];
	case 2:
		return $number . $this->ordinals['second'];
}

Further Reading