Passed
Pull Request — 2.x (#45)
by Darío
05:09 queued 02:40
created

UpdatePlanRequest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 87.1%

Importance

Changes 0
Metric Value
wmc 6
eloc 31
dl 0
loc 56
ccs 27
cts 31
cp 0.871
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 39 4
A __construct() 0 3 1
A getId() 0 3 1
1
<?php
2
3
namespace PaymentGateway\PayPalSdk\Plans\Requests;
4
5
use PaymentGateway\PayPalSdk\Products\Concerns\HasProductDescription;
6
use PaymentGateway\PayPalSdk\Subscriptions\Concerns\HasPaymentPreferences;
7
8
class UpdatePlanRequest
9
{
10
    use HasProductDescription;
11
    use HasPaymentPreferences;
12
13
    protected string $id;
14
15 2
    public function __construct(string $id)
16
    {
17 2
        $this->id = $id;
18 2
    }
19
20 2
    public function getId(): string
21
    {
22 2
        return $this->id;
23
    }
24
25 2
    public function toArray(): array
26
    {
27 2
        $request = [];
28
29 2
        if ($this->productDescription ?? null) {
30
            $request[] = [
31
                'op' => 'replace',
32
                'path' => '/description',
33
                'value' => $this->productDescription
34
            ];
35
        }
36
37 2
        if ($this->paymentPreferences ?? null) {
38 2
            $request[] = [
39 2
                'op' => 'replace',
40 2
                'path' => '/payment_preferences/auto_bill_outstanding',
41 2
                'value' => $this->paymentPreferences->isAutoBillOutstanding()
42
            ];
43 2
            $request[] = [
44 2
                'op' => 'replace',
45 2
                'path' => '/payment_preferences/payment_failure_threshold',
46 2
                'value' => $this->paymentPreferences->getPaymentFailureThreshold()
47
            ];
48 2
            $request[] = [
49 2
                'op' => 'replace',
50 2
                'path' => '/payment_preferences/setup_fee_failure_action',
51 2
                'value' => $this->paymentPreferences->getSetupFeeFailureAction()
52
            ];
53
54 2
            if ($this->paymentPreferences->getSetupFee()) {
55 1
                $request[] = [
56 1
                    'op' => 'replace',
57 1
                    'path' => '/payment_preferences/setup_fee',
58 1
                    'value' => $this->paymentPreferences->getSetupFee()->toArray()
59
                ];
60
            }
61
        }
62
63 2
        return $request;
64
    }
65
}
66