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 |
||
39 | class CirclesController extends BaseController { |
||
40 | |||
41 | // /** @var string */ |
||
|
|||
42 | // private $userId; |
||
43 | // /** @var IL10N */ |
||
44 | // private $l10n; |
||
45 | // /** @var ConfigService */ |
||
46 | // private $configService; |
||
47 | // |
||
48 | // /** @var MiscService */ |
||
49 | // private $miscService; |
||
50 | // |
||
51 | // public function __construct( |
||
52 | // $appName, |
||
53 | // IRequest $request, |
||
54 | // $userId, |
||
55 | // IL10N $l10n, |
||
56 | // ConfigService $configService, |
||
57 | // CirclesService $circlesService, |
||
58 | // MiscService $miscService |
||
59 | // ) { |
||
60 | // parent::__construct($appName, $request); |
||
61 | // |
||
62 | // $this->userId = $userId; |
||
63 | // $this->l10n = $l10n; |
||
64 | // $this->configService = $configService; |
||
65 | // $this->circlesService = $circlesService; |
||
66 | // $this->miscService = $miscService; |
||
67 | // } |
||
68 | |||
69 | |||
70 | /** |
||
71 | * @NoAdminRequired |
||
72 | * @NoSubAdminRequired |
||
73 | * |
||
74 | * @param $type |
||
75 | * @param string $name |
||
76 | * |
||
77 | * @return DataResponse |
||
78 | */ |
||
79 | public function create($type, $name) { |
||
115 | |||
116 | |||
117 | /** |
||
118 | * @NoAdminRequired |
||
119 | * @NoSubAdminRequired |
||
120 | * |
||
121 | * @param $type |
||
122 | * @param string $name |
||
123 | * |
||
124 | * @return DataResponse |
||
125 | */ |
||
126 | public function list($type, $name = '') { |
||
147 | |||
148 | |||
149 | /** |
||
150 | * @NoAdminRequired |
||
151 | * @NoSubAdminRequired |
||
152 | * |
||
153 | * @param $id |
||
154 | * |
||
155 | * @return DataResponse |
||
156 | * @internal param string $name |
||
157 | * |
||
158 | */ |
||
159 | public function details($id) { |
||
180 | |||
181 | |||
182 | /** |
||
183 | * @NoAdminRequired |
||
184 | * @NoSubAdminRequired |
||
185 | * |
||
186 | * @param $id |
||
187 | * |
||
188 | * @return DataResponse |
||
189 | * @internal param string $name |
||
190 | * |
||
191 | */ |
||
192 | View Code Duplication | public function join($id) { |
|
212 | |||
213 | |||
214 | /** |
||
215 | * @NoAdminRequired |
||
216 | * @NoSubAdminRequired |
||
217 | * |
||
218 | * @param $id |
||
219 | * |
||
220 | * @return DataResponse |
||
221 | * @internal param string $name |
||
222 | * |
||
223 | */ |
||
224 | View Code Duplication | public function leave($id) { |
|
243 | |||
244 | |||
245 | } |
||
246 | |||
247 |
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.