FileAggregateRoot   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A eraseEvents() 0 4 1
A events() 0 4 1
A publish() 0 4 1
A record() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the BenGorFile package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorFile\File\Domain\Model;
14
15
/**
16
 * File aggregate root class.
17
 *
18
 * @author Beñat Espiña <[email protected]>
19
 */
20
abstract class FileAggregateRoot
21
{
22
    /**
23
     * Array which contains the domain events.
24
     *
25
     * @var array
26
     */
27
    private $events = [];
28
29
    /**
30
     * Clears the events container.
31
     */
32
    public function eraseEvents()
33
    {
34
        $this->events = [];
35
    }
36
37
    /**
38
     * Gets the recorded domain events.
39
     *
40
     * @return array
41
     */
42
    public function events()
43
    {
44
        return $this->events;
45
    }
46
47
    /**
48
     * Publishes the domain event.
49
     *
50
     * If the solution needs a singleton based event system,
51
     * this methods will be overwritten.
52
     *
53
     * The recommend way is to record events domains in the aggregate root
54
     * so, by default, this method calls to the "record" method.
55
     *
56
     * @param FileEvent $anEvent The domain event
57
     */
58
    protected function publish(FileEvent $anEvent)
59
    {
60
        $this->record($anEvent);
61
    }
62
63
    /**
64
     * Saves the given domain event inside event container.
65
     *
66
     * @param FileEvent $anEvent The domain event
67
     */
68
    private function record(FileEvent $anEvent)
69
    {
70
        $this->events[] = $anEvent;
71
    }
72
}
73