RawEvent::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

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