Completed
Pull Request — master (#35)
by Romain
02:33
created

PreCheckout::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
namespace Kerox\Messenger\Model\Callback;
3
4
use Kerox\Messenger\Model\Callback\Payment\RequestedUserInfo;
5
use Kerox\Messenger\Model\Common\Address;
6
7
class PreCheckout
8
{
9
10
    /**
11
     * @var string
12
     */
13
    protected $payload;
14
15
    /**
16
     * @var \Kerox\Messenger\Model\Callback\Payment\RequestedUserInfo
17
     */
18
    protected $requestedUserInfo;
19
20
    /**
21
     * @var array
22
     */
23
    protected $amount;
24
25
    /**
26
     * PreCheckout constructor.
27
     *
28
     * @param string $payload
29
     * @param \Kerox\Messenger\Model\Callback\Payment\RequestedUserInfo $requestedUserInfo
30
     * @param array $amount
31
     */
32 4
    public function __construct(string $payload, RequestedUserInfo $requestedUserInfo, array $amount)
33
    {
34 4
        $this->payload = $payload;
35 4
        $this->requestedUserInfo = $requestedUserInfo;
36 4
        $this->amount = $amount;
37 4
    }
38
39
    /**
40
     * @return string
41
     */
42 1
    public function getPayload(): string
43
    {
44 1
        return $this->payload;
45
    }
46
47
    /**
48
     * @return \Kerox\Messenger\Model\Callback\Payment\RequestedUserInfo
49
     */
50 2
    public function getRequestedUserInfo(): RequestedUserInfo
51
    {
52 2
        return $this->requestedUserInfo;
53
    }
54
55
    /**
56
     * @return \Kerox\Messenger\Model\Common\Address
57
     */
58 2
    public function getShippingAddress(): Address
59
    {
60 2
        return $this->requestedUserInfo->getShippingAddress();
61
    }
62
63
    /**
64
     * @return null|string
65
     */
66 1
    public function getCurrency()
67
    {
68 1
        return $this->amount['currency'] ?? null;
69
    }
70
71
    /**
72
     * @return null|string
73
     */
74 1
    public function getAmount()
75
    {
76 1
        return $this->amount['amount'] ?? null;
77
    }
78
79
    /**
80
     * @param array $payload
81
     * @return static
82
     */
83 4
    public static function create(array $payload)
84
    {
85 4
        $requestedUserInfo = RequestedUserInfo::create($payload['requested_user_info']);
86
87 4
        return new static($payload['payload'], $requestedUserInfo, $payload['amount']);
88
    }
89
}
90