Passed
Push — master ( 745713...423bfb )
by Darío
07:06 queued 04:58
created

UpdatePlanRequest::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 36
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 3.0368

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 36
ccs 21
cts 25
cp 0.84
rs 9.536
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 3.0368
1
<?php
2
3
namespace PaymentGateway\PayPalSdk\Subscriptions\Requests;
4
5
use PaymentGateway\PayPalSdk\Products\Concerns\HasDescription;
6
use PaymentGateway\PayPalSdk\Subscriptions\Concerns\HasPaymentPreferences;
7
8
class UpdatePlanRequest
9
{
10
    use HasDescription;
11
    use HasPaymentPreferences;
12
13
    protected string $id;
14
15 1
    public function __construct(string $id)
16
    {
17 1
        $this->id = $id;
18 1
    }
19
20 1
    public function getId(): string
21
    {
22 1
        return $this->id;
23
    }
24
25 1
    public function toArray(): array
26
    {
27 1
        $request = [];
28
29 1
        if ($this->description ?? null) {
30
            $request[] = [
31
                'op' => 'replace',
32
                'path' => '/description',
33
                'value' => $this->description
34
            ];
35
        }
36
37 1
        if ($this->paymentPreferences ?? null) {
38 1
            $request[] = [
39 1
                'op' => 'replace',
40 1
                'path' => '/payment_preferences/auto_bill_outstanding',
41 1
                'value' => $this->paymentPreferences->isAutoBillOutstanding()
42
            ];
43 1
            $request[] = [
44 1
                'op' => 'replace',
45 1
                'path' => '/payment_preferences/payment_failure_threshold',
46 1
                'value' => $this->paymentPreferences->getPaymentFailureThreshold()
47
            ];
48 1
            $request[] = [
49 1
                'op' => 'replace',
50 1
                'path' => '/payment_preferences/setup_fee_failure_action',
51 1
                'value' => $this->paymentPreferences->getSetupFeeFailureAction()
52
            ];
53 1
            $request[] = [
54 1
                'op' => 'replace',
55 1
                'path' => '/payment_preferences/setup_fee',
56 1
                'value' => $this->paymentPreferences->getSetupFee()->toArray()
57
            ];
58
        }
59
60 1
        return $request;
61
    }
62
}
63