Conditions | 1 |
Paths | 1 |
Total Lines | 258 |
Code Lines | 255 |
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 |
||
307 | function printcenter_get_countries() { |
||
308 | $countries = array( |
||
309 | 'US' => 'United States', |
||
310 | 'CA' => 'Canada', |
||
311 | 'GB' => 'United Kingdom', |
||
312 | 'AF' => 'Afghanistan', |
||
313 | 'AX' => 'Åland Islands', |
||
314 | 'AL' => 'Albania', |
||
315 | 'DZ' => 'Algeria', |
||
316 | 'AS' => 'American Samoa', |
||
317 | 'AD' => 'Andorra', |
||
318 | 'AO' => 'Angola', |
||
319 | 'AI' => 'Anguilla', |
||
320 | 'AQ' => 'Antarctica', |
||
321 | 'AG' => 'Antigua and Barbuda', |
||
322 | 'AR' => 'Argentina', |
||
323 | 'AM' => 'Armenia', |
||
324 | 'AW' => 'Aruba', |
||
325 | 'AU' => 'Australia', |
||
326 | 'AT' => 'Austria', |
||
327 | 'AZ' => 'Azerbaijan', |
||
328 | 'BS' => 'Bahamas', |
||
329 | 'BH' => 'Bahrain', |
||
330 | 'BD' => 'Bangladesh', |
||
331 | 'BB' => 'Barbados', |
||
332 | 'BY' => 'Belarus', |
||
333 | 'BE' => 'Belgium', |
||
334 | 'BZ' => 'Belize', |
||
335 | 'BJ' => 'Benin', |
||
336 | 'BM' => 'Bermuda', |
||
337 | 'BT' => 'Bhutan', |
||
338 | 'BO' => 'Bolivia', |
||
339 | 'BQ' => 'Bonaire, Saint Eustatius and Saba', |
||
340 | 'BA' => 'Bosnia and Herzegovina', |
||
341 | 'BW' => 'Botswana', |
||
342 | 'BV' => 'Bouvet Island', |
||
343 | 'BR' => 'Brazil', |
||
344 | 'IO' => 'British Indian Ocean Territory', |
||
345 | 'BN' => 'Brunei Darrussalam', |
||
346 | 'BG' => 'Bulgaria', |
||
347 | 'BF' => 'Burkina Faso', |
||
348 | 'BI' => 'Burundi', |
||
349 | 'KH' => 'Cambodia', |
||
350 | 'CM' => 'Cameroon', |
||
351 | 'CV' => 'Cape Verde', |
||
352 | 'KY' => 'Cayman Islands', |
||
353 | 'CF' => 'Central African Republic', |
||
354 | 'TD' => 'Chad', |
||
355 | 'CL' => 'Chile', |
||
356 | 'CN' => 'China', |
||
357 | 'CX' => 'Christmas Island', |
||
358 | 'CC' => 'Cocos Islands', |
||
359 | 'CO' => 'Colombia', |
||
360 | 'KM' => 'Comoros', |
||
361 | 'CD' => 'Congo, Democratic People\'s Republic', |
||
362 | 'CG' => 'Congo, Republic of', |
||
363 | 'CK' => 'Cook Islands', |
||
364 | 'CR' => 'Costa Rica', |
||
365 | 'CI' => 'Cote d\'Ivoire', |
||
366 | 'HR' => 'Croatia/Hrvatska', |
||
367 | 'CU' => 'Cuba', |
||
368 | 'CW' => 'CuraÇao', |
||
369 | 'CY' => 'Cyprus', |
||
370 | 'CZ' => 'Czech Republic', |
||
371 | 'DK' => 'Denmark', |
||
372 | 'DJ' => 'Djibouti', |
||
373 | 'DM' => 'Dominica', |
||
374 | 'DO' => 'Dominican Republic', |
||
375 | 'TP' => 'East Timor', |
||
376 | 'EC' => 'Ecuador', |
||
377 | 'EG' => 'Egypt', |
||
378 | 'GQ' => 'Equatorial Guinea', |
||
379 | 'SV' => 'El Salvador', |
||
380 | 'ER' => 'Eritrea', |
||
381 | 'EE' => 'Estonia', |
||
382 | 'ET' => 'Ethiopia', |
||
383 | 'FK' => 'Falkland Islands', |
||
384 | 'FO' => 'Faroe Islands', |
||
385 | 'FJ' => 'Fiji', |
||
386 | 'FI' => 'Finland', |
||
387 | 'FR' => 'France', |
||
388 | 'GF' => 'French Guiana', |
||
389 | 'PF' => 'French Polynesia', |
||
390 | 'TF' => 'French Southern Territories', |
||
391 | 'GA' => 'Gabon', |
||
392 | 'GM' => 'Gambia', |
||
393 | 'GE' => 'Georgia', |
||
394 | 'DE' => 'Germany', |
||
395 | 'GR' => 'Greece', |
||
396 | 'GH' => 'Ghana', |
||
397 | 'GI' => 'Gibraltar', |
||
398 | 'GL' => 'Greenland', |
||
399 | 'GD' => 'Grenada', |
||
400 | 'GP' => 'Guadeloupe', |
||
401 | 'GU' => 'Guam', |
||
402 | 'GT' => 'Guatemala', |
||
403 | 'GG' => 'Guernsey', |
||
404 | 'GN' => 'Guinea', |
||
405 | 'GW' => 'Guinea-Bissau', |
||
406 | 'GY' => 'Guyana', |
||
407 | 'HT' => 'Haiti', |
||
408 | 'HM' => 'Heard and McDonald Islands', |
||
409 | 'VA' => 'Holy See (City Vatican State)', |
||
410 | 'HN' => 'Honduras', |
||
411 | 'HK' => 'Hong Kong', |
||
412 | 'HU' => 'Hungary', |
||
413 | 'IS' => 'Iceland', |
||
414 | 'IN' => 'India', |
||
415 | 'ID' => 'Indonesia', |
||
416 | 'IR' => 'Iran', |
||
417 | 'IQ' => 'Iraq', |
||
418 | 'IE' => 'Ireland', |
||
419 | 'IM' => 'Isle of Man', |
||
420 | 'IL' => 'Israel', |
||
421 | 'IT' => 'Italy', |
||
422 | 'JM' => 'Jamaica', |
||
423 | 'JP' => 'Japan', |
||
424 | 'JE' => 'Jersey', |
||
425 | 'JO' => 'Jordan', |
||
426 | 'KZ' => 'Kazakhstan', |
||
427 | 'KE' => 'Kenya', |
||
428 | 'KI' => 'Kiribati', |
||
429 | 'KW' => 'Kuwait', |
||
430 | 'KG' => 'Kyrgyzstan', |
||
431 | 'LA' => 'Lao People\'s Democratic Republic', |
||
432 | 'LV' => 'Latvia', |
||
433 | 'LB' => 'Lebanon', |
||
434 | 'LS' => 'Lesotho', |
||
435 | 'LR' => 'Liberia', |
||
436 | 'LY' => 'Libyan Arab Jamahiriya', |
||
437 | 'LI' => 'Liechtenstein', |
||
438 | 'LT' => 'Lithuania', |
||
439 | 'LU' => 'Luxembourg', |
||
440 | 'MO' => 'Macau', |
||
441 | 'MK' => 'Macedonia', |
||
442 | 'MG' => 'Madagascar', |
||
443 | 'MW' => 'Malawi', |
||
444 | 'MY' => 'Malaysia', |
||
445 | 'MV' => 'Maldives', |
||
446 | 'ML' => 'Mali', |
||
447 | 'MT' => 'Malta', |
||
448 | 'MH' => 'Marshall Islands', |
||
449 | 'MQ' => 'Martinique', |
||
450 | 'MR' => 'Mauritania', |
||
451 | 'MU' => 'Mauritius', |
||
452 | 'YT' => 'Mayotte', |
||
453 | 'MX' => 'Mexico', |
||
454 | 'FM' => 'Micronesia', |
||
455 | 'MD' => 'Moldova, Republic of', |
||
456 | 'MC' => 'Monaco', |
||
457 | 'MN' => 'Mongolia', |
||
458 | 'ME' => 'Montenegro', |
||
459 | 'MS' => 'Montserrat', |
||
460 | 'MA' => 'Morocco', |
||
461 | 'MZ' => 'Mozambique', |
||
462 | 'MM' => 'Myanmar', |
||
463 | 'NA' => 'Namibia', |
||
464 | 'NR' => 'Nauru', |
||
465 | 'NP' => 'Nepal', |
||
466 | 'NL' => 'Netherlands', |
||
467 | 'AN' => 'Netherlands Antilles', |
||
468 | 'NC' => 'New Caledonia', |
||
469 | 'NZ' => 'New Zealand', |
||
470 | 'NI' => 'Nicaragua', |
||
471 | 'NE' => 'Niger', |
||
472 | 'NG' => 'Nigeria', |
||
473 | 'NU' => 'Niue', |
||
474 | 'NF' => 'Norfolk Island', |
||
475 | 'KR' => 'North Korea', |
||
476 | 'MP' => 'Northern Mariana Islands', |
||
477 | 'NO' => 'Norway', |
||
478 | 'OM' => 'Oman', |
||
479 | 'PK' => 'Pakistan', |
||
480 | 'PW' => 'Palau', |
||
481 | 'PS' => 'Palestinian Territories', |
||
482 | 'PA' => 'Panama', |
||
483 | 'PG' => 'Papua New Guinea', |
||
484 | 'PY' => 'Paraguay', |
||
485 | 'PE' => 'Peru', |
||
486 | 'PH' => 'Phillipines', |
||
487 | 'PN' => 'Pitcairn Island', |
||
488 | 'PL' => 'Poland', |
||
489 | 'PT' => 'Portugal', |
||
490 | 'PR' => 'Puerto Rico', |
||
491 | 'QA' => 'Qatar', |
||
492 | 'XK' => 'Republic of Kosovo', |
||
493 | 'RE' => 'Reunion Island', |
||
494 | 'RO' => 'Romania', |
||
495 | 'RU' => 'Russian Federation', |
||
496 | 'RW' => 'Rwanda', |
||
497 | 'BL' => 'Saint Barthélemy', |
||
498 | 'SH' => 'Saint Helena', |
||
499 | 'KN' => 'Saint Kitts and Nevis', |
||
500 | 'LC' => 'Saint Lucia', |
||
501 | 'MF' => 'Saint Martin (French)', |
||
502 | 'SX' => 'Saint Martin (Dutch)', |
||
503 | 'PM' => 'Saint Pierre and Miquelon', |
||
504 | 'VC' => 'Saint Vincent and the Grenadines', |
||
505 | 'SM' => 'San Marino', |
||
506 | 'ST' => 'São Tomé and Príncipe', |
||
507 | 'SA' => 'Saudi Arabia', |
||
508 | 'SN' => 'Senegal', |
||
509 | 'RS' => 'Serbia', |
||
510 | 'SC' => 'Seychelles', |
||
511 | 'SL' => 'Sierra Leone', |
||
512 | 'SG' => 'Singapore', |
||
513 | 'SK' => 'Slovak Republic', |
||
514 | 'SI' => 'Slovenia', |
||
515 | 'SB' => 'Solomon Islands', |
||
516 | 'SO' => 'Somalia', |
||
517 | 'ZA' => 'South Africa', |
||
518 | 'GS' => 'South Georgia', |
||
519 | 'KP' => 'South Korea', |
||
520 | 'SS' => 'South Sudan', |
||
521 | 'ES' => 'Spain', |
||
522 | 'LK' => 'Sri Lanka', |
||
523 | 'SD' => 'Sudan', |
||
524 | 'SR' => 'Suriname', |
||
525 | 'SJ' => 'Svalbard and Jan Mayen Islands', |
||
526 | 'SZ' => 'Swaziland', |
||
527 | 'SE' => 'Sweden', |
||
528 | 'CH' => 'Switzerland', |
||
529 | 'SY' => 'Syrian Arab Republic', |
||
530 | 'TW' => 'Taiwan', |
||
531 | 'TJ' => 'Tajikistan', |
||
532 | 'TZ' => 'Tanzania', |
||
533 | 'TH' => 'Thailand', |
||
534 | 'TL' => 'Timor-Leste', |
||
535 | 'TG' => 'Togo', |
||
536 | 'TK' => 'Tokelau', |
||
537 | 'TO' => 'Tonga', |
||
538 | 'TT' => 'Trinidad and Tobago', |
||
539 | 'TN' => 'Tunisia', |
||
540 | 'TR' => 'Turkey', |
||
541 | 'TM' => 'Turkmenistan', |
||
542 | 'TC' => 'Turks and Caicos Islands', |
||
543 | 'TV' => 'Tuvalu', |
||
544 | 'UG' => 'Uganda', |
||
545 | 'UA' => 'Ukraine', |
||
546 | 'AE' => 'United Arab Emirates', |
||
547 | 'UY' => 'Uruguay', |
||
548 | 'UM' => 'US Minor Outlying Islands', |
||
549 | 'UZ' => 'Uzbekistan', |
||
550 | 'VU' => 'Vanuatu', |
||
551 | 'VE' => 'Venezuela', |
||
552 | 'VN' => 'Vietnam', |
||
553 | 'VG' => 'Virgin Islands (British)', |
||
554 | 'VI' => 'Virgin Islands (USA)', |
||
555 | 'WF' => 'Wallis and Futuna Islands', |
||
556 | 'EH' => 'Western Sahara', |
||
557 | 'WS' => 'Western Samoa', |
||
558 | 'YE' => 'Yemen', |
||
559 | 'ZM' => 'Zambia', |
||
560 | 'ZW' => 'Zimbabwe' |
||
561 | ); |
||
562 | |||
563 | return $countries; |
||
564 | } |
||
565 | |||
602 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.