Skip to content

Commit

Permalink
This change corrects return types to "static" where late static
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bwaidelich committed Apr 11, 2022
1 parent 6f5dc83 commit fa0c38b
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Classes/AbstractEventSourcedAggregateRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Event/EventTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Classes/EventListener/Mapping/EventToListenerMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Classes/EventPublisher/DeferEventPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function __construct(EventPublisherInterface $wrappedEventPublisher)

public static function forPublisher(EventPublisherInterface $eventPublisher): self
{
return new static($eventPublisher);
return new DeferEventPublisher($eventPublisher);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Classes/EventStore/WritableEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit fa0c38b

Please sign in to comment.