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 DashboardController extends Controller |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Dashboard overview. |
||
| 23 | */ |
||
| 24 | public function index() |
||
| 31 | |||
| 32 | /** |
||
| 33 | * My tasks. |
||
| 34 | */ |
||
| 35 | View Code Duplication | public function tasks() |
|
| 36 | { |
||
| 37 | $user = $this->getUser(); |
||
| 38 | |||
| 39 | $this->response->html($this->helper->layout->dashboard('dashboard/tasks', [ |
||
| 40 | 'title' => t('My tasks'), |
||
| 41 | 'paginator' => $this->taskPagination->getDashboardPaginator($user['id'], 'tasks', 50), |
||
| 42 | 'user' => $user, |
||
| 43 | ])); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * My subtasks. |
||
| 48 | */ |
||
| 49 | View Code Duplication | public function subtasks() |
|
| 50 | { |
||
| 51 | $user = $this->getUser(); |
||
| 52 | |||
| 53 | $this->response->html($this->helper->layout->dashboard('dashboard/subtasks', [ |
||
| 54 | 'title' => t('My subtasks'), |
||
| 55 | 'paginator' => $this->subtaskPagination->getDashboardPaginator($user['id'], 'subtasks', 50), |
||
| 56 | 'user' => $user, |
||
| 57 | ])); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * My activities. |
||
| 62 | */ |
||
| 63 | View Code Duplication | public function activities() |
|
| 64 | { |
||
| 65 | $user = $this->getUser(); |
||
| 66 | |||
| 67 | $this->response->html($this->helper->layout->dashboard('dashboard/activities', [ |
||
| 68 | 'title' => t('My activities'), |
||
| 69 | 'events' => $this->helper->projectActivity->getProjectsEvents($this->projectPermissionModel->getActiveProjectIds($user['id']), 100), |
||
| 70 | 'user' => $user, |
||
| 71 | ])); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * My calendar. |
||
| 76 | */ |
||
| 77 | View Code Duplication | public function calendar() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * My slider. |
||
| 89 | */ |
||
| 90 | View Code Duplication | public function slider() |
|
| 100 | } |
||
| 101 |
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.