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 | ]; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var \DNProject |
||
| 25 | */ |
||
| 26 | protected $project = null; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var \DNEnvironment |
||
| 30 | */ |
||
| 31 | protected $environment = null; |
||
| 32 | |||
| 33 | public function init() { |
||
| 34 | parent::init(); |
||
| 35 | |||
| 36 | $this->project = $this->getCurrentProject(); |
||
| 37 | |||
| 38 | if(!$this->project) { |
||
| 39 | return $this->project404Response(); |
||
| 40 | } |
||
| 41 | |||
| 42 | // Performs canView permission check by limiting visible projects |
||
| 43 | $this->environment = $this->getCurrentEnvironment($this->project); |
||
| 44 | if(!$this->environment) { |
||
| 45 | return $this->environment404Response(); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @return string |
||
| 51 | */ |
||
| 52 | public function Link() { |
||
| 53 | return \Controller::join_links($this->environment->Link(), self::ACTION_PLAN); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * |
||
| 58 | * @param \SS_HTTPRequest $request |
||
| 59 | * |
||
| 60 | * @return \HTMLText|\SS_HTTPResponse |
||
| 61 | */ |
||
| 62 | public function index(\SS_HTTPRequest $request) { |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param SS_HTTPRequest $request |
||
| 71 | * @return SS_HTTPResponse |
||
| 72 | */ |
||
| 73 | public function gitupdate(SS_HTTPRequest $request) { |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param SS_HTTPRequest $request |
||
| 88 | * |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | public function gitrefs(\SS_HTTPRequest $request) { |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Generate the data structure used by the frontend component. |
||
| 132 | * |
||
| 133 | * @param string $name of the component |
||
| 134 | * |
||
| 135 | * @return array |
||
| 136 | */ |
||
| 137 | public function getModel($name) { |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @param int $ID |
||
| 145 | * @return SS_HTTPResponse |
||
| 146 | */ |
||
| 147 | protected function getFetch($ID) { |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @return SS_HTTPResponse |
||
| 163 | */ |
||
| 164 | View Code Duplication | protected function createFetch() { |
|
| 181 | |||
| 182 | /** |
||
| 183 | * @param $project |
||
| 184 | * |
||
| 185 | * @return array |
||
| 186 | */ |
||
| 187 | protected function getGitBranches($project) { |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param $project |
||
| 200 | * |
||
| 201 | * @return array |
||
| 202 | */ |
||
| 203 | protected function getGitTags($project) { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @param $project |
||
| 216 | * |
||
| 217 | * @return array |
||
| 218 | */ |
||
| 219 | protected function getGitPrevDeploys($project) { |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Return a simple response with a message |
||
| 249 | * |
||
| 250 | * @param string $message |
||
| 251 | * @param int $statusCode |
||
| 252 | * @return SS_HTTPResponse |
||
| 253 | */ |
||
| 254 | protected function getAPIResponse($message, $statusCode) { |
||
| 266 | } |
||
| 267 |
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: