AuditEvent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 27
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setPayload() 0 9 2
A __construct() 0 7 2
A getPayload() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DH\Auditor\Event;
6
7
use DH\Auditor\Exception\InvalidArgumentException;
8
use DH\Auditor\Provider\Doctrine\Persistence\Helper\SchemaHelper;
9
use Symfony\Contracts\EventDispatcher\Event;
10
11
abstract class AuditEvent extends Event
12
{
13
    private array $payload;
14
15
    public function __construct(array $payload)
16
    {
17
        if (!SchemaHelper::isValidPayload($payload)) {
18
            throw new InvalidArgumentException('Invalid payload.');
19
        }
20
21
        $this->payload = $payload;
22
    }
23
24
    final public function setPayload(array $payload): self
25
    {
26
        if (!SchemaHelper::isValidPayload($payload)) {
27
            throw new InvalidArgumentException('Invalid payload.');
28
        }
29
30
        $this->payload = $payload;
31
32
        return $this;
33
    }
34
35
    final public function getPayload(): array
36
    {
37
        return $this->payload;
38
    }
39
}
40