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 |
||
28 | class InstallationStatusDeterminator |
||
29 | { |
||
30 | /** |
||
31 | * The home path determinator. |
||
32 | * |
||
33 | * @var HomePathDeterminator |
||
34 | */ |
||
35 | private $home; |
||
36 | |||
37 | /** |
||
38 | * Local cache flag determining if tenside is properly configured. |
||
39 | * |
||
40 | * @var null|bool |
||
41 | */ |
||
42 | private $isTensideConfigured; |
||
43 | |||
44 | /** |
||
45 | * Local cache flag determining if a composer.json is present. |
||
46 | * |
||
47 | * @var null|bool |
||
48 | */ |
||
49 | private $isProjectPresent; |
||
50 | |||
51 | /** |
||
52 | * Local cache flag determining if the composer project has been installed (vendor present). |
||
53 | * |
||
54 | * @var null|bool |
||
55 | */ |
||
56 | private $isProjectInstalled; |
||
57 | |||
58 | /** |
||
59 | * Create a new instance. |
||
60 | * |
||
61 | * @param HomePathDeterminator $homePathDeterminator The home path determinator. |
||
62 | */ |
||
63 | public function __construct(HomePathDeterminator $homePathDeterminator) |
||
67 | |||
68 | /** |
||
69 | * Check if a "tenside.json" is present. |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | public function isTensideConfigured() |
||
83 | |||
84 | /** |
||
85 | * Check if a project "composer.json" is present. |
||
86 | * |
||
87 | * @return bool |
||
88 | */ |
||
89 | View Code Duplication | public function isProjectPresent() |
|
97 | |||
98 | /** |
||
99 | * Check if the vendor directory is present. |
||
100 | * |
||
101 | * @return bool |
||
102 | */ |
||
103 | View Code Duplication | public function isProjectInstalled() |
|
111 | |||
112 | /** |
||
113 | * Flag if everything is completely installed. |
||
114 | * |
||
115 | * @return bool |
||
116 | */ |
||
117 | public function isComplete() |
||
123 | } |
||
124 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.