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 TaskDuplicationModel extends Model |
||
20 | { |
||
21 | /** |
||
22 | * Fields to copy when duplicating a task. |
||
23 | * |
||
24 | * @var string[] |
||
25 | */ |
||
26 | protected $fieldsToDuplicate = [ |
||
27 | 'title', |
||
28 | 'description', |
||
29 | 'date_due', |
||
30 | 'color_id', |
||
31 | 'project_id', |
||
32 | 'column_id', |
||
33 | 'owner_id', |
||
34 | 'score', |
||
35 | 'priority', |
||
36 | 'category_id', |
||
37 | 'time_estimated', |
||
38 | 'swimlane_id', |
||
39 | 'recurrence_status', |
||
40 | 'recurrence_trigger', |
||
41 | 'recurrence_factor', |
||
42 | 'recurrence_timeframe', |
||
43 | 'recurrence_basedate', |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * Duplicate a task to the same project. |
||
48 | * |
||
49 | * @param int $task_id Task id |
||
50 | * |
||
51 | * @return bool|int Duplicated task id |
||
52 | */ |
||
53 | public function duplicate($task_id) |
||
63 | |||
64 | /** |
||
65 | * Check if the assignee and the category are available in the destination project. |
||
66 | * |
||
67 | * @param array $values |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | public function checkDestinationProjectValues(array &$values) |
||
112 | |||
113 | /** |
||
114 | * Duplicate fields for the new task. |
||
115 | * |
||
116 | * @param int $task_id Task id |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | protected function copyFields($task_id) |
||
131 | |||
132 | /** |
||
133 | * Create the new task and duplicate subtasks. |
||
134 | * |
||
135 | * @param int $task_id Task id |
||
136 | * @param array $values Form values |
||
137 | * |
||
138 | * @return bool|int |
||
139 | */ |
||
140 | protected function save($task_id, array $values) |
||
150 | } |
||
151 |
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@property
annotation 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.