Passed
Push — feature/billing-plans ( ede562 )
by Darío
07:23
created

StorePlanRequest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 42.11%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 35
c 1
b 0
f 1
dl 0
loc 94
ccs 16
cts 38
cp 0.4211
rs 10
wmc 13

10 Methods

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