Passed
Push — feature/change-method-names-fo... ( a1d20f )
by Darío
02:56
created

StorePlanRequest::getPlanName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace PaymentGateway\PayPalSdk\Subscriptions\Requests;
4
5
use PaymentGateway\PayPalSdk\Subscriptions\Concerns\HasPlanDescription;
6
use PaymentGateway\PayPalSdk\Subscriptions\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
22
    protected BillingCycleSet $billingCycleSet;
23
24 1
    public function __construct(string $productId, string $planName, BillingCycleSet $billingCycleSet)
25
    {
26 1
        $this->productId = $productId;
27 1
        $this->planName = $planName;
28 1
        $this->billingCycleSet = $billingCycleSet;
29 1
    }
30
31
    public function getProductId(): string
32
    {
33
        return $this->productId;
34
    }
35
36
    public function setProductId(string $productId): self
37
    {
38
        $this->productId = $productId;
39
40
        return $this;
41
    }
42
43
    public function getPlanName(): string
44
    {
45
        return $this->planName;
46
    }
47
48
    public function setPlanName(string $planName): self
49
    {
50
        $this->planName = $planName;
51
52
        return $this;
53
    }
54
55
    public function getBillingCycleSet(): BillingCycleSet
56
    {
57
        return $this->billingCycleSet;
58
    }
59
60
    public function setBillingCycleSet(BillingCycleSet $billingCycleSet): self
61
    {
62
        $this->billingCycleSet = $billingCycleSet;
63
64
        return $this;
65
    }
66
67 1
    public function toArray(): array
68
    {
69
        $request = [
70 1
            'product_id' => $this->productId,
71 1
            'name' => $this->planName,
72 1
            'billing_cycles' => $this->billingCycleSet->toArray()
73
        ];
74
75 1
        if ($this->productDescription ?? null) {
0 ignored issues
show
Bug Best Practice introduced by
The property productDescription does not exist on PaymentGateway\PayPalSdk...quests\StorePlanRequest. Did you maybe forget to declare it?
Loading history...
76
            $request['description'] = $this->planDescription;
77
        }
78
79 1
        if ($this->planStatus ?? null) {
80
            $request['status'] = $this->planStatus;
81
        }
82
83 1
        if (!($this->paymentPreferences ?? null)) {
84 1
            $money = new Money(CurrencyCode::UNITED_STATES_DOLLAR, '0');
85 1
            $this->paymentPreferences = new PaymentPreferences($money);
86
        }
87
88 1
        $request['payment_preferences'] = $this->paymentPreferences->toArray();
89
90 1
        return $request;
91
    }
92
}
93