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 TransitionModel extends Model |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * SQL table name. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | const TABLE = 'transitions'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Save transition event. |
||
| 30 | * |
||
| 31 | * @param int $user_id |
||
| 32 | * @param array $task_event |
||
| 33 | * |
||
| 34 | * @return bool |
||
| 35 | */ |
||
| 36 | public function save($user_id, array $task_event) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Get time spent by task for each column. |
||
| 53 | * |
||
| 54 | * @param int $task_id |
||
| 55 | * |
||
| 56 | * @return array |
||
| 57 | */ |
||
| 58 | public function getTimeSpentByTask($task_id) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Get all transitions by task. |
||
| 69 | * |
||
| 70 | * @param int $task_id |
||
| 71 | * |
||
| 72 | * @return array |
||
| 73 | */ |
||
| 74 | public function getAllByTask($task_id) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get all transitions by project. |
||
| 96 | * |
||
| 97 | * @param int $project_id |
||
| 98 | * @param mixed $from Start date (timestamp or user formatted date) |
||
| 99 | * @param mixed $to End date (timestamp or user formatted date) |
||
| 100 | * |
||
| 101 | * @return array |
||
| 102 | */ |
||
| 103 | public function getAllByProjectAndDate($project_id, $from, $to) |
||
| 136 | } |
||
| 137 |
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.