| Conditions | 10 |
| Paths | 15 |
| Total Lines | 53 |
| Code Lines | 25 |
| 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 |
||
| 93 | public function get_issuers() { |
||
| 94 | $issuers = array(); |
||
| 95 | |||
| 96 | try { |
||
| 97 | $payment_methods_response = $this->client->get_payment_methods( new PaymentMethodsRequest( $this->config->get_merchant_account() ) ); |
||
| 98 | } catch ( Exception $e ) { |
||
| 99 | $this->error = new WP_Error( 'adyen_error', $e->getMessage() ); |
||
| 100 | |||
| 101 | return $issuers; |
||
| 102 | } |
||
| 103 | |||
| 104 | $payment_methods = $payment_methods_response->get_payment_methods(); |
||
| 105 | |||
| 106 | // Limit to iDEAL payment methods. |
||
| 107 | $payment_methods = array_filter( |
||
| 108 | $payment_methods, |
||
| 109 | /** |
||
| 110 | * Check if payment method is iDEAL. |
||
| 111 | * |
||
| 112 | * @param PaymentMethod $payment_method Payment method. |
||
| 113 | * |
||
| 114 | * @return boolean True if payment method is iDEAL, false otherwise. |
||
| 115 | */ |
||
| 116 | function( $payment_method ) { |
||
| 117 | return ( PaymentMethodType::IDEAL === $payment_method->get_type() ); |
||
| 118 | } |
||
| 119 | ); |
||
| 120 | |||
| 121 | foreach ( $payment_methods as $payment_method ) { |
||
| 122 | $details = $payment_method->get_details(); |
||
| 123 | |||
| 124 | if ( is_array( $details ) ) { |
||
| 125 | foreach ( $details as $detail ) { |
||
| 126 | if ( ! isset( $detail->key, $detail->type, $detail->items ) ) { |
||
| 127 | continue; |
||
| 128 | } |
||
| 129 | |||
| 130 | if ( 'issuer' === $detail->key && 'select' === $detail->type ) { |
||
| 131 | foreach ( $detail->items as $item ) { |
||
| 132 | $issuers[ \strval( $item->id ) ] = \strval( $item->name ); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | if ( empty( $issuers ) ) { |
||
| 140 | return $issuers; |
||
| 141 | } |
||
| 142 | |||
| 143 | return array( |
||
| 144 | array( |
||
| 145 | 'options' => $issuers, |
||
| 146 | ), |
||
| 150 |