Failed Conditions
Push — master ( c24b3a...b512e9 )
by Florent
14:42
created

Event::jsonSerialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\Core\Event;
15
16
use OAuth2Framework\Component\Core\Id\Id;
17
use OAuth2Framework\Component\Core\Domain\DomainObject;
18
19
abstract class Event implements DomainObject
20
{
21
    /**
22
     * @return mixed
23
     */
24
    abstract public function getPayload();
25
26
    /**
27
     * @return Id
28
     */
29
    abstract public function getDomainId(): Id;
30
31
    /**
32
     * @return string
33
     */
34
    public function getType(): string
35
    {
36
        return get_class($this);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function jsonSerialize()
43
    {
44
        $data = [
45
            '$schema' => $this->getSchema(),
46
            'type' => get_class($this),
47
            'domain_id' => $this->getDomainId()->getValue(),
48
        ];
49
        $payload = $this->getPayload();
50
        if (null !== $payload) {
51
            $data['payload'] = $payload;
52
        }
53
54
        return $data;
55
    }
56
}
57