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 |
||
| 11 | class Menu extends Model |
||
| 12 | { |
||
| 13 | |||
| 14 | public function getSource() |
||
| 18 | |||
| 19 | protected $translateModel = 'Menu\Model\Translate\MenuTranslate'; // translate |
||
| 20 | |||
| 21 | private $id; |
||
| 22 | private $root = 'top'; |
||
| 23 | private $parent_id; |
||
| 24 | private $work_title; |
||
| 25 | private $depth = 0; |
||
| 26 | private $left_key; |
||
| 27 | private $right_key; |
||
| 28 | private $created_at; |
||
| 29 | private $updated_at; |
||
| 30 | public $title; // translate |
||
| 31 | |||
| 32 | public static $roots = [ |
||
| 33 | 'top' => 'Top Menu', |
||
| 34 | ]; |
||
| 35 | |||
| 36 | public function initialize() |
||
| 41 | |||
| 42 | public function validation() |
||
| 53 | |||
| 54 | public function beforeCreate() |
||
| 58 | |||
| 59 | public function beforeUpdate() |
||
| 63 | |||
| 64 | public static function treeUpperLeafs($root) |
||
| 73 | |||
| 74 | View Code Duplication | public function children() |
|
| 89 | |||
| 90 | public function hasChildren() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @return mixed |
||
| 99 | */ |
||
| 100 | public function getId() |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @param mixed $id |
||
| 107 | */ |
||
| 108 | public function setId($id) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | public function getRoot() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param string $root |
||
| 123 | */ |
||
| 124 | public function setRoot($root) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @return mixed |
||
| 131 | */ |
||
| 132 | public function getParentId() |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @param mixed $parent_id |
||
| 139 | */ |
||
| 140 | public function setParentId($parent_id) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @return mixed |
||
| 147 | */ |
||
| 148 | public function getDepth() |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @param mixed $depth |
||
| 155 | */ |
||
| 156 | public function setDepth($depth) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @return mixed |
||
| 163 | */ |
||
| 164 | public function getLeftKey() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @param mixed $left_key |
||
| 171 | */ |
||
| 172 | public function setLeftKey($left_key) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @return mixed |
||
| 179 | */ |
||
| 180 | public function getRightKey() |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @param mixed $right_key |
||
| 187 | */ |
||
| 188 | public function setRightKey($right_key) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @return mixed |
||
| 195 | */ |
||
| 196 | public function getTitle() |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @param mixed $title |
||
| 203 | */ |
||
| 204 | public function setTitle($title) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @return mixed |
||
| 211 | */ |
||
| 212 | public function getCreatedAt() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @param mixed $created_at |
||
| 219 | */ |
||
| 220 | public function setCreatedAt($created_at) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @return mixed |
||
| 227 | */ |
||
| 228 | public function getUpdatedAt() |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @param mixed $updated_at |
||
| 235 | */ |
||
| 236 | public function setUpdatedAt($updated_at) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @return mixed |
||
| 243 | */ |
||
| 244 | public function getWorkTitle() |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @param mixed $work_title |
||
| 251 | */ |
||
| 252 | public function setWorkTitle($work_title) |
||
| 256 | |||
| 257 | } |
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: