Completed
Pull Request — master (#73)
by Romain
02:08
created

Postback::getTitle()   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
3
namespace Kerox\Messenger\Model\Callback;
4
5
class Postback
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $title;
11
12
    /**
13
     * @var null|string
14
     */
15
    protected $payload;
16
17
    /**
18
     * @var null|\Kerox\Messenger\Model\Callback\Referral
19
     */
20
    protected $referral;
21
22
    /**
23
     * Postback constructor.
24
     *
25
     * @param string                                   $title
26
     * @param null|string                              $payload
27
     * @param \Kerox\Messenger\Model\Callback\Referral $referral
28
     */
29 3
    public function __construct(string $title, $payload = null, $referral = null)
30
    {
31 3
        $this->title = $title;
32 3
        $this->payload = $payload;
33 3
        $this->referral = $referral;
34 3
    }
35
36
    /**
37
     * @return string
38
     */
39 2
    public function getTitle(): string
40
    {
41 2
        return $this->title;
42
    }
43
44
    /**
45
     * @return bool
46
     */
47 2
    public function hasPayload(): bool
48
    {
49 2
        return $this->payload !== null;
50
    }
51
52
    /**
53
     * @return null|string
54
     */
55 2
    public function getPayload()
56
    {
57 2
        return $this->payload;
58
    }
59
60
    /**
61
     * @return bool
62
     */
63 2
    public function hasReferral(): bool
64
    {
65 2
        return $this->referral !== null;
66
    }
67
68
    /**
69
     * @return null|\Kerox\Messenger\Model\Callback\Referral
70
     */
71 2
    public function getReferral()
72
    {
73 2
        return $this->referral;
74
    }
75
76
    /**
77
     * @param array $callbackData
78
     *
79
     * @return \Kerox\Messenger\Model\Callback\Postback
80
     */
81 2
    public static function create(array $callbackData): Postback
82
    {
83 2
        $payload = $callbackData['payload'] ?? null;
84 2
        $referral = isset($callbackData['referral']) ? Referral::create($callbackData['referral']) : null;
85
86 2
        return new static($callbackData['title'], $payload, $referral);
87
    }
88
}
89