Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 7 | class PHP_Autoloader { |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Registers the autoloader with PHP so that it can begin autoloading classes. |
||
| 11 | * |
||
| 12 | * @param Version_Loader $version_loader The class loader to use in the autoloader. |
||
| 13 | */ |
||
| 14 | public function register_autoloader( $version_loader ) { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Unregisters the active autoloader so that it will no longer autoload classes. |
||
| 28 | */ |
||
| 29 | public function unregister_autoloader() { |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Loads a class file if one could be found. |
||
| 60 | * |
||
| 61 | * Note: This function is static so that the autoloader can be easily unregistered. If |
||
| 62 | * it was a class method we would have to unwrap the object to check the namespace. |
||
| 63 | * |
||
| 64 | * @param string $class_name The name of the class to autoload. |
||
| 65 | * |
||
| 66 | * @return bool Indicates whether or not a class file was loaded. |
||
| 67 | */ |
||
| 68 | View Code Duplication | public static function load_class( $class_name ) { |
|
| 82 | } |
||
| 83 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.