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 ColumnModel extends Model |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * SQL table name. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | const TABLE = 'columns'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Get a column by the id. |
||
| 30 | * |
||
| 31 | * @param int $column_id Column id |
||
| 32 | * |
||
| 33 | * @return array |
||
| 34 | */ |
||
| 35 | public function getById($column_id) |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Get projectId by the columnId. |
||
| 42 | * |
||
| 43 | * @param int $column_id Column id |
||
| 44 | * |
||
| 45 | * @return int |
||
| 46 | */ |
||
| 47 | public function getProjectId($column_id) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Get the first column id for a given project. |
||
| 54 | * |
||
| 55 | * @param int $project_id Project id |
||
| 56 | * |
||
| 57 | * @return int |
||
| 58 | */ |
||
| 59 | public function getFirstColumnId($project_id) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get the last column id for a given project. |
||
| 66 | * |
||
| 67 | * @param int $project_id Project id |
||
| 68 | * |
||
| 69 | * @return int |
||
| 70 | */ |
||
| 71 | public function getLastColumnId($project_id) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Get the position of the last column for a given project. |
||
| 78 | * |
||
| 79 | * @param int $project_id Project id |
||
| 80 | * |
||
| 81 | * @return int |
||
| 82 | */ |
||
| 83 | public function getLastColumnPosition($project_id) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Get a column id by the name. |
||
| 94 | * |
||
| 95 | * @param int $project_id |
||
| 96 | * @param string $title |
||
| 97 | * |
||
| 98 | * @return int |
||
| 99 | */ |
||
| 100 | public function getColumnIdByTitle($project_id, $title) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Get a column title by the id. |
||
| 107 | * |
||
| 108 | * @param int $column_id |
||
| 109 | * |
||
| 110 | * @return int |
||
| 111 | */ |
||
| 112 | public function getColumnTitleById($column_id) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Get all columns sorted by position for a given project. |
||
| 119 | * |
||
| 120 | * @param int $project_id Project id |
||
| 121 | * |
||
| 122 | * @return array |
||
| 123 | */ |
||
| 124 | public function getAll($project_id) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Get the list of columns sorted by position [ column_id => title ]. |
||
| 131 | * |
||
| 132 | * @param int $project_id Project id |
||
| 133 | * @param bool $prepend Prepend a default value |
||
| 134 | * |
||
| 135 | * @return array |
||
| 136 | */ |
||
| 137 | public function getList($project_id, $prepend = false) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Add a new column to the board. |
||
| 146 | * |
||
| 147 | * @param int $project_id Project id |
||
| 148 | * @param string $title Column title |
||
| 149 | * @param int $task_limit Task limit |
||
| 150 | * @param string $description Column description |
||
| 151 | * @param int $hide_in_dashboard |
||
| 152 | * |
||
| 153 | * @return bool|int |
||
| 154 | */ |
||
| 155 | public function create($project_id, $title, $task_limit = 0, $description = '', $hide_in_dashboard = 0) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Update a column. |
||
| 171 | * |
||
| 172 | * @param int $column_id Column id |
||
| 173 | * @param string $title Column title |
||
| 174 | * @param int $task_limit Task limit |
||
| 175 | * @param string $description Optional description |
||
| 176 | * @param int $hide_in_dashboard |
||
| 177 | * |
||
| 178 | * @return bool |
||
| 179 | */ |
||
| 180 | public function update($column_id, $title, $task_limit = 0, $description = '', $hide_in_dashboard = 0) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Remove a column and all tasks associated to this column. |
||
| 192 | * |
||
| 193 | * @param int $column_id Column id |
||
| 194 | * |
||
| 195 | * @return bool |
||
| 196 | */ |
||
| 197 | public function remove($column_id) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Change column position. |
||
| 204 | * |
||
| 205 | * @param int $project_id |
||
| 206 | * @param int $column_id |
||
| 207 | * @param int $position |
||
| 208 | * |
||
| 209 | * @return bool |
||
| 210 | */ |
||
| 211 | View Code Duplication | public function changePosition($project_id, $column_id, $position) |
|
| 234 | } |
||
| 235 |
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.