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 |
||
11 | class DutyUsers extends DutyHelper |
||
12 | { |
||
13 | public function __construct(Duty $duty) |
||
17 | |||
18 | /** |
||
19 | * Generate a collection to be used for our view 'duty.show'. |
||
20 | * |
||
21 | * @return Collection |
||
22 | */ |
||
23 | public function htmlOutput() |
||
43 | |||
44 | /** |
||
45 | * Generate a collection to be used for emails. View is either emails.duty_future or emails.duty_today. |
||
46 | * |
||
47 | * @return \Illuminate\Support\Collection |
||
48 | */ |
||
49 | public function emailOutput() |
||
60 | |||
61 | /** |
||
62 | * Get function for the list. List is stored on the helper class. |
||
63 | * |
||
64 | * @return Collection |
||
65 | */ |
||
66 | public function getList() |
||
70 | |||
71 | /** |
||
72 | * Grab the next user to work the duty roster and record them in our database so they are the current worker. |
||
73 | */ |
||
74 | View Code Duplication | public function recordNextEntry() |
|
83 | |||
84 | /** |
||
85 | * Get the current user in our database who is working the duty roster. |
||
86 | * |
||
87 | * @return DutyUsers |
||
88 | */ |
||
89 | public function getLastWorked() |
||
95 | |||
96 | /** |
||
97 | * Get a list of all users for a specific duty sorted by the user's last name. |
||
98 | * |
||
99 | * @return DutyUsers |
||
100 | */ |
||
101 | public function queryList() |
||
107 | |||
108 | /** |
||
109 | * Take our list of users and merge them with dates so that each user is assigned a duty date. |
||
110 | * |
||
111 | * @return DutyUsers |
||
112 | */ |
||
113 | public function combineListWithDates() |
||
134 | |||
135 | /** |
||
136 | * Query a list of users who we swapped around and insert them into our current duty list of users. |
||
137 | */ |
||
138 | public function insertFromDutySwap() |
||
161 | |||
162 | /** |
||
163 | * Convert the list of users into a collection of date and users |
||
164 | */ |
||
165 | private function convertListToCollection() |
||
177 | } |
||
178 |