Skip to content

Commit 29a0a4b

Browse files
committed
Fix lookup of first and last events (regression in last refactor)
1 parent d97d418 commit 29a0a4b

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/StateMachine/AEventProcessor.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,15 @@ public function getEventChain() : array
249249
* @return Event|null
250250
*/
251251
public function getFirstEvent() : ?Event {
252-
$lastKey = array_key_first($this->consumedEvents);
253-
return ($lastKey === null) ? null : $this->consumedEvents[$lastKey];
252+
return $this->consumedEvents[array_key_first($this->consumedEvents)] ?? null;
254253
}
255254

256255
/**
257256
* Get the most recent (last) event we handled
258257
* @return Event|null
259258
*/
260259
public function getLastEvent() : ?Event {
261-
$firstKey = array_key_first($this->consumedEvents);
262-
return ($firstKey === null) ? null : $this->consumedEvents[$firstKey];
260+
return $this->consumedEvents[array_key_last($this->consumedEvents)] ?? null;
263261
}
264262

265263
/**
@@ -307,7 +305,7 @@ public function trimEventChain(int $length) : void
307305
*/
308306
public function firstEventDateTime(): ?DateTimeInterface
309307
{
310-
return $this->consumedEvents[array_key_first($this->consumedEvents)]?->datetime;
308+
return ($this->consumedEvents[array_key_first($this->consumedEvents)] ?? null)?->datetime;
311309
}
312310

313311
/**
@@ -316,7 +314,7 @@ public function firstEventDateTime(): ?DateTimeInterface
316314
*/
317315
public function lastSeenEventDateTime(): ?DateTimeInterface
318316
{
319-
return $this->consumedEvents[array_key_last($this->consumedEvents)]?->datetime;
317+
return ($this->consumedEvents[array_key_last($this->consumedEvents)] ?? null)?->datetime;
320318
}
321319

322320
/**

0 commit comments

Comments
 (0)