EntityWithEvents   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getId() 0 3 1
A record() 0 3 1
A releaseEvents() 0 6 1
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
}