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 |
||
4 | class DeployPlanDispatcher extends Dispatcher { |
||
5 | |||
6 | const ACTION_PLAN = 'plan'; |
||
7 | |||
8 | /** |
||
9 | * @var array |
||
10 | */ |
||
11 | private static $action_types = [ |
||
12 | self::ACTION_PLAN |
||
13 | ]; |
||
14 | |||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | public static $allowed_actions = [ |
||
19 | 'git_refs', |
||
20 | ]; |
||
21 | |||
22 | /** |
||
23 | * @var \DNProject |
||
24 | */ |
||
25 | protected $project = null; |
||
26 | |||
27 | /** |
||
28 | * @var \DNEnvironment |
||
29 | */ |
||
30 | protected $environment = null; |
||
31 | |||
32 | public function init() { |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | public function Link() { |
||
58 | |||
59 | /** |
||
60 | * Render configuration form. |
||
61 | * |
||
62 | * @param \SS_HTTPRequest $request |
||
63 | * |
||
64 | * @return \HTMLText|\SS_HTTPResponse |
||
65 | */ |
||
66 | public function index(\SS_HTTPRequest $request) { |
||
72 | |||
73 | public function update_git(\SS_HTTPRequest $request) { |
||
76 | |||
77 | /** |
||
78 | * @param SS_HTTPRequest $request |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public function git_refs(\SS_HTTPRequest $request) { |
||
120 | |||
121 | /** |
||
122 | * Generate the data structure used by the frontend component. |
||
123 | * |
||
124 | * @param string $name of the component |
||
125 | * |
||
126 | * @return array |
||
127 | */ |
||
128 | public function getModel($name) { |
||
133 | |||
134 | /** |
||
135 | * @param $project |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | protected function getGitBranches($project) { |
||
149 | |||
150 | /** |
||
151 | * @param $project |
||
152 | * |
||
153 | * @return array |
||
154 | */ |
||
155 | protected function getGitTags($project) { |
||
165 | |||
166 | /** |
||
167 | * @param $project |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | protected function getGitPrevDeploys($project) { |
||
198 | } |
||
199 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.