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 |
||
| 18 | class AdminHelper extends AppHelper |
||
| 19 | { |
||
| 20 | public $helpers = [ |
||
| 21 | 'Breadcrumbs', |
||
| 22 | 'SaitoHelp', |
||
| 23 | 'Html', |
||
| 24 | 'TimeH' |
||
| 25 | ]; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * help |
||
| 29 | * |
||
| 30 | * @param string $id id |
||
| 31 | * @return mixed |
||
| 32 | */ |
||
| 33 | public function help($id) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * cache badge |
||
| 40 | * |
||
| 41 | * @param string $engine engine |
||
| 42 | * @return string |
||
| 43 | */ |
||
| 44 | protected function _cacheBadge($engine) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * badge |
||
| 66 | * |
||
| 67 | * @param string $text text |
||
| 68 | * @param null $type type |
||
| 69 | * @return mixed |
||
| 70 | */ |
||
| 71 | public function badge($text, $type = null) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Adds Breadcrumb item |
||
| 90 | * |
||
| 91 | * @see BreadcrumbsHelper::add() |
||
| 92 | * |
||
| 93 | * @param string $title Title |
||
| 94 | * @param string $url URL |
||
| 95 | * @param array $options Options |
||
| 96 | * @return BreadcrumbsHelper |
||
| 97 | */ |
||
| 98 | public function addBreadcrumb($title, $url = null, array $options = []) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * format cake log |
||
| 114 | * |
||
| 115 | * @bogus the ability to see logs isn't in Saito 5 anymore |
||
| 116 | * |
||
| 117 | * @param string $log log |
||
| 118 | * @return string |
||
| 119 | */ |
||
| 120 | public function formatCakeLog($log) |
||
| 166 | |||
| 167 | /** |
||
| 168 | * jquery table |
||
| 169 | * |
||
| 170 | * @param string $selector selector |
||
| 171 | * @param string $sort sort |
||
| 172 | * |
||
| 173 | * @return void |
||
| 174 | */ |
||
| 175 | public function jqueryTable($selector, $sort) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * accession to roles |
||
| 200 | * |
||
| 201 | * @param int $accession accession |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | View Code Duplication | public function accessionToRoles($accession) |
|
| 217 | } |
||
| 218 |
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: