Passed
Pull Request — master (#77)
by Maximilian
06:13
created

Payload   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 36
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromAmazonRequest() 0 9 4
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