From 33e5b56fd63183bf78a56fb22fe3b85c3bf0b0f8 Mon Sep 17 00:00:00 2001 From: David Badura Date: Tue, 2 Jan 2024 18:40:07 +0100 Subject: [PATCH] improve naming --- .../AggregateRootAttributeBehaviour.php | 10 +++++----- ...orted.php => AggregateRootIdNotSupported.php} | 10 +++++----- src/Aggregate/ApplyMethodNotFound.php | 6 +++--- .../AggregateRootClassNotRegistered.php | 4 ++-- ...dNotFound.php => AggregateRootIdNotFound.php} | 6 +++--- .../AggregateRootNameNotRegistered.php | 4 ++-- .../AggregateWithoutMetadataAware.php | 6 +++--- .../AttributeAggregateRootMetadataFactory.php | 2 +- .../AggregateRoot/DuplicateApplyMethod.php | 6 +++--- src/Metadata/AggregateRoot/NoAggregateRoot.php | 6 +++--- src/Metadata/Event/EventNameNotRegistered.php | 4 ++-- src/Repository/AggregateDetached.php | 8 ++++---- src/Repository/AggregateNotFound.php | 4 ++-- src/Repository/AggregateUnknown.php | 8 ++++---- src/Repository/PlayheadMismatch.php | 6 +++--- src/Repository/SnapshotRebuildFailed.php | 16 ++++++++-------- src/Repository/WrongAggregate.php | 6 +++--- src/Snapshot/SnapshotNotConfigured.php | 6 +++--- src/Snapshot/SnapshotNotFound.php | 8 ++++---- 19 files changed, 63 insertions(+), 63 deletions(-) rename src/Aggregate/{AggregateIdNotSupported.php => AggregateRootIdNotSupported.php} (51%) rename src/Metadata/AggregateRoot/{AggregateIdNotFound.php => AggregateRootIdNotFound.php} (56%) diff --git a/src/Aggregate/AggregateRootAttributeBehaviour.php b/src/Aggregate/AggregateRootAttributeBehaviour.php index f615e1f77..69ee4bf7b 100644 --- a/src/Aggregate/AggregateRootAttributeBehaviour.php +++ b/src/Aggregate/AggregateRootAttributeBehaviour.php @@ -43,13 +43,13 @@ public function aggregateRootId(): AggregateRootId $reflection = new ReflectionProperty($this, $metadata->idProperty); - /** @var mixed $aggregateId */ - $aggregateId = $reflection->getValue($this); + /** @var mixed $aggregateRootId */ + $aggregateRootId = $reflection->getValue($this); - if (!$aggregateId instanceof AggregateRootId) { - throw new AggregateIdNotSupported($this::class, $aggregateId); + if (!$aggregateRootId instanceof AggregateRootId) { + throw new AggregateRootIdNotSupported($this::class, $aggregateRootId); } - return $this->cachedAggregateRootId = $aggregateId; + return $this->cachedAggregateRootId = $aggregateRootId; } } diff --git a/src/Aggregate/AggregateIdNotSupported.php b/src/Aggregate/AggregateRootIdNotSupported.php similarity index 51% rename from src/Aggregate/AggregateIdNotSupported.php rename to src/Aggregate/AggregateRootIdNotSupported.php index 8d4a4bbb7..a8fcd3509 100644 --- a/src/Aggregate/AggregateIdNotSupported.php +++ b/src/Aggregate/AggregateRootIdNotSupported.php @@ -9,15 +9,15 @@ use function get_debug_type; use function sprintf; -final class AggregateIdNotSupported extends RuntimeException +final class AggregateRootIdNotSupported extends RuntimeException { - /** @param class-string $className */ - public function __construct(string $className, mixed $value) + /** @param class-string $aggregateRootClass */ + public function __construct(string $aggregateRootClass, mixed $value) { parent::__construct( sprintf( - 'aggregate id in class "%s" must be instance of "%s", got "%s"', - $className, + 'aggregate root id in class "%s" must be instance of "%s", got "%s"', + $aggregateRootClass, AggregateRootId::class, get_debug_type($value), ), diff --git a/src/Aggregate/ApplyMethodNotFound.php b/src/Aggregate/ApplyMethodNotFound.php index 9b25b1ac6..9de0ac582 100644 --- a/src/Aggregate/ApplyMethodNotFound.php +++ b/src/Aggregate/ApplyMethodNotFound.php @@ -9,15 +9,15 @@ final class ApplyMethodNotFound extends AggregateException { /** - * @param class-string $aggregate + * @param class-string $aggregateRootClass * @param class-string $event */ - public function __construct(string $aggregate, string $event) + public function __construct(string $aggregateRootClass, string $event) { parent::__construct( sprintf( 'Apply method in "%s" could not be found for the event "%s"', - $aggregate, + $aggregateRootClass, $event, ), ); diff --git a/src/Metadata/AggregateRoot/AggregateRootClassNotRegistered.php b/src/Metadata/AggregateRoot/AggregateRootClassNotRegistered.php index 8bddeaa98..cd7f80fa6 100644 --- a/src/Metadata/AggregateRoot/AggregateRootClassNotRegistered.php +++ b/src/Metadata/AggregateRoot/AggregateRootClassNotRegistered.php @@ -10,12 +10,12 @@ final class AggregateRootClassNotRegistered extends MetadataException { - public function __construct(string $eventClass) + public function __construct(string $aggregateRootClass) { parent::__construct( sprintf( 'Aggregate root class "%s" is not registered', - $eventClass, + $aggregateRootClass, ), ); } diff --git a/src/Metadata/AggregateRoot/AggregateIdNotFound.php b/src/Metadata/AggregateRoot/AggregateRootIdNotFound.php similarity index 56% rename from src/Metadata/AggregateRoot/AggregateIdNotFound.php rename to src/Metadata/AggregateRoot/AggregateRootIdNotFound.php index 6447e503d..222fc393a 100644 --- a/src/Metadata/AggregateRoot/AggregateIdNotFound.php +++ b/src/Metadata/AggregateRoot/AggregateRootIdNotFound.php @@ -8,10 +8,10 @@ use function sprintf; -final class AggregateIdNotFound extends RuntimeException +final class AggregateRootIdNotFound extends RuntimeException { - public function __construct(string $className) + public function __construct(string $aggregateRootClass) { - parent::__construct(sprintf('class %s has no property marked as aggregate id', $className)); + parent::__construct(sprintf('class %s has no property marked as aggregate root id', $aggregateRootClass)); } } diff --git a/src/Metadata/AggregateRoot/AggregateRootNameNotRegistered.php b/src/Metadata/AggregateRoot/AggregateRootNameNotRegistered.php index db7f5b145..ce6519da1 100644 --- a/src/Metadata/AggregateRoot/AggregateRootNameNotRegistered.php +++ b/src/Metadata/AggregateRoot/AggregateRootNameNotRegistered.php @@ -10,12 +10,12 @@ final class AggregateRootNameNotRegistered extends MetadataException { - public function __construct(string $evenName) + public function __construct(string $name) { parent::__construct( sprintf( 'Aggregate root name "%s" is not registered', - $evenName, + $name, ), ); } diff --git a/src/Metadata/AggregateRoot/AggregateWithoutMetadataAware.php b/src/Metadata/AggregateRoot/AggregateWithoutMetadataAware.php index 9cd0f1577..0fdf90263 100644 --- a/src/Metadata/AggregateRoot/AggregateWithoutMetadataAware.php +++ b/src/Metadata/AggregateRoot/AggregateWithoutMetadataAware.php @@ -10,9 +10,9 @@ final class AggregateWithoutMetadataAware extends MetadataException { - /** @param class-string $class */ - public function __construct(string $class) + /** @param class-string $aggregateRootClass */ + public function __construct(string $aggregateRootClass) { - parent::__construct(sprintf('The class "%s" does not implements AggregateRootMetadataAware', $class)); + parent::__construct(sprintf('The class "%s" does not implements AggregateRootMetadataAware', $aggregateRootClass)); } } diff --git a/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php b/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php index 9422608a7..99a03aaa6 100644 --- a/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php +++ b/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php @@ -114,7 +114,7 @@ private function findIdProperty(ReflectionClass $reflector): string return $property->getName(); } - throw new AggregateIdNotFound($reflector->getName()); + throw new AggregateRootIdNotFound($reflector->getName()); } private function findSnapshot(ReflectionClass $reflector): Snapshot|null diff --git a/src/Metadata/AggregateRoot/DuplicateApplyMethod.php b/src/Metadata/AggregateRoot/DuplicateApplyMethod.php index 2e648ea0a..8e5107317 100644 --- a/src/Metadata/AggregateRoot/DuplicateApplyMethod.php +++ b/src/Metadata/AggregateRoot/DuplicateApplyMethod.php @@ -12,17 +12,17 @@ final class DuplicateApplyMethod extends MetadataException { /** - * @param class-string $aggregate + * @param class-string $aggregateRootClass * @param class-string $event */ - public function __construct(string $aggregate, string $event, string $fistMethod, string $secondMethod) + public function __construct(string $aggregateRootClass, string $event, string $fistMethod, string $secondMethod) { parent::__construct( sprintf( 'Two methods "%s" and "%s" on the aggregate "%s" want to apply the same event "%s". Only one method can apply an event.', $fistMethod, $secondMethod, - $aggregate, + $aggregateRootClass, $event, ), ); diff --git a/src/Metadata/AggregateRoot/NoAggregateRoot.php b/src/Metadata/AggregateRoot/NoAggregateRoot.php index ece78fb91..ba3f9ecbc 100644 --- a/src/Metadata/AggregateRoot/NoAggregateRoot.php +++ b/src/Metadata/AggregateRoot/NoAggregateRoot.php @@ -10,9 +10,9 @@ final class NoAggregateRoot extends MetadataException { - /** @param class-string $class */ - public function __construct(string $class) + /** @param class-string $aggregateRootClass */ + public function __construct(string $aggregateRootClass) { - parent::__construct(sprintf('The class "%s" does not implement AggregateRoot', $class)); + parent::__construct(sprintf('The class "%s" does not implement AggregateRoot', $aggregateRootClass)); } } diff --git a/src/Metadata/Event/EventNameNotRegistered.php b/src/Metadata/Event/EventNameNotRegistered.php index 663d4497c..bc113c167 100644 --- a/src/Metadata/Event/EventNameNotRegistered.php +++ b/src/Metadata/Event/EventNameNotRegistered.php @@ -10,12 +10,12 @@ final class EventNameNotRegistered extends MetadataException { - public function __construct(string $evenName) + public function __construct(string $name) { parent::__construct( sprintf( 'Event name "%s" is not registered', - $evenName, + $name, ), ); } diff --git a/src/Repository/AggregateDetached.php b/src/Repository/AggregateDetached.php index faa7b0f8e..eb164cb9f 100644 --- a/src/Repository/AggregateDetached.php +++ b/src/Repository/AggregateDetached.php @@ -11,14 +11,14 @@ final class AggregateDetached extends RepositoryException { - /** @param class-string $aggregateClass */ - public function __construct(string $aggregateClass, AggregateRootId $aggregateId) + /** @param class-string $aggregateRootClass */ + public function __construct(string $aggregateRootClass, AggregateRootId $aggregateRootId) { parent::__construct( sprintf( 'An error occurred while saving the aggregate "%s" with the ID "%s", causing the uncommitted events to be lost. Please reload the aggregate.', - $aggregateClass, - $aggregateId->toString(), + $aggregateRootClass, + $aggregateRootId->toString(), ), ); } diff --git a/src/Repository/AggregateNotFound.php b/src/Repository/AggregateNotFound.php index 7b46eaf4e..33e864725 100644 --- a/src/Repository/AggregateNotFound.php +++ b/src/Repository/AggregateNotFound.php @@ -10,8 +10,8 @@ final class AggregateNotFound extends RepositoryException { - public function __construct(string $aggregateClass, AggregateRootId $id) + public function __construct(string $aggregateRootClass, AggregateRootId $rootId) { - parent::__construct(sprintf('aggregate "%s::%s" not found', $aggregateClass, $id->toString())); + parent::__construct(sprintf('aggregate "%s::%s" not found', $aggregateRootClass, $rootId->toString())); } } diff --git a/src/Repository/AggregateUnknown.php b/src/Repository/AggregateUnknown.php index 8a7277ef3..bbdad3f45 100644 --- a/src/Repository/AggregateUnknown.php +++ b/src/Repository/AggregateUnknown.php @@ -11,14 +11,14 @@ final class AggregateUnknown extends RepositoryException { - /** @param class-string $aggregateClass */ - public function __construct(string $aggregateClass, AggregateRootId $aggregateId) + /** @param class-string $aggregateRootClass */ + public function __construct(string $aggregateRootClass, AggregateRootId $aggregateRootId) { parent::__construct( sprintf( 'The aggregate %s with the ID "%s" was not loaded from this repository. Please reload the aggregate.', - $aggregateClass, - $aggregateId->toString(), + $aggregateRootClass, + $aggregateRootId->toString(), ), ); } diff --git a/src/Repository/PlayheadMismatch.php b/src/Repository/PlayheadMismatch.php index 82175e097..d8199b9a8 100644 --- a/src/Repository/PlayheadMismatch.php +++ b/src/Repository/PlayheadMismatch.php @@ -10,14 +10,14 @@ final class PlayheadMismatch extends RepositoryException { - public function __construct(string $aggregateClass, AggregateRootId $aggregateId, int $playhead, int $eventCount) + public function __construct(string $aggregateRootClass, AggregateRootId $aggregateRootId, int $playhead, int $eventCount) { parent::__construct(sprintf( 'There is a mismatch between the playhead [%s] and the event count [%s] for the aggregate [%s] with the id [%s]', $playhead, $eventCount, - $aggregateClass, - $aggregateId->toString(), + $aggregateRootClass, + $aggregateRootId->toString(), )); } } diff --git a/src/Repository/SnapshotRebuildFailed.php b/src/Repository/SnapshotRebuildFailed.php index 29d7962d3..a4d5aa74b 100644 --- a/src/Repository/SnapshotRebuildFailed.php +++ b/src/Repository/SnapshotRebuildFailed.php @@ -12,17 +12,17 @@ final class SnapshotRebuildFailed extends RepositoryException { - /** @param class-string $aggregateClass */ + /** @param class-string $aggregateRootClass */ public function __construct( - private string $aggregateClass, - private AggregateRootId $aggregateId, + private string $aggregateRootClass, + private AggregateRootId $aggregateRootId, Throwable $previous, ) { parent::__construct( sprintf( 'Rebuild from snapshot of aggregate "%s" with the id "%s" failed', - $aggregateClass, - $aggregateId->toString(), + $aggregateRootClass, + $aggregateRootId->toString(), ), 0, $previous, @@ -32,11 +32,11 @@ public function __construct( /** @return class-string */ public function aggregateClass(): string { - return $this->aggregateClass; + return $this->aggregateRootClass; } - public function aggregateId(): AggregateRootId + public function aggregateRootId(): AggregateRootId { - return $this->aggregateId; + return $this->aggregateRootId; } } diff --git a/src/Repository/WrongAggregate.php b/src/Repository/WrongAggregate.php index 3c864a671..3536e877b 100644 --- a/src/Repository/WrongAggregate.php +++ b/src/Repository/WrongAggregate.php @@ -9,13 +9,13 @@ final class WrongAggregate extends RepositoryException { /** - * @param class-string $aggregateClass + * @param class-string $aggregateRootClass * @param class-string $expected */ - public function __construct(string $aggregateClass, string $expected) + public function __construct(string $aggregateRootClass, string $expected) { parent::__construct( - sprintf('Wrong aggregate given: got "%s" but expected "%s"', $aggregateClass, $expected), + sprintf('Wrong aggregate given: got "%s" but expected "%s"', $aggregateRootClass, $expected), ); } } diff --git a/src/Snapshot/SnapshotNotConfigured.php b/src/Snapshot/SnapshotNotConfigured.php index bd948a13a..ef862d512 100644 --- a/src/Snapshot/SnapshotNotConfigured.php +++ b/src/Snapshot/SnapshotNotConfigured.php @@ -10,13 +10,13 @@ final class SnapshotNotConfigured extends SnapshotException { - /** @param class-string $aggregateClass */ - public function __construct(string $aggregateClass) + /** @param class-string $aggregateRootClass */ + public function __construct(string $aggregateRootClass) { parent::__construct( sprintf( 'Missing snapshot configuration for the aggregate class "%s"', - $aggregateClass, + $aggregateRootClass, ), ); } diff --git a/src/Snapshot/SnapshotNotFound.php b/src/Snapshot/SnapshotNotFound.php index d606d0ca4..e41f69234 100644 --- a/src/Snapshot/SnapshotNotFound.php +++ b/src/Snapshot/SnapshotNotFound.php @@ -12,14 +12,14 @@ final class SnapshotNotFound extends SnapshotException { - /** @param class-string $aggregate */ - public function __construct(string $aggregate, AggregateRootId $id, Throwable|null $previous = null) + /** @param class-string $aggregateRootClass */ + public function __construct(string $aggregateRootClass, AggregateRootId $rootId, Throwable|null $previous = null) { parent::__construct( sprintf( 'snapshot for aggregate "%s" with the id "%s" not found', - $aggregate, - $id->toString(), + $aggregateRootClass, + $rootId->toString(), ), 0, $previous,