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 | 'gitupdate', |
||
20 | 'gitrefs', |
||
21 | 'deploysummary' |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * @var \DNProject |
||
26 | */ |
||
27 | protected $project = null; |
||
28 | |||
29 | /** |
||
30 | * @var \DNEnvironment |
||
31 | */ |
||
32 | protected $environment = null; |
||
33 | |||
34 | public function init() { |
||
49 | |||
50 | /** |
||
51 | * @return string |
||
52 | */ |
||
53 | public function Link() { |
||
56 | |||
57 | /** |
||
58 | * |
||
59 | * @param \SS_HTTPRequest $request |
||
60 | * |
||
61 | * @return \HTMLText|\SS_HTTPResponse |
||
62 | */ |
||
63 | public function index(\SS_HTTPRequest $request) { |
||
69 | |||
70 | /** |
||
71 | * @param SS_HTTPRequest $request |
||
72 | * @return SS_HTTPResponse |
||
73 | */ |
||
74 | public function gitupdate(SS_HTTPRequest $request) { |
||
84 | |||
85 | /** |
||
86 | * @param SS_HTTPRequest $request |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | public function gitrefs(\SS_HTTPRequest $request) { |
||
128 | |||
129 | /** |
||
130 | * Generate the data structure used by the frontend component. |
||
131 | * |
||
132 | * @param string $name of the component |
||
133 | * |
||
134 | * @return array |
||
135 | */ |
||
136 | public function getModel($name) { |
||
141 | |||
142 | /** |
||
143 | * @param int $ID |
||
144 | * @return SS_HTTPResponse |
||
145 | */ |
||
146 | protected function getFetch($ID) { |
||
159 | |||
160 | /** |
||
161 | * @return SS_HTTPResponse |
||
162 | */ |
||
163 | View Code Duplication | protected function createFetch() { |
|
180 | |||
181 | /** |
||
182 | * @param SS_HTTPRequest $request |
||
183 | * |
||
184 | * @return SS_HTTPResponse |
||
185 | */ |
||
186 | public function deploysummary(SS_HTTPRequest $request) { |
||
226 | |||
227 | /** |
||
228 | * @param $project |
||
229 | * |
||
230 | * @return array |
||
231 | */ |
||
232 | protected function getGitBranches($project) { |
||
242 | |||
243 | /** |
||
244 | * @param $project |
||
245 | * |
||
246 | * @return array |
||
247 | */ |
||
248 | protected function getGitTags($project) { |
||
258 | |||
259 | /** |
||
260 | * @param $project |
||
261 | * |
||
262 | * @return array |
||
263 | */ |
||
264 | protected function getGitPrevDeploys($project) { |
||
291 | |||
292 | /** |
||
293 | * Return a simple response with a message |
||
294 | * |
||
295 | * @param string $message |
||
296 | * @param int $statusCode |
||
297 | * @return SS_HTTPResponse |
||
298 | */ |
||
299 | protected function getAPIResponse($message, $statusCode) { |
||
311 | |||
312 | /** |
||
313 | * @param ArrayData $interface |
||
314 | * @param array $codeVersion |
||
315 | * |
||
316 | * @return bool |
||
317 | */ |
||
318 | protected function canCompareCodeVersion(\ArrayData $interface, $codeVersion) { |
||
333 | } |
||
334 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: