Passed
Push — master ( 8a7749...5c0d1f )
by Romain
39s queued 10s
created

RequestThreadControlEvent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 71
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

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