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

UpdatePlanRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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