Passed
Push — refactor/move-plan-domain-to-i... ( 6a77eb )
by Darío
03:14
created

StorePlanRequest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 13
eloc 36
dl 0
loc 92
ccs 36
cts 38
cp 0.9474
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setProductId() 0 5 1
A getBillingCycleSet() 0 3 1
A getPlanStatus() 0 3 1
A __construct() 0 5 1
A setPlanStatus() 0 5 1
A toArray() 0 25 4
A getProductId() 0 3 1
A getPlanName() 0 3 1
A setPlanName() 0 5 1
A setBillingCycleSet() 0 5 1
1
<?php
2
3
namespace PaymentGateway\PayPalSdk\Plans\Requests;
4
5
use PaymentGateway\PayPalSdk\Plans\Concerns\HasPlanDescription;
6
use PaymentGateway\PayPalSdk\Plans\Concerns\HasPlanStatus;
7
use PaymentGateway\PayPalSdk\Subscriptions\BillingCycles\BillingCycleSet;
8
use PaymentGateway\PayPalSdk\Subscriptions\Concerns\HasPaymentPreferences;
9
use PaymentGateway\PayPalSdk\Subscriptions\Constants\CurrencyCode;
10
use PaymentGateway\PayPalSdk\Subscriptions\Money;
11
use PaymentGateway\PayPalSdk\Subscriptions\PaymentPreferences;
12
13
class StorePlanRequest
14
{
15
    use HasPlanDescription;
16
    use HasPlanStatus;
17
    use HasPaymentPreferences;
18
19
    protected string $productId;
20
    protected string $planName;
21
    protected string $planStatus;
22
23
    protected BillingCycleSet $billingCycleSet;
24
25 4
    public function __construct(string $productId, string $planName, BillingCycleSet $billingCycleSet)
26
    {
27 4
        $this->productId = $productId;
28 4
        $this->planName = $planName;
29 4
        $this->billingCycleSet = $billingCycleSet;
30 4
    }
31
32 1
    public function getProductId(): string
33
    {
34 1
        return $this->productId;
35
    }
36
37 1
    public function setProductId(string $productId): self
38
    {
39 1
        $this->productId = $productId;
40
41 1
        return $this;
42
    }
43
44 1
    public function getPlanName(): string
45
    {
46 1
        return $this->planName;
47
    }
48
49 1
    public function setPlanName(string $planName): self
50
    {
51 1
        $this->planName = $planName;
52
53 1
        return $this;
54
    }
55
56 1
    public function getPlanStatus(): string
57
    {
58 1
        return $this->planStatus;
59
    }
60
61 2
    public function setPlanStatus(string $planStatus): self
62
    {
63 2
        $this->planStatus = $planStatus;
64
65 2
        return $this;
66
    }
67
68
    public function getBillingCycleSet(): BillingCycleSet
69
    {
70
        return $this->billingCycleSet;
71
    }
72
73 1
    public function setBillingCycleSet(BillingCycleSet $billingCycleSet): self
74
    {
75 1
        $this->billingCycleSet = $billingCycleSet;
76
77 1
        return $this;
78
    }
79
80 4
    public function toArray(): array
81
    {
82
        $request = [
83 4
            'product_id' => $this->productId,
84 4
            'name' => $this->planName,
85
        ];
86
87 4
        if ($this->planDescription ?? null) {
88 2
            $request['description'] = $this->planDescription;
89
        }
90
91 4
        if ($this->planStatus ?? null) {
92 2
            $request['status'] = $this->planStatus;
93
        }
94
95 4
        $request['billing_cycles'] = $this->billingCycleSet->toArray();
96
97 4
        if (!($this->paymentPreferences ?? null)) {
98 4
            $money = new Money(CurrencyCode::UNITED_STATES_DOLLAR, '0');
99 4
            $this->paymentPreferences = new PaymentPreferences($money);
100
        }
101
102 4
        $request['payment_preferences'] = $this->paymentPreferences->toArray();
103
104 4
        return $request;
105
    }
106
}
107