Extensions::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aweapi\Openapi;
6
7
use Countable;
8
9
final class Extensions implements Definition, Countable
10
{
11
    private $values = [];
12
13 57
    public function __construct(iterable $values = [])
14
    {
15 57
        foreach ($values as $key => $value) {
16
            // The value can be null, a primitive, an array or an object.
17
            // Can have any valid JSON format value. So must not be filtered.
18 57
            $this->values[$key] = $value;
19
        }
20
    }
21
22 54
    public function count(): int
23
    {
24 54
        return count($this->values);
25
    }
26
27 53
    public function extendValues(?array $properties): ?array
28
    {
29 53
        if ($this->count() === 0) {
30 1
            return $properties;
31
        }
32
33 53
        if (empty($properties)) {
34 1
            return $this->jsonSerialize();
35
        }
36
37 53
        return $properties + $this->jsonSerialize();
38
    }
39
40
    /**
41
     * @return mixed
42
     */
43 1
    public function getExtension(string $key)
44
    {
45 1
        return $this->values[$key];
46
    }
47
48 1
    public function hasExtension(string $key): bool
49
    {
50 1
        return array_key_exists($key, $this->values);
51
    }
52
53 56
    public function jsonSerialize(): array
54
    {
55 56
        return $this->values;
56
    }
57
}
58