Metadata   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 29
ccs 8
cts 11
cp 0.7272
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 15 4
A jsonSerialize() 0 3 1
1
<?php
2
3
namespace GoCardlessPayment\MandateCheckout;
4
5
use GoCardlessPayment\Makeable;
6
7
class Metadata implements \JsonSerializable
8
{
9
    use Makeable;
10
11
    public array $data = [];
12
13
    /**
14
     * @throws \Exception
15
     */
16 1
    public function add(string $key, string $value): static
17
    {
18 1
        if (count($this->data) >= 3) {
19
            throw new \Exception('Max 3 items allowed in metadata.');
20
        }
21 1
        if (strlen($key) > 50) {
22
            throw new \Exception('Key length max - 50 chars.');
23
        }
24 1
        if (strlen($value) > 500) {
25
            throw new \Exception('Value length max - 500 chars.');
26
        }
27
28 1
        $this->data[$key] = $value;
29
30 1
        return $this;
31
    }
32
33 1
    public function jsonSerialize(): array
34
    {
35 1
        return array_filter($this->data, fn ($i) => ! is_null($i));
36
    }
37
}
38