Passed
Pull Request — master (#93)
by Romain
02:36
created

RequestThreadControlEvent::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 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
    public function __construct(
32
        string $senderId,
33
        string $recipientId,
34
        int $timestamp,
35
        RequestThreadControl $requestThreadControl
36
    ) {
37
        parent::__construct($senderId, $recipientId);
38
39
        $this->timestamp = $timestamp;
40
        $this->requestThreadControl = $requestThreadControl;
41
    }
42
43
    /**
44
     * @return int
45
     */
46
    public function getTimestamp(): int
47
    {
48
        return $this->timestamp;
49
    }
50
51
    /**
52
     * @return \Kerox\Messenger\Model\Callback\RequestThreadControl
53
     */
54
    public function getTakeThreadControl(): RequestThreadControl
55
    {
56
        return $this->requestThreadControl;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getName(): string
63
    {
64
        return self::NAME;
65
    }
66
67
    /**
68
     * @param array $payload
69
     *
70
     * @return \Kerox\Messenger\Event\RequestThreadControlEvent
71
     */
72
    public static function create(array $payload): self
73
    {
74
        $senderId = $payload['sender']['id'];
75
        $recipientId = $payload['recipient']['id'];
76
        $timestamp = $payload['timestamp'];
77
        $requestThreadControl = RequestThreadControl::create($payload['request_thread_control']);
78
79
        return new static($senderId, $recipientId, $timestamp, $requestThreadControl);
80
    }
81
}
82