Passed
Push — master ( 7891a8...364829 )
by Romain
01:13
created

AppRolesEvent::getAppRoles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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