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

InputEvent::fromAmazonRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 8
ccs 7
cts 7
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\Request\Request\GameEngine\Event;
6
7
class InputEvent
8
{
9
    public const ACTION_DOWN = 'down';
10
    public const ACTION_UP = 'up';
11
12
    /**
13
     * @param string $gadgetId Gadget identifier
14
     * @param \DateTime $timestamp Event timestamp
15
     * @param string $action Action type (down/up)
16
     * @param string $color Color of the input
17
     * @param string $feature Feature that triggered the event
18
     */
19
    public function __construct(
20
        public string $gadgetId,
21
        public \DateTime $timestamp,
22
        public string $action,
23
        public string $color,
24
        public string $feature,
25
    ) {
26
    }
27
28 1
    public static function fromAmazonRequest(array $amazonRequest): self
29
    {
30 1
        return new self(
31 1
            gadgetId: $amazonRequest['gadgetId'],
32 1
            timestamp: new \DateTime($amazonRequest['timestamp']),
33 1
            action: $amazonRequest['action'],
34 1
            color: $amazonRequest['color'],
35 1
            feature: $amazonRequest['feature'],
36 1
        );
37
    }
38
}
39