Passed
Push — refactor/move-plan-domain-to-i... ( 6a77eb )
by Darío
03:14
created

UpdatePlanRequest::toArray()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 39
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 4.0582

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 39
ccs 22
cts 26
cp 0.8462
rs 9.52
c 0
b 0
f 0
cc 4
nc 6
nop 0
crap 4.0582
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