Passed
Push — master ( 8f851d...b464b5 )
by Maximilian
01:07 queued 11s
created

Payload::fromAmazonRequest()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 4
nc 8
nop 1
1
<?php
2
3
namespace MaxBeckers\AmazonAlexa\Request\Request\System;
4
5
/**
6
 * @author Maximilian Beckers <[email protected]>
7
 */
8
class Payload
9
{
10
    const RESULT_ACCEPTED          = 'ACCEPTED';
11
    const RESULT_DECLINED          = 'DECLINED';
12
    const RESULT_ALREADY_PURCHASED = 'ALREADY_PURCHASED';
13
    const RESULT_ERROR             = 'ERROR';
14
15
    /**
16
     * @var string|null
17
     */
18
    public $purchaseResult;
19
20
    /**
21
     * @var string|null
22
     */
23
    public $productId;
24
25
    /**
26
     * @var string|null
27
     */
28
    public $message;
29
30
    /**
31
     * @param array $amazonRequest
32
     *
33
     * @return Payload
34
     */
35
    public static function fromAmazonRequest(array $amazonRequest): self
36
    {
37
        $status = new self();
38
39
        $status->purchaseResult = isset($amazonRequest['purchaseResult']) ? $amazonRequest['purchaseResult'] : null;
40
        $status->productId      = isset($amazonRequest['productId']) ? $amazonRequest['productId'] : null;
41
        $status->message        = isset($amazonRequest['message']) ? $amazonRequest['message'] : null;
42
43
        return $status;
44
    }
45
}
46