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

InputEvent   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
dl 0
loc 29
ccs 7
cts 9
cp 0.7778
rs 10
c 1
b 0
f 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromAmazonRequest() 0 8 1
A __construct() 0 7 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