AuditEvent::setPayload()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 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