Postback::getTitle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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