Test Failed
Pull Request — master (#74)
by
unknown
08:19
created

Message::getEntities()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Kerox\Messenger\Model\Callback;
4
5
class Message
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $messageId;
11
12
    /**
13
     * @var int
14
     */
15
    protected $sequence;
16
17
    /**
18
     * @var null|string
19
     */
20
    protected $text;
21
22
    /**
23
     * @var null|string
24
     */
25
    protected $quickReply;
26
27
    /**
28
     * @var array
29
     */
30
    protected $attachments;
31
32
    /**
33
     * @var null|array
34
     */
35
    protected $entities;
36
37
    /**
38
     * Message constructor.
39
     *
40
     * @param string $messageId
41
     * @param int    $sequence
42
     * @param string $text
43
     * @param string $quickReply
44
     * @param array  $attachments
45
     */
46
    public function __construct(
47
        string $messageId,
48
        int $sequence,
49
        array $entities = [],
50
        string $text = null,
51
        string $quickReply = null,
52
        array $attachments = []
53
    ) {
54
        $this->messageId = $messageId;
55
        $this->sequence = $sequence;
56
        $this->text = $text;
57
        $this->quickReply = $quickReply;
58
        $this->attachments = $attachments;
59
        $this->entities = $entities;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getMessageId(): string
66
    {
67
        return $this->messageId;
68
    }
69
70
    /**
71
     * @return int
72
     */
73
    public function getSequence(): int
74
    {
75
        return $this->sequence;
76
    }
77
78
    /**
79
     * @return null|string
80
     */
81
    public function getText()
82
    {
83
        return $this->text;
84
    }
85
86
    /**
87
     * @return bool
88
     */
89
    public function hasText(): bool
90
    {
91
        return $this->text !== null && $this->text !== '';
92
    }
93
94
    /**
95
     * @return null|string
96
     */
97
    public function getQuickReply()
98
    {
99
        return $this->quickReply;
100
    }
101
102
    /**
103
     * @return bool
104
     */
105
    public function hasQuickReply(): bool
106
    {
107
        return $this->quickReply !== null && $this->quickReply !== '';
108
    }
109
110
    /**
111
        * @return array
112
        */
113
    public function getAttachments(): array
114
    {
115
        return $this->attachments;
116
    }
117
118
    /**
119
     * @return array
120
     */
121
    public function getEntities(): array
122
    {
123
        return $this->entities;
124
    }
125
126
    /**
127
     * @return bool
128
     */
129
    public function hasAttachments(): bool
130
    {
131
        return !empty($this->attachments);
132
    }
133
134
    /**
135
     * @param array $callbackData
136
     *
137
     * @return \Kerox\Messenger\Model\Callback\Message
138
     */
139
    public static function create(array $callbackData)
140
    {
141
        $text = $callbackData['text'] ?? null;
142
        $quickReply = $callbackData['quick_reply']['payload'] ?? null;
143
        $attachments = $callbackData['attachments'] ?? [];
144
145
        return new static(
146
            $callbackData['mid'],
147
            $callbackData['seq'],
148
            isset($callbackData['nlp']) ? $callbackData['nlp']['entities'] : null,
149
            $text,
150
            $quickReply,
151
            $attachments
152
        );
153
    }
154
}
155