Passed
Pull Request — master (#65)
by Romain
02:01
created

AppRolesEvent   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 69
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getTimestamp() 0 4 1
A getAppRoles() 0 4 1
A getName() 0 4 1
A create() 0 9 2
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