Passed
Pull Request — master (#97)
by Maximilian
03:52
created

Environment::jsonSerialize()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

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