CommittedEvents   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 35
wmc 7
lcom 0
cbo 3
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 18 5
A getFromVersion() 0 4 1
A getToVersion() 0 4 1
1
<?php
2
3
namespace Domain\Eventing;
4
5
use Domain\Identity\Identity;
6
use Domain\Eventing\Exception\CorruptAggregateHistory;
7
8
/**
9
 * @author Sebastiaan Hilbers <[email protected]>
10
 */
11
class CommittedEvents extends AbstractEventStream
12
{
13
    private $fromVersion;
14
15
    private $toVersion;
16
17
    public function __construct(Identity $identity, array $events)
18
    {
19
        $this->identity = $identity;
20
21
        foreach ($events as $event) {
22
            if (!$event instanceof DomainEvent || !$event->getAggregateIdentity()->equals($identity)) {
23
                throw new CorruptAggregateHistory;
24
            }
25
26
            $this->events[] = $event;
27
        }
28
29
        if (count($events) > 0) {
30
            $this->fromVersion = array_shift(array_values($events));
0 ignored issues
show
Bug introduced by
array_values($events) cannot be passed to array_shift() as the parameter $array expects a reference.
Loading history...
31
            $this->toVersion = array_pop(array_values($events));
0 ignored issues
show
Bug introduced by
array_values($events) cannot be passed to array_pop() as the parameter $array expects a reference.
Loading history...
32
            reset($this->events);
33
        }
34
    }
35
36
    public function getFromVersion()
37
    {
38
        return $this->fromVersion->version;
39
    }
40
41
    public function getToVersion()
42
    {
43
        return $this->toVersion;
44
    }
45
}
46