PolicyEnforcementEvent::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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