PassThreadControlEvent::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Event;
6
7
use Kerox\Messenger\Model\Callback\PassThreadControl;
8
9
class PassThreadControlEvent extends AbstractEvent
10
{
11
    public const NAME = 'pass_thread_control';
12
13
    /**
14
     * @var int
15
     */
16
    protected $timestamp;
17
18
    /**
19
     * @var \Kerox\Messenger\Model\Callback\PassThreadControl
20
     */
21
    protected $passThreadControl;
22
23
    /**
24
     * PassThreadControlEvent constructor.
25
     */
26 2
    public function __construct(
27
        string $senderId,
28
        string $recipientId,
29
        int $timestamp,
30
        PassThreadControl $passThreadControl
31
    ) {
32 2
        parent::__construct($senderId, $recipientId);
33
34 2
        $this->timestamp = $timestamp;
35 2
        $this->passThreadControl = $passThreadControl;
36 2
    }
37
38 1
    public function getTimestamp(): int
39
    {
40 1
        return $this->timestamp;
41
    }
42
43 2
    public function getPassThreadControl(): PassThreadControl
44
    {
45 2
        return $this->passThreadControl;
46
    }
47
48 1
    public function getName(): string
49
    {
50 1
        return self::NAME;
51
    }
52
53
    /**
54
     * @return \Kerox\Messenger\Event\PassThreadControlEvent
55
     */
56 1
    public static function create(array $payload): self
57
    {
58 1
        $senderId = $payload['sender']['id'];
59 1
        $recipientId = $payload['recipient']['id'];
60 1
        $timestamp = $payload['timestamp'];
61 1
        $passThreadControl = PassThreadControl::create($payload['pass_thread_control']);
62
63 1
        return new static($senderId, $recipientId, $timestamp, $passThreadControl);
64
    }
65
}
66