FetchTransactionRequest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 24
loc 24
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 9 9 1
A getEndpoint() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Ebanx fetchTransaction Request.
4
 */
5
namespace Omnipay\Ebanx\Message;
6
7
/**
8
 * Ebanx fetchTransaction Request.
9
 *
10
 * To query a payment and fetch its details, you must call the API method query.
11
 * You can either use the 'transactionReference' or the 'transactionId' to fetch the transaction:
12
 *
13
 * Example:
14
 *
15
 * <code>
16
 *   // Create a gateway for the Ebanx Gateway
17
 *   // (routes to GatewayFactory::create)
18
 *   $gateway = Omnipay::create('Ebanx');
19
 *
20
 *   // Initialise the gateway
21
 *   $gateway->initialize(array(
22
 *       'integration_key' => 'MyApiKey',
23
 *   ));
24
 *
25
 *   // Do an authorize transaction on the gateway
26
 *   $transaction = $gateway->fetchTransaction(array(
27
 *     'transactionReference' => '5d5eb3389d1bce23d265b8d2376688b09a0fafc56d453252',
28
 *     // 'transactionId' => '28937128947231897',
29
 *   ));
30
 *
31
 *   $response = $transaction->send();
32
 *   if ($response->isSuccessful()) {
33
 *       echo $response->getData();
34
 *   } else {
35
 *       // payment failed: display message to customer
36
 *       exit($response->getMessage());
37
 *   }
38
 * </code>
39
 *
40
 * @see  \Omnipay\Ebanx\Gateway
41
 * @link https://developers.ebanxpagamentos.com/api-reference/ebanx-payment-api/ebanx-payment-guide/guide-capture-a-payment/
42
 */
43 View Code Duplication
class FetchTransactionRequest extends AbstractRequest
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
{
45 3
    public function getData()
46
    {
47
        /*
48
         * As the query request the params should be passed in the query
49
         * not in the body, we return an empty array for the body, and
50
         * change the params at the getEndpoint method.
51
         */
52 3
        return [];
53
    }
54
55 6
    public function getEndpoint()
56
    {
57 6
        $data                          = $this->getDefaultParameters();
58 6
        $data['hash']                  = $this->getTransactionReference();
59 6
        $data['merchant_payment_code'] = $this->getTransactionId();
60
61
        // Remove empty values to only send hash or merchant payment code
62 6
        $data = array_filter($data);
63
64 6
        return parent::getEndpoint() . '/query?' . http_build_query($data, '', '&');
65
    }
66
}
67