| Conditions | 8 |
| Paths | 40 |
| Total Lines | 70 |
| Code Lines | 37 |
| 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 |
||
| 95 | public function start( Payment $payment ) { |
||
| 96 | $request = new OrderRequest(); |
||
| 97 | |||
| 98 | $request->currency = $payment->get_total_amount()->get_currency()->get_alphabetic_code(); |
||
| 99 | $request->amount = $payment->get_total_amount()->get_cents(); |
||
| 100 | $request->merchant_order_id = $payment->get_order_id(); |
||
| 101 | $request->description = $payment->get_description(); |
||
| 102 | $request->return_url = $payment->get_return_url(); |
||
| 103 | |||
| 104 | // To make the 'Test' meta box work, set payment method to iDEAL if an issuer_id has been set. |
||
| 105 | $issuer = $payment->get_issuer(); |
||
| 106 | |||
| 107 | $payment_method = $payment->get_method(); |
||
| 108 | |||
| 109 | if ( empty( $payment_method ) && ! empty( $issuer ) ) { |
||
| 110 | $payment_method = PaymentMethods::IDEAL; |
||
| 111 | } |
||
| 112 | |||
| 113 | if ( PaymentMethods::IDEAL === $payment_method ) { |
||
| 114 | $request->issuer = $issuer; |
||
| 115 | } |
||
| 116 | |||
| 117 | $request->method = Methods::transform( $payment_method ); |
||
| 118 | |||
| 119 | $order = $this->client->create_order( $request ); |
||
| 120 | |||
| 121 | if ( $order ) { |
||
| 122 | $payment->set_transaction_id( $order->id ); |
||
| 123 | |||
| 124 | $action_url = add_query_arg( array( |
||
| 125 | 'payment_redirect' => $payment->get_id(), |
||
| 126 | 'key' => $payment->key, |
||
| 127 | ), home_url( '/' ) ); |
||
| 128 | |||
| 129 | if ( PaymentMethods::BANK_TRANSFER === $payment_method ) { |
||
| 130 | // Set payment redirect message with received transaction reference. |
||
| 131 | // @link https://s3-eu-west-1.amazonaws.com/wl1-apidocs/api.kassacompleet.nl/index.html#payment-methods-without-the-redirect-flow-performing_redirect-requirement |
||
| 132 | $message = sprintf( |
||
| 133 | /* translators: 1: payment provider name, 2: PSP account name, 3: PSP account number, 4: PSP account BIC, 5: formatted amount, 6: transaction reference */ |
||
| 134 | __( 'You have chosen the payment method "Bank transfer". To complete your payment, please transfer the amount to the payment service provider (%1$s). |
||
| 135 | |||
| 136 | <strong>Account holder:</strong> %2$s |
||
| 137 | <strong>Account IBAN:</strong> %3$s |
||
| 138 | <strong>Account BIC:</strong> %4$s |
||
| 139 | <strong>Amount:</strong> %5$s |
||
| 140 | <strong>Transaction reference:</strong> %6$s |
||
| 141 | |||
| 142 | <em>Please note: only payments with the mentioned transaction reference can be processed.</em>', 'pronamic_ideal' ), |
||
| 143 | __( 'ING', 'pronamic_ideal' ), |
||
| 144 | 'ING PSP', |
||
| 145 | 'NL13INGB0005300060', |
||
| 146 | 'INGBNL2A', |
||
| 147 | $payment->get_total_amount()->format_i18n(), |
||
| 148 | $order->transactions[0]->payment_method_details->reference |
||
| 149 | ); |
||
| 150 | |||
| 151 | $payment->set_meta( 'payment_redirect_message', $message ); |
||
| 152 | } |
||
| 153 | |||
| 154 | if ( isset( $order->transactions[0]->payment_url ) ) { |
||
| 155 | $action_url = $order->transactions[0]->payment_url; |
||
| 156 | } |
||
| 157 | |||
| 158 | $payment->set_action_url( $action_url ); |
||
| 159 | } |
||
| 160 | |||
| 161 | $error = $this->client->get_error(); |
||
| 162 | |||
| 163 | if ( is_wp_error( $error ) ) { |
||
| 164 | $this->error = $error; |
||
| 165 | } |
||
| 207 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: