Completed
Pull Request — master (#41)
by David
12:31 queued 09:06
created

EventStore::retrieveLog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Rawkode\Eidetic\EventStore;
4
5
use Rawkode\Eidetic\EventSourcing\EventSourcedEntity;
6
7
abstract class EventStore implements Serializer
8
{
9
    use EventPublisherMixin;
10
11
    // Subscriber hooks
12
    const EVENT_STORED = 'eidetic.eventstore.event_stored';
13
14
    // Implement these in your concretion
15
16
    /**
17
     * @param EventSourcedEntity $eventSourcedEntity
18
     * @param object             $event
0 ignored issues
show
Bug introduced by
There is no parameter named $event. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
19
     *
20
     * @throws InvalidEventException
21
     */
22
    abstract protected function persist(EventSourcedEntity $eventSourcedEntity);
23
24
    /**
25
     * Return all event log entries for $entityIdentifier.
26
     *
27
     * @param string $entityIdentifier
28
     *
29
     * @return array
30
     */
31
    abstract protected function eventLog($entityIdentifier);
32
33
    abstract protected function startTransaction();
34
    abstract protected function abortTransaction();
35
    abstract protected function completeTransaction();
36
37
    /** @var array */
38
    private $stagedEvents = [];
39
40
    /** @var Serializer */
41
    protected $serializer;
42
43
    /**
44
     * Store an EventSourcedEntity's staged events.
45
     *
46
     * @param string $key
0 ignored issues
show
Bug introduced by
There is no parameter named $key. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
47
     * @param array  $events
0 ignored issues
show
Documentation introduced by
There is no parameter named $events. Did you maybe mean $eventSourcedEntity?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
48
     *
49
     * @throws InvalidEventException
50
     */
51 8
    public function store(EventSourcedEntity $eventSourcedEntity)
52
    {
53
        try {
54 8
            $this->startTransaction();
55 8
            $this->persist($eventSourcedEntity);
56 8
        } catch (Exception $exception) {
0 ignored issues
show
Bug introduced by
The class Rawkode\Eidetic\EventStore\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
57
            $this->abortTransaction();
58
            throw $exception;
59
        }
60
61 8
        $this->completeTransaction();
62 8
    }
63
64
    /**
65
     * Returns all events for $entityIdentifier.
66
     *
67
     * @param string $key
0 ignored issues
show
Bug introduced by
There is no parameter named $key. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
68
     *
69
     * @return array
70
     */
71 4
    public function retrieve($entityIdentifier)
72
    {
73 4
        $eventLog = $this->eventLog($entityIdentifier);
74
75 2
        return array_map(function ($eventLogEntry) {
76 2
            return $eventLogEntry['event'];
77 2
        }, $eventLog);
78
    }
79
80
    /**
81
     * Returns all the log entries for $entityIdentifier.
82
     *
83
     * @param string $key
0 ignored issues
show
Bug introduced by
There is no parameter named $key. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
84
     *
85
     * @return array
86
     */
87 4
    public function retrieveLog($entityIdentifier)
88
    {
89 4
        return $this->eventLog($entityIdentifier);
90
    }
91
92
    /**
93
     * @return array
94
     */
95
    protected function stagedEvents()
96
    {
97
        return $this->stagedEvents;
98
    }
99
100
    /**
101
     * @param object $object
102
     *
103
     * @return string
104
     */
105 8
    public function serialize($object)
106
    {
107 8
        if (false === is_null($this->serializer)) {
108
            return $this->serializer->serialize($object);
109
        }
110
111 8
        return base64_encode(serialize($object));
112
    }
113
114
    /**
115
     * @param string $serializedObject
116
     *
117
     * @return object
118
     */
119 6
    public function unserialize($serializedObject)
120
    {
121 6
        if (false === is_null($this->serializer)) {
122
            return $this->serializer->serialize($serializedObject);
123
        }
124
125 6
        return unserialize(base64_decode($serializedObject));
126
    }
127
}
128