| Conditions | 6 |
| Paths | 12 |
| Total Lines | 64 |
| Code Lines | 44 |
| 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 |
||
| 177 | public function update_status( Payment $payment ) { |
||
| 178 | $method = Server::get( 'REQUEST_METHOD', FILTER_SANITIZE_STRING ); |
||
| 179 | |||
| 180 | $data = array(); |
||
| 181 | |||
| 182 | switch ( $method ) { |
||
| 183 | case 'GET': |
||
| 184 | $data = $_GET; // WPCS: CSRF OK. |
||
| 185 | |||
| 186 | break; |
||
| 187 | case 'POST': |
||
| 188 | $data = $_POST; // WPCS: CSRF OK. |
||
| 189 | |||
| 190 | break; |
||
| 191 | } |
||
| 192 | |||
| 193 | $data = Util::urldecode( $data ); |
||
| 194 | |||
| 195 | $data = stripslashes_deep( $data ); |
||
| 196 | |||
| 197 | $data = $this->client->verify_request( $data ); |
||
| 198 | |||
| 199 | if ( $data ) { |
||
| 200 | $payment->set_transaction_id( $data[ Parameters::PAYMENT ] ); |
||
| 201 | $payment->set_status( Statuses::transform( $data[ Parameters::STATUS_CODE ] ) ); |
||
| 202 | $payment->set_consumer_iban( $data[ Parameters::SERVICE_IDEAL_CONSUMER_IBAN ] ); |
||
| 203 | $payment->set_consumer_bic( $data[ Parameters::SERVICE_IDEAL_CONSUMER_BIC ] ); |
||
| 204 | $payment->set_consumer_name( $data[ Parameters::SERVICE_IDEAL_CONSUMER_NAME ] ); |
||
| 205 | |||
| 206 | $labels = array( |
||
| 207 | Parameters::PAYMENT => __( 'Payment', 'pronamic_ideal' ), |
||
| 208 | Parameters::PAYMENT_METHOD => __( 'Payment Method', 'pronamic_ideal' ), |
||
| 209 | Parameters::STATUS_CODE => __( 'Status Code', 'pronamic_ideal' ), |
||
| 210 | Parameters::STATUS_CODE_DETAIL => __( 'Status Code Detail', 'pronamic_ideal' ), |
||
| 211 | Parameters::STATUS_MESSAGE => __( 'Status Message', 'pronamic_ideal' ), |
||
| 212 | Parameters::INVOICE_NUMBER => __( 'Invoice Number', 'pronamic_ideal' ), |
||
| 213 | Parameters::AMOUNT => __( 'Amount', 'pronamic_ideal' ), |
||
| 214 | Parameters::CURRENCY => __( 'Currency', 'pronamic_ideal' ), |
||
| 215 | Parameters::TIMESTAMP => __( 'Timestamp', 'pronamic_ideal' ), |
||
| 216 | Parameters::SERVICE_IDEAL_CONSUMER_ISSUER => __( 'Service iDEAL Consumer Issuer', 'pronamic_ideal' ), |
||
| 217 | Parameters::SERVICE_IDEAL_CONSUMER_NAME => __( 'Service iDEAL Consumer Name', 'pronamic_ideal' ), |
||
| 218 | Parameters::SERVICE_IDEAL_CONSUMER_IBAN => __( 'Service iDEAL Consumer IBAN', 'pronamic_ideal' ), |
||
| 219 | Parameters::SERVICE_IDEAL_CONSUMER_BIC => __( 'Service iDEAL Consumer BIC', 'pronamic_ideal' ), |
||
| 220 | Parameters::TRANSACTIONS => __( 'Transactions', 'pronamic_ideal' ), |
||
| 221 | ); |
||
| 222 | |||
| 223 | $note = ''; |
||
| 224 | |||
| 225 | $note .= '<p>'; |
||
| 226 | $note .= __( 'Buckaroo data:', 'pronamic_ideal' ); |
||
| 227 | $note .= '</p>'; |
||
| 228 | |||
| 229 | $note .= '<dl>'; |
||
| 230 | |||
| 231 | foreach ( $labels as $key => $label ) { |
||
| 232 | if ( isset( $data[ $key ] ) ) { |
||
| 233 | $note .= sprintf( '<dt>%s</dt>', esc_html( $label ) ); |
||
| 234 | $note .= sprintf( '<dd>%s</dd>', esc_html( $data[ $key ] ) ); |
||
| 235 | } |
||
| 236 | } |
||
| 237 | |||
| 238 | $note .= '</dl>'; |
||
| 239 | |||
| 240 | $payment->add_note( $note ); |
||
| 241 | } |
||
| 244 |