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

ReactionEvent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTimestamp() 0 3 1
A create() 0 8 1
A getName() 0 3 1
A __construct() 0 6 1
A getReaction() 0 3 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