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 |
||
20 | class Console extends \Symfony\Component\Console\Application |
||
21 | { |
||
22 | use EnableDIAnnotations; |
||
23 | |||
24 | /** |
||
25 | * @inject |
||
26 | * @var ConsoleContainerBuilder |
||
27 | */ |
||
28 | protected $consoleContainerBuilder; |
||
29 | |||
30 | /** |
||
31 | * @inject |
||
32 | * @var InvokerInterface |
||
33 | */ |
||
34 | private $diInvoker; |
||
35 | |||
36 | /** |
||
37 | * @param FactoryInterface $factory |
||
38 | * @return Console |
||
39 | * @throws \DI\DependencyException |
||
40 | * @throws \DI\NotFoundException |
||
41 | */ |
||
42 | static public function create(FactoryInterface $factory) |
||
46 | /** |
||
47 | * @param $className |
||
48 | * @throws \Exception |
||
49 | */ |
||
50 | 1 | public function loadCommandsFromClass($className) |
|
64 | |||
65 | /** |
||
66 | * @param $fromPath |
||
67 | * @param string $namespace |
||
68 | * @throws \Exception |
||
69 | */ |
||
70 | View Code Duplication | public function loadCommandsFromPath($fromPath, $namespace = '') |
|
95 | |||
96 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.