From fa0c38b12a5fba38a97876c474658d11500f31fe Mon Sep 17 00:00:00 2001 From: bwaidelich Date: Mon, 11 Apr 2022 11:21:50 +0200 Subject: [PATCH] This change corrects return types to "static" where late static binding is used and corrects `new static` to `new self` in classes declared as `final`. *Exceptions:* For `DeferEventPublisher` and `DefaultAppliedEventsStorage` the class name itself is used in order to prevent IDEs to complain about the use of `static` in a final class. Those classes currently rely on Flow object management so `self` refers to the proxy class Resolves #309 --- Classes/AbstractEventSourcedAggregateRoot.php | 2 +- Classes/Event/EventTypeResolver.php | 2 +- .../AppliedEventsStorage/DefaultAppliedEventsStorage.php | 2 +- Classes/EventListener/Mapping/EventToListenerMapping.php | 2 +- Classes/EventPublisher/DeferEventPublisher.php | 2 +- Classes/EventStore/WritableEvents.php | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Classes/AbstractEventSourcedAggregateRoot.php b/Classes/AbstractEventSourcedAggregateRoot.php index 1e7d00d3..d3d1b5b1 100644 --- a/Classes/AbstractEventSourcedAggregateRoot.php +++ b/Classes/AbstractEventSourcedAggregateRoot.php @@ -49,7 +49,7 @@ final public function getReconstitutionVersion(): int return $this->reconstitutionVersion; } - final public static function reconstituteFromEventStream(EventStream $stream): self + final public static function reconstituteFromEventStream(EventStream $stream): static { $instance = new static(); $lastAppliedEventVersion = -1; diff --git a/Classes/Event/EventTypeResolver.php b/Classes/Event/EventTypeResolver.php index bf5ad24f..8ef038d9 100644 --- a/Classes/Event/EventTypeResolver.php +++ b/Classes/Event/EventTypeResolver.php @@ -56,7 +56,7 @@ public function injectObjectManager(ObjectManagerInterface $objectManager): void */ public function initializeObject(): void { - $this->mapping = static::eventTypeMapping($this->objectManager); + $this->mapping = self::eventTypeMapping($this->objectManager); $this->reversedMapping = array_flip($this->mapping); } diff --git a/Classes/EventListener/AppliedEventsStorage/DefaultAppliedEventsStorage.php b/Classes/EventListener/AppliedEventsStorage/DefaultAppliedEventsStorage.php index cd301e38..cbf37721 100644 --- a/Classes/EventListener/AppliedEventsStorage/DefaultAppliedEventsStorage.php +++ b/Classes/EventListener/AppliedEventsStorage/DefaultAppliedEventsStorage.php @@ -55,7 +55,7 @@ protected function __construct(string $eventListenerIdentifier) */ public static function forEventListener(EventListenerInterface $listener): self { - return new static(\get_class($listener)); + return new DefaultAppliedEventsStorage(\get_class($listener)); } /** diff --git a/Classes/EventListener/Mapping/EventToListenerMapping.php b/Classes/EventListener/Mapping/EventToListenerMapping.php index 305082e8..1ddc4d9a 100644 --- a/Classes/EventListener/Mapping/EventToListenerMapping.php +++ b/Classes/EventListener/Mapping/EventToListenerMapping.php @@ -45,7 +45,7 @@ private function __construct(string $eventClassName, string $listenerClassName, public static function create(string $eventClassName, string $listenerClassName, array $options): self { - return new static($eventClassName, $listenerClassName, $options); + return new self($eventClassName, $listenerClassName, $options); } public function getEventClassName(): string diff --git a/Classes/EventPublisher/DeferEventPublisher.php b/Classes/EventPublisher/DeferEventPublisher.php index c0e2526d..a6851b0d 100644 --- a/Classes/EventPublisher/DeferEventPublisher.php +++ b/Classes/EventPublisher/DeferEventPublisher.php @@ -39,7 +39,7 @@ protected function __construct(EventPublisherInterface $wrappedEventPublisher) public static function forPublisher(EventPublisherInterface $eventPublisher): self { - return new static($eventPublisher); + return new DeferEventPublisher($eventPublisher); } /** diff --git a/Classes/EventStore/WritableEvents.php b/Classes/EventStore/WritableEvents.php index 9c6c4629..2f61d14b 100644 --- a/Classes/EventStore/WritableEvents.php +++ b/Classes/EventStore/WritableEvents.php @@ -37,14 +37,14 @@ public static function fromArray(array $events): self throw new \InvalidArgumentException(sprintf('Only instances of WritableEvent are allowed, given: %s', \is_object($event) ? \get_class($event) : \gettype($event)), 1540316594); } } - return new static(array_values($events)); + return new self(array_values($events)); } public function append(WritableEvent $event): self { $events = $this->events; $events[] = $event; - return new static($events); + return new self($events); } /**