Completed
Push — master ( 3fb39c...d85d4f )
by Romain
10s
created

GamePlayEvent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 67
rs 10
c 0
b 0
f 0

5 Methods

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