Passed
Pull Request — master (#97)
by Maximilian
04:17
created

LogCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\LogLevel;
8
9
class LogCommand extends AbstractStandardCommand
10
{
11
    public const TYPE = 'Log';
12
13
    /**
14
     * @param LogLevel $level Log level for the message
15
     * @param string|null $message Message to log
16
     * @param array|null $arguments Optional map of key-value pairs for data-binding
17
     */
18 8
    public function __construct(
19
        public LogLevel $level = LogLevel::INFO,
20
        public ?string $message = null,
21
        public ?array $arguments = null,
22
    ) {
23 8
        parent::__construct(self::TYPE);
24
    }
25
26 4
    public function jsonSerialize(): array
27
    {
28 4
        $data = parent::jsonSerialize();
29
30 4
        $data['level'] = $this->level->value;
31
32 4
        if ($this->message !== null) {
33 3
            $data['message'] = $this->message;
34
        }
35
36 4
        if ($this->arguments !== null && !empty($this->arguments)) {
37 1
            $data['arguments'] = $this->arguments;
38
        }
39
40 4
        return $data;
41
    }
42
}
43