Passed
Push — master ( a53d55...43aca1 )
by Maximilian
03:50
created

Entity::jsonSerialize()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 8
nc 8
nop 0
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 4
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\Component;
6
7
class Entity implements \JsonSerializable
8
{
9
    /**
10
     * @param string|null $id Entity identifier
11
     * @param string|null $type Entity type
12
     * @param mixed $value Entity value
13
     */
14 9
    public function __construct(
15
        public ?string $id = null,
16
        public ?string $type = null,
17
        public mixed $value = null,
18
    ) {
19 9
    }
20
21 6
    public function jsonSerialize(): array
22
    {
23 6
        $data = [];
24
25 6
        if ($this->id !== null) {
26 5
            $data['id'] = $this->id;
27
        }
28
29 6
        if ($this->type !== null) {
30 4
            $data['type'] = $this->type;
31
        }
32
33 6
        if ($this->value !== null) {
34 4
            $data['value'] = $this->value;
35
        }
36
37 6
        return $data;
38
    }
39
}
40