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 |
||
| 19 | class TaskLinkModel extends Model |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * SQL table name. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | const TABLE = 'task_has_links'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Events. |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | const EVENT_CREATE_UPDATE = 'task_internal_link.create_update'; |
||
| 34 | const EVENT_DELETE = 'task_internal_link.delete'; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Get projectId from $task_link_id. |
||
| 38 | * |
||
| 39 | * @param int $task_link_id |
||
| 40 | * |
||
| 41 | * @return int |
||
| 42 | */ |
||
| 43 | public function getProjectId($task_link_id) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Get a task link. |
||
| 54 | * |
||
| 55 | * @param int $task_link_id Task link id |
||
| 56 | * |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | View Code Duplication | public function getById($task_link_id) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Get the opposite task link (use the unique index task_has_links_unique). |
||
| 78 | * |
||
| 79 | * @param array $task_link |
||
| 80 | * |
||
| 81 | * @return array |
||
| 82 | */ |
||
| 83 | public function getOppositeTaskLink(array $task_link) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get all links attached to a task. |
||
| 96 | * |
||
| 97 | * @param int $task_id Task id |
||
| 98 | * |
||
| 99 | * @return array |
||
| 100 | */ |
||
| 101 | public function getAll($task_id) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Get all links attached to a task grouped by label. |
||
| 138 | * |
||
| 139 | * @param int $task_id Task id |
||
| 140 | * |
||
| 141 | * @return array |
||
| 142 | */ |
||
| 143 | public function getAllGroupedByLabel($task_id) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Create a new link. |
||
| 161 | * |
||
| 162 | * @param int $task_id Task id |
||
| 163 | * @param int $opposite_task_id Opposite task id |
||
| 164 | * @param int $link_id Link id |
||
| 165 | * |
||
| 166 | * @return int|bool |
||
| 167 | */ |
||
| 168 | public function create($task_id, $opposite_task_id, $link_id) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Update a task link. |
||
| 190 | * |
||
| 191 | * @param int $task_link_id Task link id |
||
| 192 | * @param int $task_id Task id |
||
| 193 | * @param int $opposite_task_id Opposite task id |
||
| 194 | * @param int $link_id Link id |
||
| 195 | * |
||
| 196 | * @return bool |
||
| 197 | */ |
||
| 198 | public function update($task_link_id, $task_id, $opposite_task_id, $link_id) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Remove a link between two tasks. |
||
| 223 | * |
||
| 224 | * @param int $task_link_id |
||
| 225 | * |
||
| 226 | * @return bool |
||
| 227 | */ |
||
| 228 | public function remove($task_link_id) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Publish events. |
||
| 262 | * |
||
| 263 | * @param int[] $task_link_ids |
||
| 264 | * @param string $eventName |
||
| 265 | */ |
||
| 266 | protected function fireEvents(array $task_link_ids, $eventName) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Create task link. |
||
| 275 | * |
||
| 276 | * @param int $task_id |
||
| 277 | * @param int $opposite_task_id |
||
| 278 | * @param int $link_id |
||
| 279 | * |
||
| 280 | * @return int|bool |
||
| 281 | */ |
||
| 282 | View Code Duplication | protected function createTaskLink($task_id, $opposite_task_id, $link_id) |
|
| 290 | |||
| 291 | /** |
||
| 292 | * Update task link. |
||
| 293 | * |
||
| 294 | * @param int $task_link_id |
||
| 295 | * @param int $task_id |
||
| 296 | * @param int $opposite_task_id |
||
| 297 | * @param int $link_id |
||
| 298 | * |
||
| 299 | * @return bool |
||
| 300 | */ |
||
| 301 | View Code Duplication | protected function updateTaskLink($task_link_id, $task_id, $opposite_task_id, $link_id) |
|
| 309 | } |
||
| 310 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.