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 |
||
8 | class PulseUpdate extends ApiObject |
||
9 | { |
||
10 | /** |
||
11 | * User who wrote the update. |
||
12 | * |
||
13 | * @var array|PulseUser |
||
14 | */ |
||
15 | protected $user; |
||
16 | |||
17 | /** |
||
18 | * The resource's URL. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $url; |
||
23 | |||
24 | /** |
||
25 | * The update's id. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $id; |
||
30 | |||
31 | /** |
||
32 | * The update's body. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $body; |
||
37 | |||
38 | /** |
||
39 | * The update's body in plain text |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $body_text; |
||
44 | |||
45 | /** |
||
46 | * The replies made to this update. |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $replies; |
||
51 | |||
52 | /** |
||
53 | * The update's kind. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $kind; |
||
58 | |||
59 | /** |
||
60 | * The update's has_assets. |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $has_assets; |
||
65 | |||
66 | /** |
||
67 | * The update's assets. |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $assets; |
||
72 | |||
73 | /** |
||
74 | * The users who watch this update. |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $watched; |
||
79 | |||
80 | /** |
||
81 | * Creation time. |
||
82 | * |
||
83 | * @var \DateTime |
||
84 | */ |
||
85 | protected $created_at; |
||
86 | |||
87 | /** |
||
88 | * Last update time. |
||
89 | * |
||
90 | * @var \DateTime |
||
91 | */ |
||
92 | protected $updated_at; |
||
93 | |||
94 | // ================================================================================================================= |
||
95 | // Getter functions |
||
96 | // ================================================================================================================= |
||
97 | |||
98 | /** |
||
99 | * User who wrote the update. |
||
100 | * |
||
101 | * @return PulseUser |
||
102 | */ |
||
103 | public function getUser() |
||
109 | |||
110 | /** |
||
111 | * The resource's URL. |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | public function getUrl() |
||
119 | |||
120 | /** |
||
121 | * The update's id. |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | public function getId() |
||
129 | |||
130 | /** |
||
131 | * The update's body. |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getBody() |
||
139 | |||
140 | /** |
||
141 | * The update's body in plain text |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | public function getBodyText() |
||
149 | |||
150 | /** |
||
151 | * The replies made to this update. |
||
152 | * |
||
153 | * @return static[] |
||
154 | */ |
||
155 | public function getReplies() |
||
161 | |||
162 | /** |
||
163 | * The update's kind. |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | public function getKind() |
||
171 | |||
172 | /** |
||
173 | * The update's has_assets. |
||
174 | * |
||
175 | * @return string |
||
176 | */ |
||
177 | public function getHasAssets() |
||
181 | |||
182 | /** |
||
183 | * The update's assets. |
||
184 | * |
||
185 | * @return string |
||
186 | */ |
||
187 | public function getAssets() |
||
191 | |||
192 | /** |
||
193 | * Creation time. |
||
194 | * |
||
195 | * @return \DateTime |
||
196 | */ |
||
197 | public function getCreatedAt() |
||
203 | |||
204 | /** |
||
205 | * Last update time. |
||
206 | * |
||
207 | * @return \DateTime |
||
208 | */ |
||
209 | public function getUpdatedAt() |
||
215 | |||
216 | /** |
||
217 | * Get the users watching this update |
||
218 | * |
||
219 | * @return PulseUser[] |
||
220 | */ |
||
221 | public function getWatchers () |
||
227 | |||
228 | // ================================================================================================================= |
||
229 | // Modification functions |
||
230 | // ================================================================================================================= |
||
231 | |||
232 | /** |
||
233 | * Delete this update |
||
234 | * |
||
235 | * @api |
||
236 | * |
||
237 | * @since 0.1.0 |
||
238 | * |
||
239 | * @throws InvalidObjectException This PulseUpdate as already been deleted |
||
240 | */ |
||
241 | View Code Duplication | public function deleteUpdate() |
|
250 | |||
251 | // ================================================================================================================= |
||
252 | // Liking functions |
||
253 | // ================================================================================================================= |
||
254 | |||
255 | /** |
||
256 | * Have a user like an update |
||
257 | * |
||
258 | * @api |
||
259 | * |
||
260 | * @param int|PulseUser $user The user that will be liking/un-liking the update |
||
261 | * |
||
262 | * @since 0.1.0 |
||
263 | */ |
||
264 | public function likeUpdate ($user) |
||
268 | |||
269 | /** |
||
270 | * Have a user unlike an update |
||
271 | * |
||
272 | * @api |
||
273 | * |
||
274 | * @param int|PulseUser $user The user that will be liking/un-liking the update |
||
275 | * |
||
276 | * @since 0.1.0 |
||
277 | */ |
||
278 | public function unlikeUpdate ($user) |
||
282 | |||
283 | /** |
||
284 | * Like and un-liking functionality |
||
285 | * |
||
286 | * @param int|PulseUser $user The user that will be liking/un-liking the update |
||
287 | * @param bool $like True to like the update, false to unlike |
||
288 | */ |
||
289 | View Code Duplication | private function likeUnlikeUpdate ($user, $like) |
|
303 | |||
304 | // ================================================================================================================= |
||
305 | // PulseUpdate functions |
||
306 | // ================================================================================================================= |
||
307 | |||
308 | /** |
||
309 | * Get all of the account's updates (ordered from new to old) |
||
310 | * |
||
311 | * @api |
||
312 | * |
||
313 | * @param array $params GET parameters passed to the URL |
||
314 | * |
||
315 | * @since 0.1.0 |
||
316 | * |
||
317 | * @return PulseUpdate[] |
||
318 | */ |
||
319 | public static function getUpdates ($params = array()) |
||
325 | |||
326 | /** |
||
327 | * Create a new update |
||
328 | * |
||
329 | * @api |
||
330 | * |
||
331 | * @param int|PulseUser $user The author of this post |
||
332 | * @param int|Pulse $pulse The Pulse to whom this update will belong to |
||
333 | * @param string $text The content of the update |
||
334 | * @param null|bool $announceToAll Whether or not to announce this update to everyone's wall |
||
335 | * |
||
336 | * @since 0.1.0 |
||
337 | * |
||
338 | * @return PulseUpdate |
||
339 | */ |
||
340 | public static function createUpdate ($user, $pulse, $text, $announceToAll = NULL) |
||
365 | } |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.