Completed
Push — master ( 3c1d03...7e0a80 )
by Dmitry
14:29
created

AbstractEvent::createdAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace hiapi\event;
4
5
use Ramsey\Uuid\Uuid;
6
use Ramsey\Uuid\UuidInterface;
7
8
/**
9
 * Class AbstractEvent
10
 *
11
 * @author Dmytro Naumenko <[email protected]>
12
 */
13
class AbstractEvent extends \League\Event\AbstractEvent implements EventInterface
14
{
15
    /**
16
     * @var UuidInterface
17
     */
18
    private $uuid;
19
    /**
20
     * @var \DateTimeImmutable
21
     */
22
    private $createdAt;
23
    /**
24
     * @var object
25
     */
26
    protected $target;
27
28
    /**
29
     * AbstractEvent constructor.
30
     *
31
     * @param null $target
32
     * @throws \Exception
33
     */
34
    public function __construct($target = null)
35
    {
36
        $this->uuid = Uuid::uuid4();
37
        $this->createdAt = new \DateTimeImmutable();
38
        $this->target = $target;
39
    }
40
41
    /**
42
     * @return object|null
43
     */
44
    public function getTarget()
45
    {
46
        return $this->target;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function uuid(): UuidInterface
53
    {
54
        return $this->uuid;
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60
    public function type(): string
61
    {
62
        return $this->getName();
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    public function createdAt(): \DateTimeImmutable
69
    {
70
        return $this->createdAt;
71
    }
72
73
    /**
74
     * @inheritdoc
75
     */
76
    public function getName()
77
    {
78
        $path = explode('\\', get_class($this));
79
        return array_pop($path);
80
    }
81
82
    /**
83
     * @return array|mixed
84
     */
85
    public function jsonSerialize()
86
    {
87
        return [
88
            'uuid' => $this->uuid(),
89
            'name' => $this->getName(),
90
            'createdAt' => $this->createdAt(),
91
        ];
92
    }
93
}
94