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

PlayMediaCommand::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\StandardCommand;
6
7
use MaxBeckers\AmazonAlexa\Request\AudioTrack;
8
9
class PlayMediaCommand extends AbstractStandardCommand
10
{
11
    public const TYPE = 'PlayMedia';
12
13
    /**
14
     * @param string|null $componentId ID of the component to play media on
15
     * @param string|array|null $source Media source URL or array of sources
16
     * @param AudioTrack|null $audioTrack Audio track to play on
17
     */
18 7
    public function __construct(
19
        public ?string $componentId = null,
20
        public string|array|null $source = null,
21
        public ?AudioTrack $audioTrack = null,
22
    ) {
23 7
        parent::__construct(self::TYPE);
24
    }
25
26 4
    public function jsonSerialize(): array
27
    {
28 4
        $data = parent::jsonSerialize();
29
30 4
        if ($this->componentId !== null) {
31 3
            $data['componentId'] = $this->componentId;
32
        }
33
34 4
        if ($this->source !== null) {
35 3
            $data['source'] = $this->source;
36
        }
37
38 4
        if ($this->audioTrack !== null) {
39 1
            $data['audioTrack'] = $this->audioTrack->value;
40
        }
41
42 4
        return $data;
43
    }
44
}
45