Passed
Push — master ( 0e21f4...195aeb )
by Romain
39s
created

Postback::hasReferral()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace Kerox\Messenger\Model\Callback;
3
4
class Postback
5
{
6
7
    /**
8
     * @var string
9
     */
10
    protected $payload;
11
12
    /**
13
     * @var null|\Kerox\Messenger\Model\Callback\Referral
14
     */
15
    protected $referral;
16
17
    /**
18
     * Postback constructor.
19
     *
20
     * @param string $payload
21
     * @param \Kerox\Messenger\Model\Callback\Referral $referral
22
     */
23 2
    public function __construct(string $payload, Referral $referral = null)
24
    {
25 2
        $this->payload = $payload;
26 2
        $this->referral = $referral;
27 2
    }
28
29
    /**
30
     * @return string
31
     */
32 1
    public function getPayload(): string
33
    {
34 1
        return $this->payload;
35
    }
36
37
    /**
38
     * @return bool
39
     */
40 1
    public function hasReferral(): bool
41
    {
42 1
        return $this->referral !== null;
43
    }
44
45
    /**
46
     * @return null|\Kerox\Messenger\Model\Callback\Referral
47
     */
48 1
    public function getReferral()
49
    {
50 1
        return $this->referral;
51
    }
52
53
    /**
54
     * @param array $payload
55
     * @return static
56
     */
57 1
    public static function create(array $payload)
58
    {
59 1
        $referral = isset($payload['referral']) ? Referral::create($payload['referral']) : null;
60
61 1
        return new static($payload['payload'], $referral);
62
    }
63
}
64