Passed
Push — 2.x ( 3908db...6bae43 )
by Darío
07:58
created

ApplicationContext::toArray()   A

Complexity

Conditions 6
Paths 32

Size

Total Lines 28
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 6

Importance

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