CancelTrait   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 48
Duplicated Lines 14.58 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 0
dl 7
loc 48
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
getAmount() 0 1 ?
getCurrency() 0 1 ?
getTransactionId() 0 1 ?
A appendCancel() 7 7 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\BillPay\Message\RequestData;
4
5
use Omnipay\Common\Exception\InvalidRequestException;
6
use SimpleXMLElement;
7
8
/**
9
 * Class CancelTrait.
10
 *
11
 * @author    Andreas Lange <[email protected]>
12
 * @copyright 2016, Connox GmbH
13
 * @license   MIT
14
 */
15
trait CancelTrait
16
{
17
    /**
18
     * Validates and returns the formated amount.
19
     *
20
     * @throws InvalidRequestException on any validation failure.
21
     *
22
     * @return string The amount formatted to the correct number of decimal places for the selected currency.
23
     *
24
     * @codeCoverageIgnore
25
     */
26
    abstract public function getAmount();
27
28
    /**
29
     * Get the payment currency code.
30
     *
31
     * @return string
32
     *
33
     * @codeCoverageIgnore
34
     */
35
    abstract public function getCurrency();
36
37
    /**
38
     * Get the transaction ID.
39
     *
40
     * The transaction ID is the identifier generated by the merchant website.
41
     *
42
     * @return string
43
     *
44
     * @codeCoverageIgnore
45
     */
46
    abstract public function getTransactionId();
47
48
    /**
49
     * Appends the rate request node to the SimpleXMLElement.
50
     *
51
     * @param SimpleXMLElement $data
52
     *
53
     * @throws InvalidRequestException
54
     */
55 2 View Code Duplication
    protected function appendCancel(SimpleXMLElement $data)
0 ignored issues
show
Duplication introduced by
This method 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...
56
    {
57 2
        $data->addChild('cancel_params');
58 2
        $data->cancel_params[0]['carttotalgross'] = round(bcmul($this->getAmount(), 100, 8));
59 2
        $data->cancel_params[0]['currency'] = $this->getCurrency();
60 2
        $data->cancel_params[0]['reference'] = $this->getTransactionId();
61 2
    }
62
}
63