AggregateAccessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setVersionSequence() 0 3 1
A setAggregateId() 0 3 1
A shiftEvent() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Blixit\EventSourcing\Aggregate;
6
7
use Blixit\EventSourcing\Event\EventInterface;
8
use Blixit\EventSourcing\Utils\Accessor;
9
use function array_shift;
10
11
class AggregateAccessor extends Accessor
12
{
13
    /** @var AggregateAccessor $instance */
14
    protected static $instance;
15
16
    /**
17
     * @param mixed $value
18
     */
19
    public function setAggregateId(AggregateRootInterface &$aggregateRoot, $value) : void
20
    {
21
        $this->writeProperty($aggregateRoot, 'aggregateId', $value);
22
    }
23
24
    public function setVersionSequence(AggregateRootInterface &$aggregateRoot, int $value) : void
25
    {
26
        $this->writeProperty($aggregateRoot, 'versionSequence', $value);
27
    }
28
29
    public function shiftEvent(AggregateRootInterface &$aggregateRoot) : ?EventInterface
30
    {
31
        /** @var AggregateRoot $aggregateRoot */
32
        $events = $aggregateRoot->getRecordedEvents();
33
        $event  = array_shift($events);
34
        if (! empty($event)) {
35
            $this->writeProperty($aggregateRoot, 'recordedEvents', $events);
36
        }
37
        return $event;
38
    }
39
}
40