BillingRequestFlow::language()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace GoCardlessPayment\MandateCheckout;
4
5
use GoCardlessPayment\Makeable;
6
use Illuminate\Support\Arr;
7
8
class BillingRequestFlow implements \JsonSerializable
9
{
10
    use Makeable;
11
12
    protected array $params = [];
13
14
    protected ?string $language = null;
15
16
    protected ?ReturnUrls $returnUrls = null;
17
18
    protected ?PrefilledCustomer $prefilledCustomer = null;
19
20 1
    public function __construct(array $params = [])
21
    {
22 1
        $this->params = $params;
23
    }
24
25 1
    public function returnUrls(?ReturnUrls $returnUrls = null): static
26
    {
27 1
        $this->returnUrls = $returnUrls;
28
29 1
        return $this;
30
    }
31
32 1
    public function prefilledCustomer(?PrefilledCustomer $prefilledCustomer): static
33
    {
34 1
        $this->prefilledCustomer = $prefilledCustomer;
35
36 1
        return $this;
37
    }
38
39
    /**
40
     * @see https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
41
     */
42
    public function language(?string $language = null): static
43
    {
44
        $this->language = $language;
45
46
        return $this;
47
    }
48
49 1
    public function setBillingRequestId(string $billingResponseId): static
50
    {
51 1
        Arr::set($this->params, 'links.billing_request', $billingResponseId);
52
53 1
        return $this;
54
    }
55
56 1
    public function jsonSerialize(): array
57
    {
58 1
        $params = [];
59
60 1
        if ($this->language) {
61
            $params['language'] = $this->language;
62
        }
63
64 1
        if ($this->prefilledCustomer) {
65 1
            $params['prefilled_customer'] = $this->prefilledCustomer->jsonSerialize();
66
        }
67
68 1
        if ($this->returnUrls) {
69 1
            $params = array_merge($params, $this->returnUrls->jsonSerialize());
70
        }
71
72 1
        return array_merge($this->params, $params);
73
    }
74
}
75