Completed
Push — master ( 69d984...0eb511 )
by Claude
03:26
created

WebCaptureRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 2
cbo 2
dl 39
loc 39
ccs 22
cts 22
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getData() 27 27 2
A createResponse() 4 4 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
namespace Omnipay\Payline\Message;
4
/**
5
 * Authorize Request
6
 *
7
 * @method WebAuthorizeResponse send()
8
 */
9 View Code Duplication
class WebCaptureRequest extends WebAuthorizeRequest
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...
10
{
11 3
    public function getData()
12
    {
13 3
        $data['payment'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
14 3
            'amount' => $this->getAmountInteger(),
15 3
            'currency' => $this->getCurrencyNumeric(),
16 3
            'action' => 101,
17 3
            'mode' => 'CPT',
18
        ];
19
20 3
        if($this->getContractNumber())
21 2
        {
22 3
            $data['payment']['contractNumber'] = $this->getContractNumber();
23 2
        }
24
25 3
        $data['order'] = [
26 3
            'ref' => $this->getTransactionReference(),
27 3
            'amount' => $this->getAmountInteger(),
28 3
            'currency' => $this->getCurrencyNumeric(),
29 3
            'date' => (new \DateTime())->format('d/m/Y H:i')
30 2
        ];
31
32 3
        $data['returnURL'] = $this->getReturnUrl();
33 3
        $data['cancelURL'] = $this->getCancelUrl();
34 3
        $data['notificationURL'] = $this->getNotifyUrl();
35
36 3
        return array_replace_recursive($this->getBaseData(), $data);
37
    }
38
39
    /**
40
     * @param \stdClass $data
41
     * @return WebAuthorizeResponse
42
     */
43 3
    protected function createResponse($data)
44
    {
45 3
        return $this->response = new WebCaptureResponse($this, $data);
46
    }
47
}
48