Conditions | 9 |
Paths | 20 |
Total Lines | 247 |
Code Lines | 180 |
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 |
||
360 | public static function data_currencies() { |
||
361 | |||
362 | // If it's already done, do not redo the filter |
||
363 | if ( ! empty( static::$currencies ) ) { |
||
364 | return static::$currencies; |
||
365 | } |
||
366 | |||
367 | $default_currencies = array( |
||
368 | 'aud' => array( |
||
369 | 'label' => 'AUD', |
||
370 | 'name' => __( 'Australian Dollar', 'pods' ), |
||
371 | 'sign' => '$', |
||
372 | 'entity' => '$', |
||
373 | ), |
||
374 | 'brl' => array( |
||
375 | 'label' => 'BRL', |
||
376 | 'name' => __( 'Brazilian Real', 'pods' ), |
||
377 | 'sign' => 'R$', |
||
378 | 'entity' => 'R$', |
||
379 | ), |
||
380 | 'cad' => array( |
||
381 | 'label' => 'CAD', |
||
382 | 'name' => __( 'Canadian Dollar', 'pods' ), |
||
383 | 'sign' => '$', |
||
384 | 'entity' => '$', |
||
385 | ), |
||
386 | 'chf' => array( |
||
387 | 'label' => 'CHF', |
||
388 | 'name' => __( 'Swiss Franc', 'pods' ), |
||
389 | 'sign' => 'Fr', |
||
390 | 'entity' => 'Fr', |
||
391 | ), |
||
392 | 'cny' => array( |
||
393 | 'label' => 'CNY', |
||
394 | 'name' => __( 'Chinese Yuan', 'pods' ), |
||
395 | 'sign' => '¥', |
||
396 | 'entity' => '¥', |
||
397 | ), |
||
398 | 'cny2' => array( |
||
399 | 'label' => 'CNY', |
||
400 | 'name' => __( 'Chinese Yuan', 'pods' ), |
||
401 | 'sign' => '元', |
||
402 | 'entity' => '元', |
||
403 | ), |
||
404 | 'czk' => array( |
||
405 | 'label' => 'CZK', |
||
406 | 'name' => __( 'Czech Koruna', 'pods' ), |
||
407 | 'sign' => 'Kč', |
||
408 | 'entity' => 'Kč', |
||
409 | ), |
||
410 | 'dkk' => array( |
||
411 | 'label' => 'DKK', |
||
412 | 'name' => __( 'Danish Krone', 'pods' ), |
||
413 | 'sign' => 'kr.', |
||
414 | 'entity' => 'kr.', |
||
415 | ), |
||
416 | 'euro' => array( |
||
417 | 'label' => 'EUR', |
||
418 | 'name' => __( 'Euro', 'pods' ), |
||
419 | 'sign' => '€', |
||
420 | 'entity' => '€', |
||
421 | ), |
||
422 | 'gbp' => array( |
||
423 | 'label' => 'GBP', |
||
424 | 'name' => __( 'British Pound', 'pods' ), |
||
425 | 'sign' => '£', |
||
426 | 'entity' => '£', |
||
427 | ), |
||
428 | 'hkd' => array( |
||
429 | 'label' => 'HKD', |
||
430 | 'name' => __( 'Hong Kong Dollar', 'pods' ), |
||
431 | 'sign' => '$', |
||
432 | 'entity' => '$', |
||
433 | ), |
||
434 | 'huf' => array( |
||
435 | 'label' => 'HUF', |
||
436 | 'name' => __( 'Hungarian Forint', 'pods' ), |
||
437 | 'sign' => 'Ft', |
||
438 | 'entity' => 'Ft', |
||
439 | ), |
||
440 | 'ils' => array( |
||
441 | 'label' => 'ILS', |
||
442 | 'name' => __( 'Israeli New Sheqel', 'pods' ), |
||
443 | 'sign' => '₪', |
||
444 | 'entity' => '₪', |
||
445 | ), |
||
446 | 'jpy' => array( |
||
447 | 'label' => 'JPY', |
||
448 | 'name' => __( 'Japanese Yen', 'pods' ), |
||
449 | 'sign' => '¥', |
||
450 | 'entity' => '¥', |
||
451 | ), |
||
452 | 'krw' => array( |
||
453 | 'label' => 'KRW', |
||
454 | 'name' => __( 'Korean Won', 'pods' ), |
||
455 | 'sign' => '₩', |
||
456 | 'entity' => '₩', |
||
457 | ), |
||
458 | 'myr' => array( |
||
459 | 'label' => 'MYR', |
||
460 | 'name' => __( 'Malaysian Ringgit', 'pods' ), |
||
461 | 'sign' => 'MR', |
||
462 | 'entity' => 'MR', |
||
463 | ), |
||
464 | 'mxn' => array( |
||
465 | 'label' => 'MXN', |
||
466 | 'name' => __( 'Mexican Peso', 'pods' ), |
||
467 | 'sign' => '$', |
||
468 | 'entity' => '$', |
||
469 | ), |
||
470 | 'nok' => array( |
||
471 | 'label' => 'NOK', |
||
472 | 'name' => __( 'Norwegian Krone', 'pods' ), |
||
473 | 'sign' => 'kr', |
||
474 | 'entity' => 'kr', |
||
475 | ), |
||
476 | 'nzd' => array( |
||
477 | 'label' => 'NZD', |
||
478 | 'name' => __( 'New Zealand Dollar', 'pods' ), |
||
479 | 'sign' => '$', |
||
480 | 'entity' => '$', |
||
481 | ), |
||
482 | 'php' => array( |
||
483 | 'label' => 'PHP', |
||
484 | 'name' => __( 'Philippine Peso', 'pods' ), |
||
485 | 'sign' => '₱', |
||
486 | 'entity' => '₱', |
||
487 | ), |
||
488 | 'pln' => array( |
||
489 | 'label' => 'PLN', |
||
490 | 'name' => __( 'Polish Złoty', 'pods' ), |
||
491 | 'sign' => 'zł', |
||
492 | 'entity' => 'zł', |
||
493 | ), |
||
494 | 'rub' => array( |
||
495 | 'label' => 'RUB', |
||
496 | 'name' => __( 'Russian Ruble', 'pods' ), |
||
497 | 'sign' => '₽', |
||
498 | 'entity' => '₽', |
||
499 | ), |
||
500 | 'sek' => array( |
||
501 | 'label' => 'SEK', |
||
502 | 'name' => __( 'Swedish Krona', 'pods' ), |
||
503 | 'sign' => 'kr', |
||
504 | 'entity' => 'kr', |
||
505 | ), |
||
506 | 'sgd' => array( |
||
507 | 'label' => 'SGD', |
||
508 | 'name' => __( 'Singapore Dollar', 'pods' ), |
||
509 | 'sign' => '$', |
||
510 | 'entity' => '$', |
||
511 | ), |
||
512 | 'thb' => array( |
||
513 | 'label' => 'THB', |
||
514 | 'name' => __( 'Thai Baht', 'pods' ), |
||
515 | 'sign' => '฿', |
||
516 | 'entity' => '฿', |
||
517 | ), |
||
518 | 'trl' => array( |
||
519 | 'label' => 'TRL', |
||
520 | 'name' => __( 'Turkish Lira', 'pods' ), |
||
521 | 'sign' => '₺', |
||
522 | 'entity' => '₺', |
||
523 | ), |
||
524 | 'twd' => array( |
||
525 | 'label' => 'TWD', |
||
526 | 'name' => __( 'Taiwan New Dollar', 'pods' ), |
||
527 | 'sign' => '$', |
||
528 | 'entity' => '$', |
||
529 | ), |
||
530 | 'usd' => array( |
||
531 | 'label' => 'USD', |
||
532 | 'name' => __( 'US Dollar', 'pods' ), |
||
533 | 'sign' => '$', |
||
534 | 'entity' => '$', |
||
535 | ), |
||
536 | 'vnd' => array( |
||
537 | 'label' => 'VND', |
||
538 | 'name' => __( 'Vietnamese Dong', 'pods' ), |
||
539 | 'sign' => '₫', |
||
540 | 'entity' => '₫', |
||
541 | ), |
||
542 | 'zar' => array( |
||
543 | 'label' => 'ZAR', |
||
544 | 'name' => __( 'South African Rand', 'pods' ), |
||
545 | 'sign' => 'R', |
||
546 | 'entity' => 'R', |
||
547 | ), |
||
548 | 'inr' => array( |
||
549 | 'label' => 'INR', |
||
550 | 'name' => __( 'Indian Rupee', 'pods' ), |
||
551 | 'sign' => '₹', |
||
552 | 'entity' => '₹', |
||
553 | ), |
||
554 | ); |
||
555 | |||
556 | /** |
||
557 | * Add custom currencies |
||
558 | * |
||
559 | * @param array $options { |
||
560 | * Required array of arrays. |
||
561 | * |
||
562 | * @type array { |
||
563 | * @type string $label The label (example: USD). |
||
564 | * @type string $name The full name (example: US Dollar). |
||
565 | * @type string $sign The sign (example: $). |
||
566 | * @type string $entity The HTML entity (example: $). |
||
567 | * } |
||
568 | * } |
||
569 | * @return array |
||
570 | */ |
||
571 | static::$currencies = apply_filters( 'pods_form_ui_field_currency_currencies', $default_currencies ); |
||
572 | |||
573 | // Sort the currencies |
||
574 | ksort( static::$currencies ); |
||
575 | |||
576 | // Backwards compatibility |
||
577 | foreach ( static::$currencies as $key => $value ) { |
||
578 | if ( is_string( $value ) ) { |
||
579 | static::$currencies[ $key ] = array( |
||
580 | 'label' => strtoupper( $key ), |
||
581 | 'name' => strtoupper( $key ), |
||
582 | 'sign' => $value, |
||
583 | 'entity' => $value, |
||
584 | ); |
||
585 | } elseif ( is_array( $value ) ) { |
||
586 | // Make sure all required values are set |
||
587 | if ( empty( $value['label'] ) ) { |
||
588 | $value['label'] = $key; |
||
589 | } |
||
590 | if ( empty( $value['name'] ) ) { |
||
591 | $value['name'] = $key; |
||
592 | } |
||
593 | if ( empty( $value['sign'] ) ) { |
||
594 | $value['sign'] = $key; |
||
595 | } |
||
596 | if ( empty( $value['entity'] ) ) { |
||
597 | $value['entity'] = $key; |
||
598 | } |
||
599 | } else { |
||
600 | // Invalid |
||
601 | unset( static::$currencies[ $key ] ); |
||
602 | }//end if |
||
603 | }//end foreach |
||
604 | |||
605 | return static::$currencies; |
||
606 | } |
||
607 | |||
641 |
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.