Completed
Pull Request — master (#24)
by David
02:37
created

EventPublishingEventStore::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4286
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Rawkode\Eidetic\EventStore;
4
5
use Rawkode\Eidetic\EventSourcing\EventSourcedEntity;
6
7
/**
8
 *
9
 */
10
final class EventPublishingEventStore implements EventStore
11
{
12
    /**
13
     * @var EventStore
14
     */
15
    private $eventStore;
16
17
    /**
18
     * @var EventPublisher
19
     */
20
    private $eventPublisher;
21
22
    /**
23
     * @param EventStore     $eventStore
24
     * @param EventPublisher $eventPublisher
25
     */
26
    public function __construct(EventStore $eventStore, EventPublisher $eventPublisher)
27
    {
28
        $this->eventStore = $eventStore;
29
        $this->eventPublisher = $eventPublisher;
30
    }
31
32
    /**
33
     * @param EventSourcedEntity $eventSourcedEntity
34
     */
35
    public function store(EventSourcedEntity $eventSourcedEntity)
36
    {
37
        $stagedEvents = $eventSourcedEntity->stagedEvents();
38
39
        $this->eventStore->store($eventSourcedEntity->identifier(), $eventSourcedEntity->stagedEvents());
40
41
        $this->publish($stagedEvents);
42
    }
43
44
    /**
45
     * @param string $identifier
46
     *
47
     * @return array
48
     */
49
    public function retrieve($identifier)
50
    {
51
        return $this->eventStore->retrieve($identifier);
52
    }
53
54
    /**
55
     * @param string $identifier
56
     *
57
     * @return array
58
     */
59
    public function retrieveLogs($identifier)
60
    {
61
        return $this->eventStore->retrieveEventLogs($identifier);
0 ignored issues
show
Bug introduced by
The method retrieveEventLogs() does not exist on Rawkode\Eidetic\EventStore\EventStore. Did you maybe mean retrieve()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
62
    }
63
64
    /**
65
     * @param array $events
66
     */
67
    private function publish(array $events)
68
    {
69
        foreach ($events as $event) {
70
            $this->eventPublisher->publish($event);
71
        }
72
    }
73
}
74