Conditions | 55 |
Paths | 216 |
Total Lines | 245 |
Code Lines | 190 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
148 | private function newVCard( $row, $uri, $text, $timestamp, $isPublic ) { |
||
149 | |||
150 | // name |
||
151 | $prefix = ''; // something like 'Dr.' |
||
152 | $firstname = ''; // given name |
||
153 | $additionalname = ''; // typically the "middle" name (second first name) |
||
154 | $lastname = ''; // family name |
||
155 | $suffix = ''; // things like "jun." or "sen." |
||
156 | $fullname = ''; // the "formatted name", may be independent from first/lastname & co. |
||
157 | // contacts |
||
158 | $emails = []; |
||
159 | $tels = []; |
||
160 | $addresses = []; |
||
161 | // organisational details: |
||
162 | $organization = ''; // any string |
||
163 | $jobtitle = ''; |
||
164 | $role = ''; |
||
165 | $department = ''; |
||
166 | // other stuff |
||
167 | $category = ''; |
||
168 | $birthday = ''; // a date |
||
169 | $url = ''; // homepage, a legal URL |
||
170 | $note = ''; // any text |
||
171 | $workaddress = false; |
||
172 | $homeaddress = false; |
||
173 | |||
174 | $workpostofficebox = ''; |
||
175 | $workextendedaddress = ''; |
||
176 | $workstreet = ''; |
||
177 | $worklocality = ''; |
||
178 | $workregion = ''; |
||
179 | $workpostalcode = ''; |
||
180 | $workcountry = ''; |
||
181 | |||
182 | $homepostofficebox = ''; |
||
183 | $homeextendedaddress = ''; |
||
184 | $homestreet = ''; |
||
185 | $homelocality = ''; |
||
186 | $homeregion = ''; |
||
187 | $homepostalcode = ''; |
||
188 | $homecountry = ''; |
||
189 | |||
190 | foreach ( $row as $field ) { |
||
191 | // later we may add more things like a generic |
||
192 | // mechanism to add non-standard vCard properties as well |
||
193 | // (could include funny things like geo, description etc.) |
||
194 | $req = $field->getPrintRequest(); |
||
195 | |||
196 | switch( strtolower( $req->getLabel() ) ) { |
||
197 | case "name": |
||
198 | $fullname = $this->getFieldValue( $field ); |
||
199 | break; |
||
200 | case "prefix": |
||
201 | $prefix = $this->getFieldCommaList( $field ); |
||
202 | break; |
||
203 | case "suffix": |
||
204 | $suffix = $this->getFieldCommaList( $field ); |
||
205 | break; |
||
206 | case "firstname": |
||
207 | // save only the first |
||
208 | $firstname = $this->getFieldValue( $field ); |
||
209 | break; |
||
210 | case "extraname": |
||
211 | $additionalname = $this->getFieldCommaList( $field ); |
||
212 | break; |
||
213 | case "lastname": |
||
214 | // save only the first |
||
215 | $lastname = $this->getFieldValue( $field ); |
||
216 | break; |
||
217 | case "note": |
||
218 | $note = $this->getFieldCommaList( $field ); |
||
219 | break; |
||
220 | case "category": |
||
221 | $category = $this->getFieldCommaList( $field ); |
||
222 | case "email": |
||
223 | while( $value = $field->getNextDataValue() ) { |
||
224 | $emails[] = new Email( 'INTERNET', $value->getShortWikiText() ); |
||
225 | } |
||
226 | break; |
||
227 | case "workphone": |
||
228 | while( $value = $field->getNextDataValue() ) { |
||
229 | $tels[] = new Tel( 'WORK', $value->getShortWikiText() ); |
||
230 | } |
||
231 | break; |
||
232 | case "cellphone": |
||
233 | while( $value = $field->getNextDataValue() ) { |
||
234 | $tels[] = new Tel( 'CELL', $value->getShortWikiText() ); |
||
235 | } |
||
236 | break; |
||
237 | case "homephone": |
||
238 | while( $value = $field->getNextDataValue() ) { |
||
239 | $tels[] = new Tel( 'HOME', $value->getShortWikiText() ); |
||
240 | } |
||
241 | break; |
||
242 | case "organization": |
||
243 | $organization = $this->getFieldValue( $field ); |
||
244 | break; |
||
245 | case "workpostofficebox": |
||
246 | if ( ( $workpostofficebox = $this->getFieldValue( $field ) ) !== '' ) { |
||
247 | $workaddress = true; |
||
248 | } |
||
249 | break; |
||
250 | case "workextendedaddress": |
||
251 | if ( ( $workextendedaddress = $this->getFieldValue( $field ) ) !== '' ) { |
||
252 | $workaddress = true; |
||
253 | } |
||
254 | break; |
||
255 | case "workstreet": |
||
256 | if ( ( $workstreet = $this->getFieldValue( $field ) ) !== '' ) { |
||
257 | $workaddress = true; |
||
258 | } |
||
259 | break; |
||
260 | case "worklocality": |
||
261 | if ( ( $worklocality = $this->getFieldValue( $field ) ) !== '' ) { |
||
262 | $workaddress = true; |
||
263 | } |
||
264 | break; |
||
265 | case "workregion": |
||
266 | if ( ( $workregion = $this->getFieldValue( $field ) ) !== '' ) { |
||
267 | $workaddress = true; |
||
268 | } |
||
269 | break; |
||
270 | case "workpostalcode": |
||
271 | if ( ( $workpostalcode = $this->getFieldValue( $field ) ) !== '' ) { |
||
272 | $workaddress = true; |
||
273 | } |
||
274 | break; |
||
275 | case "workcountry": |
||
276 | if ( ( $workcountry = $this->getFieldValue( $field ) ) !== '' ) { |
||
277 | $workaddress = true; |
||
278 | } |
||
279 | break; |
||
280 | case "homepostofficebox": |
||
281 | if ( ( $homepostofficebox = $this->getFieldValue( $field ) ) !== '' ) { |
||
282 | $homeaddress = true; |
||
283 | } |
||
284 | break; |
||
285 | case "homeextendedaddress": |
||
286 | if ( ( $homeextendedaddress = $this->getFieldValue( $field ) ) !== '' ) { |
||
287 | $homeaddress = true; |
||
288 | } |
||
289 | break; |
||
290 | case "homestreet": |
||
291 | if ( ( $homestreet = $this->getFieldValue( $field ) ) !== '' ) { |
||
292 | $homeaddress = true; |
||
293 | } |
||
294 | break; |
||
295 | case "homelocality": |
||
296 | if ( ( $homelocality = $this->getFieldValue( $field ) ) !== '' ) { |
||
297 | $homeaddress = true; |
||
298 | } |
||
299 | break; |
||
300 | case "homeregion": |
||
301 | if ( ( $homeregion = $this->getFieldValue( $field ) ) !== '' ) { |
||
302 | $homeaddress = true; |
||
303 | } |
||
304 | break; |
||
305 | case "homepostalcode": |
||
306 | if ( ( $homepostalcode = $this->getFieldValue( $field ) ) !== '' ) { |
||
307 | $homeaddress = true; |
||
308 | } |
||
309 | break; |
||
310 | case "homecountry": |
||
311 | if ( ( $homecountry = $this->getFieldValue( $field ) ) !== '' ) { |
||
312 | $homeaddress = true; |
||
313 | } |
||
314 | break; |
||
315 | case "birthday": |
||
316 | if ( $req->getTypeID() == TimeValue::TYPE_ID ) { |
||
317 | $value = $field->getNextDataValue(); |
||
318 | if ( $value !== false ) { |
||
319 | $birthday = $value->getISO8601Date(); |
||
320 | } |
||
321 | } |
||
322 | break; |
||
323 | case "homepage": |
||
324 | if ( $req->getTypeID() == "_uri" ) { |
||
325 | $value = $field->getNextDataValue(); |
||
326 | if ( $value !== false ) { |
||
327 | $url = $value->getWikiValue(); |
||
328 | } |
||
329 | } |
||
330 | break; |
||
331 | } |
||
332 | } |
||
333 | |||
334 | if ( $workaddress ) { |
||
335 | $addresses[] = new Address ( |
||
336 | 'WORK', |
||
337 | [ |
||
338 | 'pobox' => $workpostofficebox, |
||
339 | 'ext' => $workextendedaddress, |
||
340 | 'street' => $workstreet, |
||
341 | 'locality' => $worklocality, |
||
342 | 'region' => $workregion, |
||
343 | 'code' => $workpostalcode, |
||
344 | 'country' => $workcountry |
||
345 | ] |
||
346 | ); |
||
347 | } |
||
348 | |||
349 | if ( $homeaddress ) { |
||
350 | $addresses[] = new Address ( |
||
351 | 'HOME', |
||
352 | [ |
||
353 | 'pobox' => $homepostofficebox, |
||
354 | 'ext' => $homeextendedaddress, |
||
355 | 'street' => $homestreet, |
||
356 | 'locality' => $homelocality, |
||
357 | 'region' => $homeregion, |
||
358 | 'code' => $homepostalcode, |
||
359 | 'country' => $homecountry |
||
360 | ] |
||
361 | ); |
||
362 | } |
||
363 | |||
364 | $vCard = new vCard( |
||
365 | $uri, |
||
366 | $text, |
||
367 | [ |
||
368 | 'prefix' => $prefix, |
||
369 | 'firstname' => $firstname, |
||
370 | 'lastname' => $lastname, |
||
371 | 'additionalname' => $additionalname, |
||
372 | 'suffix' => $suffix, |
||
373 | 'fullname' => $fullname, |
||
374 | 'tel' => $tels, |
||
375 | 'address' => $addresses, |
||
376 | 'email' => $emails, |
||
377 | 'birthday' => $birthday, |
||
378 | 'title' => $jobtitle, |
||
379 | 'role' => $role, |
||
380 | 'organization' => $organization, |
||
381 | 'department' => $department, |
||
382 | 'category' => $category, |
||
383 | 'url' => $url, |
||
384 | 'note' => $note |
||
385 | ] |
||
386 | ); |
||
387 | |||
388 | $vCard->isPublic( $isPublic ); |
||
389 | $vCard->setTimestamp( $timestamp ); |
||
390 | |||
391 | return $vCard; |
||
392 | } |
||
393 | |||
428 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.