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

PreCheckout   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 1
dl 0
loc 83
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getPayload() 0 4 1
A getRequestedUserInfo() 0 4 1
A getShippingAddress() 0 4 1
A getCurrency() 0 4 1
A getAmount() 0 4 1
A create() 0 6 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