Passed
Pull Request — master (#7)
by Damien
03:55
created

AuditEvent::setPayload()   A

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
namespace DH\Auditor\Event;
4
5
use DH\Auditor\Exception\InvalidArgumentException;
6
use DH\Auditor\Provider\Doctrine\Persistence\Helper\SchemaHelper;
7
use Symfony\Component\EventDispatcher\Event as ComponentEvent;
8
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
9
10
if (class_exists(ContractsEvent::class)) {
11
    abstract class AuditEvent extends ContractsEvent
12
    {
13
        /**
14
         * @var array
15
         */
16
        private $payload;
17
18
        public function __construct(array $payload)
19
        {
20
            if (!SchemaHelper::isValidPayload($payload)) {
21
                throw new InvalidArgumentException('Invalid payload.');
22
            }
23
24
            $this->payload = $payload;
25
        }
26
27
        final public function setPayload(array $payload): ContractsEvent
28
        {
29
            if (!SchemaHelper::isValidPayload($payload)) {
30
                throw new InvalidArgumentException('Invalid payload.');
31
            }
32
33
            $this->payload = $payload;
34
35
            return $this;
36
        }
37
38
        final public function getPayload(): array
39
        {
40
            return $this->payload;
41
        }
42
    }
43
} else {
44
    abstract class AuditEvent extends ComponentEvent
45
    {
46
        /**
47
         * @var array
48
         */
49
        private $payload;
50
51
        public function __construct(array $payload)
52
        {
53
            if (!SchemaHelper::isValidPayload($payload)) {
54
                throw new InvalidArgumentException('Invalid payload.');
55
            }
56
57
            $this->payload = $payload;
58
        }
59
60
        final public function setPayload(array $payload): ComponentEvent
61
        {
62
            if (!SchemaHelper::isValidPayload($payload)) {
63
                throw new InvalidArgumentException('Invalid payload.');
64
            }
65
66
            $this->payload = $payload;
67
68
            return $this;
69
        }
70
71
        final public function getPayload(): array
72
        {
73
            return $this->payload;
74
        }
75
    }
76
}
77