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

LogCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 32
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 1
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 15 4
A __construct() 0 6 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