Completed
Pull Request — master (#51)
by Romain
02:30 queued 18s
created

RawEvent::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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