Passed
Push — feature/refactor-subscription-... ( 326c18 )
by Darío
03:04
created

ApplicationContext   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Test Coverage

Coverage 62.26%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 21
eloc 45
c 1
b 0
f 0
dl 0
loc 128
ccs 33
cts 53
cp 0.6226
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getBrandName() 0 3 1
A getUserAction() 0 3 1
A getShippingPreference() 0 3 1
A setCancelUrl() 0 5 1
A getCancelUrl() 0 3 1
A getLocale() 0 3 1
A getPaymentMethod() 0 3 1
A setReturnUrl() 0 5 1
A getReturnUrl() 0 3 1
A setPaymentMethod() 0 5 1
A toArray() 0 28 6
A setShippingPreference() 0 5 1
A setBrandName() 0 5 1
A setUserAction() 0 5 1
A setLocale() 0 5 1
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 8
    public function __construct(string $returnUrl, string $cancelUrl)
16
    {
17 8
        $this->returnUrl = $returnUrl;
18 8
        $this->cancelUrl = $cancelUrl;
19 8
    }
20
21
    public function getBrandName(): ?string
22
    {
23
        return $this->brandName;
24
    }
25
26 1
    public function setBrandName(?string $brandName): self
27
    {
28 1
        $this->brandName = $brandName;
29
30 1
        return $this;
31
    }
32
33
    public function getLocale(): ?string
34
    {
35
        return $this->locale;
36
    }
37
38 1
    public function setLocale(?string $locale): self
39
    {
40 1
        $this->locale = $locale;
41
42 1
        return $this;
43
    }
44
45
    public function getShippingPreference(): ?string
46
    {
47
        return $this->shippingPreference;
48
    }
49
50 1
    public function setShippingPreference(?string $shippingPreference): self
51
    {
52 1
        $this->shippingPreference = $shippingPreference;
53
54 1
        return $this;
55
    }
56
57
    public function getUserAction(): ?string
58
    {
59
        return $this->userAction;
60
    }
61
62 1
    public function setUserAction(?string $userAction): self
63
    {
64 1
        $this->userAction = $userAction;
65
66 1
        return $this;
67
    }
68
69
    public function getPaymentMethod(): ?PaymentMethod
70
    {
71
        return $this->paymentMethod;
72
    }
73
74 1
    public function setPaymentMethod(?PaymentMethod $paymentMethod): self
75
    {
76 1
        $this->paymentMethod = $paymentMethod;
77
78 1
        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 8
    public function toArray(): array
106
    {
107
        $data = [
108 8
            'return_url' => $this->returnUrl,
109 8
            'cancel_url' => $this->cancelUrl
110
        ];
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