Passed
Push — master ( fb865f...3ad45c )
by Romain
51s queued 14s
created

ReactionEvent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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