| Conditions | 6 |
| Paths | 8 |
| Total Lines | 57 |
| Code Lines | 36 |
| 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 |
||
| 66 | function wpinv_get_errors() { |
||
| 67 | |||
| 68 | // Contains known errors. |
||
| 69 | $all_errors = array( |
||
| 70 | 'perm_cancel_subscription' => array( |
||
| 71 | 'type' => 'error', |
||
| 72 | 'text' => __( 'You do not have permission to cancel this subscription', 'invoicing' ), |
||
| 73 | ), |
||
| 74 | 'cannot_cancel_subscription' => array( |
||
| 75 | 'type' => 'error', |
||
| 76 | 'text' => __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ), |
||
| 77 | ), |
||
| 78 | 'cancelled_subscription' => array( |
||
| 79 | 'type' => 'success', |
||
| 80 | 'text' => __( 'Subscription cancelled successfully.', 'invoicing' ), |
||
| 81 | ), |
||
| 82 | 'address_updated' => array( |
||
| 83 | 'type' => 'success', |
||
| 84 | 'text' => __( 'Address updated successfully.', 'invoicing' ), |
||
| 85 | ), |
||
| 86 | 'perm_delete_invoice' => array( |
||
| 87 | 'type' => 'error', |
||
| 88 | 'text' => __( 'You do not have permission to delete this invoice', 'invoicing' ), |
||
| 89 | ), |
||
| 90 | 'cannot_delete_invoice' => array( |
||
| 91 | 'type' => 'error', |
||
| 92 | 'text' => __( 'This invoice cannot be deleted as it has already been paid.', 'invoicing' ), |
||
| 93 | ), |
||
| 94 | 'deleted_invoice' => array( |
||
| 95 | 'type' => 'success', |
||
| 96 | 'text' => __( 'Invoice deleted successfully.', 'invoicing' ), |
||
| 97 | ), |
||
| 98 | 'card_declined' => array( |
||
| 99 | 'type' => 'error', |
||
| 100 | 'text' => __( 'Your card was declined.', 'invoicing' ), |
||
| 101 | ), |
||
| 102 | 'invalid_currency' => array( |
||
| 103 | 'type' => 'error', |
||
| 104 | 'text' => __( 'The chosen payment gateway does not support this currency.', 'invoicing' ), |
||
| 105 | ), |
||
| 106 | ); |
||
| 107 | |||
| 108 | $errors = apply_filters( 'wpinv_errors', array() ); |
||
| 109 | |||
| 110 | if ( isset( $_GET['wpinv-notice'] ) && isset( $all_errors[ $_GET['wpinv-notice'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
||
| 111 | $errors[ $_GET['wpinv-notice'] ] = $all_errors[ $_GET['wpinv-notice'] ]; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
||
| 112 | } |
||
| 113 | |||
| 114 | if ( isset( $GLOBALS['wpinv_notice'] ) && isset( $all_errors[ $GLOBALS['wpinv_notice'] ] ) ) { |
||
| 115 | $errors[ $GLOBALS['wpinv_notice'] ] = $all_errors[ $GLOBALS['wpinv_notice'] ]; |
||
| 116 | } |
||
| 117 | |||
| 118 | if ( isset( $GLOBALS['wpinv_custom_notice'] ) ) { |
||
| 119 | $errors[ $GLOBALS['wpinv_notice']['code'] ] = $GLOBALS['wpinv_custom_notice']; |
||
| 120 | } |
||
| 121 | |||
| 122 | return $errors; |
||
| 123 | } |
||
| 238 |