MandateRequest::__construct()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace GoCardlessPayment\MandateCheckout;
4
5
use GoCardlessPayment\Makeable;
6
7
class MandateRequest implements \JsonSerializable
8
{
9
    use Makeable;
10
11
    protected array $params = [];
12
13
    protected ?string $authorisationSource = null;
14
15
    protected ?string $currencyCode = null;
16
17
    protected ?string $verify = null;
18
19
    protected ?string $scheme = null;
20
21
    protected ?Metadata $metadata = null;
22
23 1
    public function __construct(array $params = [])
24
    {
25 1
        $this->params = $params;
26
    }
27
28
    /**
29
     * @see https://www.moderntreasury.com/learn/sec-codes
30
     */
31
    public function authorisationSource(?string $authorisationSource): static
32
    {
33
        $this->authorisationSource = $authorisationSource;
34
35
        return $this;
36
    }
37
38
    /**
39
     * @see https://en.wikipedia.org/wiki/ISO_4217#Active_codes
40
     */
41
    public function currency(?string $currencyCode): static
42
    {
43
        $this->currencyCode = $currencyCode;
44
45
        return $this;
46
    }
47
48 1
    public function metadata(?Metadata $metadata): static
49
    {
50 1
        $this->metadata = $metadata;
51
52 1
        return $this;
53
    }
54
55
    /**
56
     * A bank payment scheme. Currently, “ach”, “autogiro”, “bacs”, “becs”, “becs_nz”, “betalingsservice”,
57
     *  “faster_payments”, “pad”, “pay_to” and “sepa_core” are supported.
58
     */
59 1
    public function scheme(?string $scheme): static
60
    {
61 1
        $this->scheme = $scheme;
62
63 1
        return $this;
64
    }
65
66 1
    public function verify(?string $verify): static
67
    {
68 1
        $this->verify = $verify;
69
70 1
        return $this;
71
    }
72
73 1
    public function verifyWhenAvailable(): static
74
    {
75 1
        return $this->verify('when_available');
76
    }
77
78 1
    public function jsonSerialize(): array
79
    {
80 1
        $params = array_filter([
81 1
            'authorisation_source' => $this->authorisationSource,
82 1
            'currency' => $this->currencyCode,
83 1
            'scheme' => $this->scheme,
84 1
            'verify' => $this->verify,
85 1
        ], fn ($i) => ! is_null($i));
86
87 1
        if ($this->metadata) {
88 1
            $params['metadata'] = $this->metadata->jsonSerialize();
89
        }
90
91 1
        return array_merge($this->params, $params);
92
    }
93
}
94