Conditions | 11 |
Paths | 1 |
Total Lines | 32 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
41 | public function find(EventMatcherInterface $eventMatcher) : array |
||
42 | { |
||
43 | $aggregateId = $eventMatcher->getAggregateId(); |
||
44 | $aggregateClass = $eventMatcher->getAggregateClass(); |
||
45 | $fromSequence = $eventMatcher->getSequence(); |
||
46 | $streamName = $eventMatcher->getStreamName(); |
||
47 | $timestamp = $eventMatcher->getTimestamp(); |
||
48 | |||
49 | return array_filter($this->events, static function (EventInterface $event) use ( |
||
50 | $aggregateId, |
||
51 | $aggregateClass, |
||
52 | $fromSequence, |
||
53 | $streamName, |
||
54 | $timestamp |
||
55 | ) { |
||
56 | $condition = true; |
||
57 | if (! empty($aggregateId)) { |
||
58 | $condition = $condition && ($event->getAggregateId() === (string) $aggregateId); |
||
59 | } |
||
60 | if (! empty($aggregateClass)) { |
||
61 | $condition = $condition && ($event->getAggregateClass() === (string) $aggregateClass); |
||
62 | } |
||
63 | if (! empty($fromSequence)) { |
||
64 | $condition = $condition && ($event->getSequence() > $fromSequence); |
||
65 | } |
||
66 | if (! empty($streamName)) { |
||
67 | $condition = $condition && ($event->getStreamName() === (string) $streamName); |
||
68 | } |
||
69 | if (! empty($timestamp)) { |
||
70 | $condition = $condition && ($event->getStreamName() > $timestamp); |
||
71 | } |
||
72 | return $condition; |
||
73 | }); |
||
76 |