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 UserNotificationModel extends Model |
||
21 | { |
||
22 | /** |
||
23 | * Send notifications to people. |
||
24 | * |
||
25 | * @param string $event_name |
||
26 | * @param array $event_data |
||
27 | */ |
||
28 | public function sendNotifications($event_name, array $event_data) |
||
38 | |||
39 | /** |
||
40 | * Send notification to someone. |
||
41 | * |
||
42 | * @param array $user User |
||
43 | * @param string $event_name |
||
44 | * @param array $event_data |
||
45 | */ |
||
46 | public function sendUserNotification(array $user, $event_name, array $event_data) |
||
64 | |||
65 | /** |
||
66 | * Get a list of people with notifications enabled. |
||
67 | * |
||
68 | * @param int $project_id Project id |
||
69 | * @param int $exclude_user_id User id to exclude |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | public function getUsersWithNotificationEnabled($project_id, $exclude_user_id = 0) |
||
91 | |||
92 | /** |
||
93 | * Enable notification for someone. |
||
94 | * |
||
95 | * @param int $user_id |
||
96 | * |
||
97 | * @return bool |
||
98 | */ |
||
99 | public function enableNotification($user_id) |
||
103 | |||
104 | /** |
||
105 | * Disable notification for someone. |
||
106 | * |
||
107 | * @param int $user_id |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function disableNotification($user_id) |
||
115 | |||
116 | /** |
||
117 | * Save settings for the given user. |
||
118 | * |
||
119 | * @param int $user_id User id |
||
120 | * @param array $values Form values |
||
121 | */ |
||
122 | public function saveSettings($user_id, array $values) |
||
139 | |||
140 | /** |
||
141 | * Read user settings to display the form. |
||
142 | * |
||
143 | * @param int $user_id User id |
||
144 | * |
||
145 | * @return array |
||
146 | */ |
||
147 | public function readSettings($user_id) |
||
155 | |||
156 | /** |
||
157 | * Get a list of project members with notification enabled. |
||
158 | * |
||
159 | * @param int $project_id Project id |
||
160 | * @param int $exclude_user_id User id to exclude |
||
161 | * |
||
162 | * @return array |
||
163 | */ |
||
164 | View Code Duplication | private function getProjectUserMembersWithNotificationEnabled($project_id, $exclude_user_id) |
|
176 | |||
177 | /** |
||
178 | * Get a list of group members with notification enabled. |
||
179 | * |
||
180 | * @param int $project_id Project id |
||
181 | * @param int $exclude_user_id User id to exclude |
||
182 | * |
||
183 | * @return array |
||
184 | */ |
||
185 | private function getProjectGroupMembersWithNotificationEnabled($project_id, $exclude_user_id) |
||
198 | |||
199 | /** |
||
200 | * Get a list of project members with notification enabled. |
||
201 | * |
||
202 | * @param int $exclude_user_id User id to exclude |
||
203 | * |
||
204 | * @return array |
||
205 | */ |
||
206 | View Code Duplication | private function getEverybodyWithNotificationEnabled($exclude_user_id) |
|
216 | } |
||
217 |
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.