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 |
||
| 18 | class Console extends \Symfony\Component\Console\Application |
||
| 19 | { |
||
| 20 | use EnableDIAnnotations; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @inject |
||
| 24 | * @var ConsoleContainerBuilder |
||
| 25 | */ |
||
| 26 | protected $consoleContainerBuilder; |
||
| 27 | |||
| 28 | |||
| 29 | /** |
||
| 30 | * @param $className |
||
| 31 | * @throws \Exception |
||
| 32 | */ |
||
| 33 | 1 | public function loadCommandsFromClass($className) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * @param $fromPath |
||
| 50 | * @param string $namespace |
||
| 51 | * @throws \Exception |
||
| 52 | */ |
||
| 53 | View Code Duplication | public function loadRoutesFromPath($fromPath, $namespace = '') |
|
| 78 | |||
| 79 | } |
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.