| Conditions | 4 |
| Paths | 4 |
| Total Lines | 57 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 6.6388 |
| 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 |
||
| 81 | 2 | public function rest_api_adyen_payments_result( WP_REST_Request $request ) { |
|
| 82 | 2 | $config_id = $request->get_param( 'config_id' ); |
|
| 83 | 2 | $payload = $request->get_param( 'payload' ); |
|
| 84 | |||
| 85 | // Gateway. |
||
| 86 | 2 | $gateway = Plugin::get_gateway( $config_id ); |
|
|
1 ignored issue
–
show
|
|||
| 87 | |||
| 88 | 2 | if ( empty( $gateway ) ) { |
|
| 89 | 1 | return new WP_Error( |
|
| 90 | 1 | 'pronamic-pay-adyen-gateway-not-found', |
|
| 91 | 1 | sprintf( |
|
| 92 | /* translators: %s: Gateway configuration ID */ |
||
| 93 | 1 | __( 'Could not found gateway with ID `%s`.', 'pronamic_ideal' ), |
|
| 94 | $config_id |
||
| 95 | 1 | ), |
|
| 96 | $config_id |
||
| 97 | 1 | ); |
|
| 98 | } |
||
| 99 | |||
| 100 | 1 | if ( ! isset( $gateway->client ) ) { |
|
| 101 | return new WP_Error( |
||
| 102 | 'pronamic-pay-adyen-client-not-found', |
||
| 103 | sprintf( |
||
| 104 | /* translators: %s: Gateway configuration ID */ |
||
| 105 | __( 'Could not found client in gateway with ID `%s`.', 'pronamic_ideal' ), |
||
| 106 | $config_id |
||
| 107 | ), |
||
| 108 | $config_id |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | |||
| 112 | // Client. |
||
| 113 | 1 | $payment_result_request = new PaymentResultRequest( $payload ); |
|
| 114 | |||
| 115 | 1 | $payment_result_response = $gateway->client->get_payment_result( $payment_result_request ); |
|
| 116 | |||
| 117 | $merchant_reference = $payment_result_response->get_merchant_reference(); |
||
| 118 | |||
| 119 | // Payment. |
||
| 120 | $payment = get_pronamic_payment( $merchant_reference ); |
||
| 121 | |||
| 122 | if ( empty( $payment ) ) { |
||
| 123 | return new WP_Error( |
||
| 124 | 'pronamic-pay-adyen-payment-not-found', |
||
| 125 | sprintf( |
||
| 126 | /* translators: %s: Adyen merchant reference */ |
||
| 127 | __( 'Could not found payment with ID `%s`.', 'pronamic_ideal' ), |
||
| 128 | $merchant_reference |
||
| 129 | ), |
||
| 130 | $payment_result_response |
||
| 131 | ); |
||
| 132 | } |
||
| 133 | |||
| 134 | PaymentResultHelper::update_payment( $payment, $payment_result_response ); |
||
| 135 | |||
| 136 | // Return payment result response. |
||
| 137 | return $payment_result_response->get_json(); |
||
| 138 | } |
||
| 140 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.