Passed
Pull Request — 1.x (#36)
by Darío
04:17 queued 02:03
created

ApplicationContext::getPaymentMethod()   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;
4
5
class ApplicationContext
6
{
7
    private ?string $brandName = null;
8
    private ?string $locale = null;
9
    private ?string $shippingPreference = null;
10
    private ?string $userAction = null;
11
    private ?PaymentMethod $paymentMethod = null;
12
    private string $returnUrl;
13
    private string $cancelUrl;
14
15 2
    public function __construct(string $returnUrl, string $cancelUrl)
16
    {
17 2
        $this->returnUrl = $returnUrl;
18 2
        $this->cancelUrl = $cancelUrl;
19 2
    }
20
21
    public function getBrandName(): ?string
22
    {
23
        return $this->brandName;
24
    }
25
26
    public function setBrandName(?string $brandName): self
27
    {
28
        $this->brandName = $brandName;
29
30
        return $this;
31
    }
32
33
    public function getLocale(): ?string
34
    {
35
        return $this->locale;
36
    }
37
38
    public function setLocale(?string $locale): self
39
    {
40
        $this->locale = $locale;
41
42
        return $this;
43
    }
44
45
    public function getShippingPreference(): ?string
46
    {
47
        return $this->shippingPreference;
48
    }
49
50
    public function setShippingPreference(?string $shippingPreference): self
51
    {
52
        $this->shippingPreference = $shippingPreference;
53
54
        return $this;
55
    }
56
57
    public function getUserAction(): ?string
58
    {
59
        return $this->userAction;
60
    }
61
62
    public function setUserAction(?string $userAction): self
63
    {
64
        $this->userAction = $userAction;
65
66
        return $this;
67
    }
68
69
    public function getPaymentMethod(): ?PaymentMethod
70
    {
71
        return $this->paymentMethod;
72
    }
73
74
    public function setPaymentMethod(?PaymentMethod $paymentMethod): self
75
    {
76
        $this->paymentMethod = $paymentMethod;
77
78
        return $this;
79
    }
80
81
    public function getReturnUrl(): string
82
    {
83
        return $this->returnUrl;
84
    }
85
86
    public function setReturnUrl(string $returnUrl): self
87
    {
88
        $this->returnUrl = $returnUrl;
89
90
        return $this;
91
    }
92
93
    public function getCancelUrl(): string
94
    {
95
        return $this->cancelUrl;
96
    }
97
98
    public function setCancelUrl(string $cancelUrl): self
99
    {
100
        $this->cancelUrl = $cancelUrl;
101
102
        return $this;
103
    }
104
105 2
    public function toArray(): array
106
    {
107
        $data = [
108 2
            'return_url' => $this->returnUrl,
109 2
            'cancel_url' => $this->cancelUrl
110
        ];
111
112 2
        if ($this->brandName) {
113
            $data['brand_name'] = $this->brandName;
114
        }
115
116 2
        if ($this->locale) {
117
            $data['locale'] = $this->locale;
118
        }
119
120 2
        if ($this->shippingPreference) {
121
            $data['shipping_preference'] = $this->shippingPreference;
122
        }
123
124 2
        if ($this->userAction) {
125
            $data['user_action'] = $this->userAction;
126
        }
127
128 2
        if ($this->paymentMethod) {
129
            $data['payment_method'] = $this->paymentMethod->toArray();
130
        }
131
132 2
        return $data;
133
    }
134
}
135