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 |
||
| 20 | class AverageTimeSpentColumnAnalytic extends Base |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Build report. |
||
| 24 | * |
||
| 25 | * @param int $project_id Project id |
||
| 26 | * |
||
| 27 | * @return array |
||
| 28 | */ |
||
| 29 | public function build($project_id) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Initialize default values for each column. |
||
| 41 | * |
||
| 42 | * @param int $project_id |
||
| 43 | * |
||
| 44 | * @return array |
||
| 45 | */ |
||
| 46 | private function initialize($project_id) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Calculate time spent for each tasks for each columns. |
||
| 65 | * |
||
| 66 | * @param array $stats |
||
| 67 | * @param int $project_id |
||
| 68 | */ |
||
| 69 | private function processTasks(array &$stats, $project_id) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Calculate averages. |
||
| 85 | * |
||
| 86 | * @param array $stats |
||
| 87 | */ |
||
| 88 | private function calculateAverage(array &$stats) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Calculate column average. |
||
| 97 | * |
||
| 98 | * @param array $column |
||
| 99 | */ |
||
| 100 | private function calculateColumnAverage(array &$column) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Get time spent for each column for a given task. |
||
| 109 | * |
||
| 110 | * @param array $task |
||
| 111 | * |
||
| 112 | * @return array |
||
| 113 | */ |
||
| 114 | private function getTaskTimeByColumns(array &$task) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Calculate time spent of a task in the current column. |
||
| 129 | * |
||
| 130 | * @param array $task |
||
| 131 | * |
||
| 132 | * @return int |
||
| 133 | */ |
||
| 134 | private function getTaskTimeSpentInCurrentColumn(array &$task) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Fetch the last 1000 tasks. |
||
| 143 | * |
||
| 144 | * @param int $project_id |
||
| 145 | * |
||
| 146 | * @return array |
||
| 147 | */ |
||
| 148 | View Code Duplication | private function getTasks($project_id) |
|
| 158 | } |
||
| 159 |
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.