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

MessageEcho   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 85
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
A isEcho() 0 4 1
A getAppId() 0 4 1
A getMetadata() 0 4 1
A create() 0 9 1
1
<?php
2
namespace Kerox\Messenger\Model\Callback;
3
4
class MessageEcho extends Message
5
{
6
7
    /**
8
     * @var bool
9
     */
10
    protected $isEcho;
11
12
    /**
13
     * @var int
14
     */
15
    protected $appId;
16
17
    /**
18
     * @var null|string
19
     */
20
    protected $metadata;
21
22
    /**
23
     * MessageEcho constructor.
24
     *
25
     * @param bool $isEcho
26
     * @param int $appId
27
     * @param string $messageId
28
     * @param int $sequence
29
     * @param string|null $metadata
30
     * @param string|null $text
31
     * @param string|null $quickReply
32
     * @param array $attachments
33
     */
34
    public function __construct(
35
        bool $isEcho,
36
        int $appId,
37
        string $messageId,
38
        int $sequence,
39
        string $metadata = null,
40
        string $text = null,
41
        string $quickReply = null,
42
        array $attachments = []
43
    ) {
44
        parent::__construct($messageId, $sequence, $text, $quickReply, $attachments);
45
46
        $this->isEcho = $isEcho;
47
        $this->appId = $appId;
48
        $this->metadata = $metadata;
49
    }
50
51
    /**
52
     * @return boolean
53
     */
54
    public function isEcho(): bool
55
    {
56
        return $this->isEcho;
57
    }
58
59
    /**
60
     * @return int
61
     */
62
    public function getAppId(): int
63
    {
64
        return $this->appId;
65
    }
66
67
    /**
68
     * @return null|string
69
     */
70
    public function getMetadata()
71
    {
72
        return $this->metadata;
73
    }
74
75
    /**
76
     * @param array $payload
77
     * @return static
78
     */
79
    public static function create(array $payload)
80
    {
81
        $metadata = $payload['metadata'] ?? null;
82
        $text = $payload['text'] ?? null;
83
        $quickReply = $payload['quick_reply']['payload'] ?? null;
84
        $attachments = $payload['attachments'] ?? [];
85
86
        return new static(true, $payload['app_id'], $payload['mid'], $payload['seq'], $metadata, $text, $quickReply, $attachments);
87
    }
88
}