Completed
Pull Request — master (#3)
by Romain
01:42
created

Message   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 104
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A getMessageId() 0 4 1
A getSequence() 0 4 1
A getText() 0 4 1
A getQuickReply() 0 4 1
A getAttachments() 0 4 1
A create() 0 8 1
1
<?php
2
namespace Kerox\Messenger\Model\Callback;
3
4
class Message
5
{
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
     * Message constructor.
34
     *
35
     * @param string $messageId
36
     * @param int $sequence
37
     * @param string $text
38
     * @param string $quickReply
39
     * @param array $attachments
40
     */
41
    public function __construct(
42
        string $messageId,
43
        int $sequence,
44
        string $text = null,
45
        string $quickReply = null,
46
        array $attachments = []
47
    ) {
48
        $this->messageId = $messageId;
49
        $this->sequence = $sequence;
50
        $this->text = $text;
51
        $this->quickReply = $quickReply;
52
        $this->attachments = $attachments;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getMessageId(): string
59
    {
60
        return $this->messageId;
61
    }
62
63
    /**
64
     * @return int
65
     */
66
    public function getSequence(): int
67
    {
68
        return $this->sequence;
69
    }
70
71
    /**
72
     * @return null|string
73
     */
74
    public function getText()
75
    {
76
        return $this->text;
77
    }
78
79
    /**
80
     * @return null|string
81
     */
82
    public function getQuickReply()
83
    {
84
        return $this->quickReply;
85
    }
86
87
    /**
88
     * @return array
89
     */
90
    public function getAttachments(): array
91
    {
92
        return $this->attachments;
93
    }
94
95
    /**
96
     * @param array $payload
97
     * @return static
98
     */
99
    public static function create(array $payload)
100
    {
101
        $text = $payload['text'] ?? null;
102
        $quickReply = $payload['quick_reply']['payload'] ?? null;
103
        $attachments = $payload['attachments'] ?? [];
104
105
        return new static($payload['mid'], $payload['seq'], $text, $quickReply, $attachments);
106
    }
107
}
108