RateTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 119
Duplicated Lines 9.24 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
getPaymentMethod() 0 1 ?
getParameter() 0 1 ?
setParameter() 0 1 ?
A getRateCount() 0 4 1
A getRateTerm() 0 4 1
A getRateTotalAmount() 0 4 1
A setRateCount() 0 4 1
A setRateTerm() 0 4 1
A setRateTotalAmount() 0 4 1
A appendRate() 11 11 2

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\BillPay\Message\AuthorizeRequest;
6
use Omnipay\Common\Exception\InvalidRequestException;
7
use Omnipay\Common\Message\AbstractRequest;
8
use SimpleXMLElement;
9
10
/**
11
 * Class RateTrait.
12
 *
13
 * @author    Andreas Lange <[email protected]>
14
 * @copyright 2016, Connox GmbH
15
 * @license   MIT
16
 */
17
trait RateTrait
18
{
19
    /**
20
     * Get the payment issuer.
21
     *
22
     * @return string
23
     *
24
     * @codeCoverageIgnore
25
     */
26
    abstract public function getPaymentMethod();
27
28
    /**
29
     * Gets count of installments to be paid during the term.
30
     *
31
     * @return int|null Count of installments to be paid during the term.
32
     */
33 3
    public function getRateCount()
34
    {
35 3
        return $this->getParameter('rateCount');
36
    }
37
38
    /**
39
     * Gets term of the installment plan.
40
     *
41
     * @return int|null months
42
     */
43 3
    public function getRateTerm()
44
    {
45 3
        return $this->getParameter('rateTerm');
46
    }
47
48
    /**
49
     * Gets total amount of the installments plan including the transaction credit interest / PayLater fee.
50
     *
51
     * @return float|null adjusted amount including all fees and interest
52
     */
53 3
    public function getRateTotalAmount()
54
    {
55 3
        return $this->getParameter('rateTotalAmount');
56
    }
57
58
    /**
59
     * Sets count of installments to be paid during the term.
60
     *
61
     * @param string $value Count of installments to be paid during the term.
62
     *
63
     * @return AuthorizeRequest
64
     */
65 11
    public function setRateCount($value)
66
    {
67 11
        return $this->setParameter('rateCount', $value);
68
    }
69
70
    /**
71
     * Sets term of the installment plan.
72
     *
73
     * @param int $value months
74
     *
75
     * @return AuthorizeRequest
76
     */
77 11
    public function setRateTerm($value)
78
    {
79 11
        return $this->setParameter('rateTerm', $value);
80
    }
81
82
    /**
83
     * Sets total amount of the installments plan including the transaction credit interest / PayLater fee.
84
     *
85
     * @param float $value
86
     *
87
     * @return AuthorizeRequest
88
     */
89 11
    public function setRateTotalAmount($value)
90
    {
91 11
        return $this->setParameter('rateTotalAmount', $value);
92
    }
93
94
    /**
95
     * Appends the rate request node to the SimpleXMLElement.
96
     *
97
     * @param SimpleXMLElement $data
98
     *
99
     * @throws InvalidRequestException
100
     */
101 9 View Code Duplication
    protected function appendRate(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...
102
    {
103 9
        if ($this->getPaymentMethod() !== 'pay_later') {
104 7
            return;
105
        }
106
107 2
        $data->addChild('rate_request');
108 2
        $data->rate_request[0]['term'] = $this->getRateTerm();
109 2
        $data->rate_request[0]['ratecount'] = $this->getRateCount();
110 2
        $data->rate_request[0]['totalamount'] = round(bcmul($this->getRateTotalAmount(), 100, 8));
111 2
    }
112
113
    /**
114
     * Get a single parameter.
115
     *
116
     * @param string $key The parameter key
117
     *
118
     * @return mixed
119
     *
120
     * @codeCoverageIgnore
121
     */
122
    abstract protected function getParameter($key);
123
124
    /**
125
     * Set a single parameter.
126
     *
127
     * @param string $key   The parameter key
128
     * @param mixed  $value The value to set
129
     *
130
     * @return AbstractRequest Provides a fluent interface
131
     *
132
     * @codeCoverageIgnore
133
     */
134
    abstract protected function setParameter($key, $value);
135
}
136