PolicyEnforcementEvent   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
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 57
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

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