RefundCapturedReservation   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 161
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 161
ccs 47
cts 47
cp 1
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 6

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getPayload() 0 15 2
A validate() 0 9 1
A getTransactionId() 0 4 1
A setTransactionId() 0 5 1
A getAmount() 0 4 1
A setAmount() 0 7 1
A getReconciliationIdentifier() 0 4 1
A setReconciliationIdentifier() 0 5 1
A isAllowOverRefund() 0 4 1
A setAllowOverRefund() 0 5 1
A getInvoiceNumber() 0 4 1
A setInvoiceNumber() 0 5 1
1
<?php
2
namespace Loevgaard\AltaPay\Payload;
3
4
use Assert\Assert;
5
use Loevgaard\AltaPay;
6
use Money\Money;
7
8
class RefundCapturedReservation extends Payload implements RefundCapturedReservationInterface
9
{
10
    use OrderLineArrayTrait;
11
12
    /**
13
     * @var string
14
     */
15
    private $transactionId;
16
17
    /**
18
     * @var int
19
     */
20
    private $amountValue;
21
22
    /**
23
     * @var string
24
     */
25
    private $amountCurrency;
26
27
    /**
28
     * @var string
29
     */
30
    private $reconciliationIdentifier;
31
32
    /**
33
     * @var boolean
34
     */
35
    private $allowOverRefund;
36
37
    /**
38
     * @var string
39
     */
40
    private $invoiceNumber;
41
42 9
    public function __construct(string $transactionId)
43
    {
44 9
        $this->transactionId = $transactionId;
45 9
        $this->orderLines = [];
46 9
    }
47
48
    /**
49
     * @return array
50
     */
51 6
    public function getPayload() : array
52
    {
53 6
        $this->validate();
54
55
        $payload = [
56 6
            'transaction_id' => $this->transactionId,
57 6
            'amount' => AltaPay\floatFromMoney($this->getAmount()),
58 6
            'reconciliation_identifier' => $this->reconciliationIdentifier,
59 6
            'allow_over_refund' => is_bool($this->allowOverRefund) ? intval($this->allowOverRefund) : null,
60 6
            'invoice_number' => $this->invoiceNumber,
61 6
            'orderLines' => $this->orderLines,
62
        ];
63
64 6
        return static::simplePayload($payload);
65
    }
66
67 6
    public function validate()
68
    {
69 6
        Assert::that($this->transactionId)->string();
70 6
        Assert::thatNullOr($this->getAmount())->isInstanceOf(Money::class);
71 6
        Assert::thatNullOr($this->reconciliationIdentifier)->string();
72 6
        Assert::thatNullOr($this->allowOverRefund)->boolean();
73 6
        Assert::thatNullOr($this->invoiceNumber)->string();
74 6
        Assert::thatNullOr($this->orderLines)->isArray();
75 6
    }
76
77
    /**
78
     * @return string
79
     */
80 3
    public function getTransactionId(): string
81
    {
82 3
        return $this->transactionId;
83
    }
84
85
    /**
86
     * @param string $transactionId
87
     * @return RefundCapturedReservation
88
     */
89 3
    public function setTransactionId(string $transactionId) : self
90
    {
91 3
        $this->transactionId = $transactionId;
92 3
        return $this;
93
    }
94
95
    /**
96
     * @return Money
97
     */
98 9
    public function getAmount(): ?Money
99
    {
100 9
        return AltaPay\createMoney((string)$this->amountCurrency, (int)$this->amountValue);
101
    }
102
103
    /**
104
     * @param Money $amount
105
     * @return RefundCapturedReservation
106
     */
107 6
    public function setAmount(Money $amount) : self
108
    {
109 6
        $this->amountCurrency = $amount->getCurrency()->getCode();
110 6
        $this->amountValue = $amount->getAmount();
0 ignored issues
show
Documentation Bug introduced by
The property $amountValue was declared of type integer, but $amount->getAmount() is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
111
112 6
        return $this;
113
    }
114
115
    /**
116
     * @return string
117
     */
118 3
    public function getReconciliationIdentifier(): ?string
119
    {
120 3
        return $this->reconciliationIdentifier;
121
    }
122
123
    /**
124
     * @param string $reconciliationIdentifier
125
     * @return RefundCapturedReservation
126
     */
127 6
    public function setReconciliationIdentifier(string $reconciliationIdentifier) : self
128
    {
129 6
        $this->reconciliationIdentifier = $reconciliationIdentifier;
130 6
        return $this;
131
    }
132
133
    /**
134
     * @return bool
135
     */
136 3
    public function isAllowOverRefund(): ?bool
137
    {
138 3
        return $this->allowOverRefund;
139
    }
140
141
    /**
142
     * @param bool $allowOverRefund
143
     * @return RefundCapturedReservation
144
     */
145 6
    public function setAllowOverRefund(bool $allowOverRefund) : self
146
    {
147 6
        $this->allowOverRefund = $allowOverRefund;
148 6
        return $this;
149
    }
150
151
    /**
152
     * @return string
153
     */
154 3
    public function getInvoiceNumber(): ?string
155
    {
156 3
        return $this->invoiceNumber;
157
    }
158
159
    /**
160
     * @param string $invoiceNumber
161
     * @return RefundCapturedReservation
162
     */
163 6
    public function setInvoiceNumber(string $invoiceNumber) : self
164
    {
165 6
        $this->invoiceNumber = $invoiceNumber;
166 6
        return $this;
167
    }
168
}
169