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

MessageEvent   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 68.42%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 77
ccs 13
cts 19
cp 0.6842
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getTimestamp() 0 4 1
A getMessage() 0 4 1
A getName() 0 4 1
A isQuickReply() 0 4 1
A create() 0 9 1
1
<?php
2
3
namespace Kerox\Messenger\Event;
4
5
use Kerox\Messenger\Model\Callback\Message;
6
7
class MessageEvent extends AbstractEvent
8
{
9
    const NAME = 'message';
10
11
    /**
12
     * @var int
13
     */
14
    protected $timestamp;
15
16
    /**
17
     * @var \Kerox\Messenger\Model\Callback\Message
18
     */
19
    protected $message;
20
21
    /**
22
     * MessageEvent constructor.
23
     *
24
     * @param string                                  $senderId
25
     * @param string                                  $recipientId
26
     * @param int                                     $timestamp
27
     * @param \Kerox\Messenger\Model\Callback\Message $message
28
     */
29 1
    public function __construct(string $senderId, string $recipientId, int $timestamp, Message $message)
30
    {
31 1
        parent::__construct($senderId, $recipientId);
32
33 1
        $this->timestamp = $timestamp;
34 1
        $this->message = $message;
35 1
    }
36
37
    /**
38
     * @return int
39
     */
40 1
    public function getTimestamp(): int
41
    {
42 1
        return $this->timestamp;
43
    }
44
45
    /**
46
     * @return \Kerox\Messenger\Model\Callback\Message
47
     */
48 1
    public function getMessage(): Message
49
    {
50 1
        return $this->message;
51
    }
52
53
    /**
54
     * @return string
55
     */
56 1
    public function getName(): string
57
    {
58 1
        return self::NAME;
59
    }
60
61
    /**
62
     * @return bool
63
     */
64 1
    public function isQuickReply(): bool
65
    {
66 1
        return $this->message->hasQuickReply();
67
    }
68
69
    /**
70
     * @param array $payload
71
     *
72
     * @return \Kerox\Messenger\Event\MessageEvent
73
     */
74
    public static function create(array $payload): MessageEvent
75
    {
76
        $senderId = $payload['sender']['id'];
77
        $recipientId = $payload['recipient']['id'];
78
        $timestamp = $payload['timestamp'];
79
        $message = Message::create($payload['message']);
80
81
        return new static($senderId, $recipientId, $timestamp, $message);
82
    }
83
}
84