Passed
Pull Request — master (#62)
by Romain
02:05
created

TakeThreadControlEvent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 69
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getTimestamp() 0 4 1
A getTakeThreadControl() 0 4 1
A getName() 0 4 1
A create() 0 9 1
1
<?php
2
3
namespace Kerox\Messenger\Event;
4
5
use Kerox\Messenger\Model\Callback\TakeThreadControl;
6
7
class TakeThreadControlEvent extends AbstractEvent
8
{
9
    const NAME = 'take_thread_control';
10
11
    /**
12
     * @var int
13
     */
14
    protected $timestamp;
15
16
    /**
17
     * @var \Kerox\Messenger\Model\Callback\TakeThreadControl
18
     */
19
    protected $takeThreadControl;
20
21
    /**
22
     * TakeThreadControlEvent constructor.
23
     *
24
     * @param string                                            $senderId
25
     * @param string                                            $recipientId
26
     * @param int                                               $timestamp
27
     * @param \Kerox\Messenger\Model\Callback\TakeThreadControl $takeThreadControl
28
     */
29 2
    public function __construct(string $senderId, string $recipientId, int $timestamp, TakeThreadControl $takeThreadControl)
30
    {
31 2
        parent::__construct($senderId, $recipientId);
32
33 2
        $this->timestamp = $timestamp;
34 2
        $this->takeThreadControl = $takeThreadControl;
35 2
    }
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\TakeThreadControl
47
     */
48 1
    public function getTakeThreadControl(): TakeThreadControl
49
    {
50 1
        return $this->takeThreadControl;
51
    }
52
53
    /**
54
     * @return string
55
     */
56 1
    public function getName(): string
57
    {
58 1
        return self::NAME;
59
    }
60
61
    /**
62
     * @param array $payload
63
     *
64
     * @return \Kerox\Messenger\Event\TakeThreadControlEvent
65
     */
66 1
    public static function create(array $payload): TakeThreadControlEvent
67
    {
68 1
        $senderId = $payload['sender']['id'];
69 1
        $recipientId = $payload['recipient']['id'];
70 1
        $timestamp = $payload['timestamp'];
71 1
        $takeThreadControl = TakeThreadControl::create($payload['take_thread_control']);
72
73 1
        return new static($senderId, $recipientId, $timestamp, $takeThreadControl);
74
    }
75
}
76