EntityWithEvents::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Domain\Entities;
4
5
use Doctrine\ORM\Mapping AS ORM;
6
use Ramsey\Uuid\UuidInterface;
7
8
abstract class EntityWithEvents
9
{
10
    /**
11
     * @var UuidInterface
12
     * @ORM\Id
13
     * @ORM\Column(type="uuid", unique=true)
14
     * @ORM\GeneratedValue(strategy="NONE")
15
     */
16
    protected $id;
17
18
    private $events = [];
19
20
    protected function __construct(UuidInterface $id)
21
    {
22
        $this->id = $id;
23
    }
24
25
    public function releaseEvents(): array
26
    {
27
        $events = $this->events;
28
        $this->events = [];
29
30
        return $events;
31
    }
32
33
    protected function record($event)
34
    {
35
        $this->events[] = $event;
36
    }
37
38
    public function getId(): UuidInterface
39
    {
40
        return $this->id;
41
    }
42
}