Passed
Push — feature/refactor-subscription-... ( 326c18 )
by Darío
03:04
created

PaymentPreferences::setPaymentFailureThreshold()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PaymentGateway\PayPalSdk\Subscriptions;
4
5
use PaymentGateway\PayPalSdk\Subscriptions\Constants\InitialPaymentFailureAction;
6
7
class PaymentPreferences
8
{
9
    protected Money $setupFee;
10
11
    protected bool $autoBillOutstanding = true;
12
13
    protected int $paymentFailureThreshold = 0;
14
15
    protected string $setupFeeFailureAction = InitialPaymentFailureAction::CANCEL;
16
17 11
    public function __construct(?Money $setupFee = null)
18
    {
19 11
        if ($setupFee) {
20 6
            $this->setSetupFee($setupFee);
21
        }
22 11
    }
23
24 6
    public function getSetupFee(): ?Money
25
    {
26 6
        return $this->setupFee ?? null;
27
    }
28
29 9
    public function setSetupFee(Money $setupFee): void
30
    {
31 9
        $this->setupFee = $setupFee;
32 9
    }
33
34 5
    public function isAutoBillOutstanding(): bool
35
    {
36 5
        return $this->autoBillOutstanding;
37
    }
38
39 1
    public function setAutoBillOutstanding(bool $autoBillOutstanding): void
40
    {
41 1
        $this->autoBillOutstanding = $autoBillOutstanding;
42 1
    }
43
44 5
    public function getPaymentFailureThreshold(): int
45
    {
46 5
        return $this->paymentFailureThreshold;
47
    }
48
49 1
    public function setPaymentFailureThreshold(int $paymentFailureThreshold): void
50
    {
51 1
        $this->paymentFailureThreshold = $paymentFailureThreshold;
52 1
    }
53
54 5
    public function getSetupFeeFailureAction(): string
55
    {
56 5
        return $this->setupFeeFailureAction;
57
    }
58
59 1
    public function setSetupFeeFailureAction(string $setupFeeFailureAction): void
60
    {
61 1
        $this->setupFeeFailureAction = $setupFeeFailureAction;
62 1
    }
63
64 6
    public function toArray(): array
65
    {
66
        $data =  [
67 6
            'auto_bill_outstanding' => $this->autoBillOutstanding,
68 6
            'setup_fee_failure_action' => $this->setupFeeFailureAction,
69 6
            'payment_failure_threshold' => $this->paymentFailureThreshold
70
        ];
71
72 6
        if ($this->setupFee ?? null) {
73 5
            $data['setup_fee'] = $this->setupFee->toArray();
74
        }
75
76 6
        return $data;
77
    }
78
}
79