CaptureReservation   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 15
loc 75
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCaptureAmount() 0 4 1
A getCaptureCurrency() 0 4 1
A getCaptureResult() 0 4 1
A getTransactions() 0 4 1
A init() 15 15 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
namespace Loevgaard\AltaPay\Response;
3
4
use Loevgaard\AltaPay;
5
use Loevgaard\AltaPay\Entity\ResultTrait;
6
use Loevgaard\AltaPay\Entity\Transaction;
7
use Loevgaard\AltaPay\Entity\TransactionsTrait;
8
use Money\Money;
9
10
class CaptureReservation extends Response
11
{
12
    use ResultTrait;
13
    use TransactionsTrait;
14
15
    /**
16
     * @var Money
17
     */
18
    protected $captureAmount;
19
20
    /**
21
     * @var int
22
     */
23
    protected $captureCurrency;
24
25
    /**
26
     * @var string
27
     */
28
    protected $captureResult;
29
30
    /**
31
     * @var Transaction[]
32
     */
33
    protected $transactions;
34
35
    /**
36
     * @return Money
37
     */
38 3
    public function getCaptureAmount() : Money
39
    {
40 3
        return $this->captureAmount;
41
    }
42
43
    /**
44
     * @return int
45
     */
46 3
    public function getCaptureCurrency() : int
47
    {
48 3
        return $this->captureCurrency;
49
    }
50
51
    /**
52
     * @deprecated According to AltaPay documentation this is deprecated,
53
     * @see https://testgateway.altapaysecure.com/merchant/help/Merchant_API#API_captureReservation
54
     * @return string
55
     */
56 3
    public function getCaptureResult() : string
57
    {
58 3
        return $this->captureResult;
59
    }
60
61
    /**
62
     * @return Transaction[]
63
     */
64 3
    public function getTransactions() : array
65
    {
66 3
        return $this->transactions;
67
    }
68
69 6 View Code Duplication
    protected function init()
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...
70
    {
71
        /** @var \SimpleXMLElement $body */
72 6
        $body = $this->xmlDoc->Body;
0 ignored issues
show
Bug introduced by
The property Body does not seem to exist in SimpleXMLElement.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
73
74 6
        $currency = (int)$body->CaptureCurrency;
75 6
        $alphaCurrency = AltaPay\alphaCurrencyFromNumeric($currency);
76
77 6
        $this->transactions     = [];
78 6
        $this->captureAmount    = AltaPay\createMoneyFromFloat($alphaCurrency, (float)$body->CaptureAmount);
79 6
        $this->captureCurrency  = $currency;
80 6
        $this->captureResult    = (string)$body->CaptureResult;
81 6
        $this->hydrateResult($body);
82 6
        $this->hydrateTransactions($body);
83 6
    }
84
}
85