UpdateProductRequest::toArray()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 37
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 5

Importance

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