diff --git a/src/Enums/MetaData.php b/src/Enums/MetaData.php index 5a77c523..4d10e758 100644 --- a/src/Enums/MetaData.php +++ b/src/Enums/MetaData.php @@ -4,8 +4,8 @@ class MetaData { - const AGGREGATE_ROOT_UUID = 'aggregate-root-uuid'; - const STORED_EVENT_ID = 'stored-event-id'; - const CREATED_AT = 'created-at'; - const AGGREGATE_ROOT_VERSION = 'aggregate-root-version'; + public const AGGREGATE_ROOT_UUID = 'aggregate-root-uuid'; + public const STORED_EVENT_ID = 'stored-event-id'; + public const CREATED_AT = 'created-at'; + public const AGGREGATE_ROOT_VERSION = 'aggregate-root-version'; } diff --git a/src/EventSerializers/JsonEventSerializer.php b/src/EventSerializers/JsonEventSerializer.php index 9999b695..07f674af 100644 --- a/src/EventSerializers/JsonEventSerializer.php +++ b/src/EventSerializers/JsonEventSerializer.php @@ -14,7 +14,7 @@ public function __construct() { $encoders = [new JsonEncoder()]; $normalizers = array_map( - fn ($className) => new $className, + fn ($className) => new $className(), config('event-sourcing.event_normalizers') ); diff --git a/src/Snapshots/EloquentSnapshotRepository.php b/src/Snapshots/EloquentSnapshotRepository.php index 1ac2fdf4..f7806508 100644 --- a/src/Snapshots/EloquentSnapshotRepository.php +++ b/src/Snapshots/EloquentSnapshotRepository.php @@ -12,7 +12,7 @@ public function __construct() { $this->snapshotModel = (string)config('event-sourcing.snapshot_model', EloquentSnapshot::class); - if (! new $this->snapshotModel instanceof EloquentSnapshot) { + if (! new $this->snapshotModel() instanceof EloquentSnapshot) { throw new InvalidEloquentSnapshotModel("The class {$this->snapshotModel} must extend EloquentSnapshot"); } } diff --git a/src/StoredEvents/Repositories/EloquentStoredEventRepository.php b/src/StoredEvents/Repositories/EloquentStoredEventRepository.php index f3c63869..8966f29f 100644 --- a/src/StoredEvents/Repositories/EloquentStoredEventRepository.php +++ b/src/StoredEvents/Repositories/EloquentStoredEventRepository.php @@ -21,7 +21,7 @@ public function __construct() { $this->storedEventModel = (string) config('event-sourcing.stored_event_model', EloquentStoredEvent::class); - if (! new $this->storedEventModel instanceof EloquentStoredEvent) { + if (! new $this->storedEventModel() instanceof EloquentStoredEvent) { throw new InvalidEloquentStoredEventModel("The class {$this->storedEventModel} must extend EloquentStoredEvent"); } } diff --git a/src/Support/ModelIdentifierNormalizer.php b/src/Support/ModelIdentifierNormalizer.php index 0b105e9f..ff94c146 100644 --- a/src/Support/ModelIdentifierNormalizer.php +++ b/src/Support/ModelIdentifierNormalizer.php @@ -13,7 +13,7 @@ class ModelIdentifierNormalizer implements NormalizerInterface, DenormalizerInterface { use SerializesAndRestoresModelIdentifiers; - + /** * @inheritdoc */ @@ -22,10 +22,10 @@ public function normalize($object, string $format = null, array $context = []) if (! $this->supportsNormalization($object)) { throw new InvalidArgumentException('Cannot serialize an object that is not a QueueableEntity or QueueableCollection in ModelIdentifierNormalizer.'); } - + return $this->getSerializedPropertyValue($object); } - + /** * @inheritdoc */ @@ -33,7 +33,7 @@ public function supportsNormalization($data, string $format = null) { return ($data instanceof QueueableEntity || $data instanceof QueueableCollection); } - + /** * @inheritdoc */ @@ -42,10 +42,10 @@ public function denormalize($data, $class, string $format = null, array $context $identifier = $data instanceof ModelIdentifier ? $data : new ModelIdentifier($data['class'], $data['id'], $data['relations'], $data['connection']); - + return $this->getRestoredPropertyValue($identifier); } - + /** * @inheritdoc */ @@ -54,13 +54,13 @@ public function supportsDenormalization($data, $type, string $format = null) return $this->normalizedDataIsModelIdentifier($data) && $this->isNormalizedToModelIdentifier($type); } - + protected function normalizedDataIsModelIdentifier($data): bool { return $data instanceof ModelIdentifier || isset($data['class'], $data['id'], $data['relations'], $data['connection']); } - + protected function isNormalizedToModelIdentifier($class): bool { return is_a($class, QueueableEntity::class, true) diff --git a/tests/AggregateRoots/AggregatePartialTest.php b/tests/AggregateRoots/AggregatePartialTest.php index 036e7357..127d9c0e 100644 --- a/tests/AggregateRoots/AggregatePartialTest.php +++ b/tests/AggregateRoots/AggregatePartialTest.php @@ -23,7 +23,7 @@ public function test_entities() ->addItem('test 2') ->persist(); - $this->assertDatabaseCount((new EloquentStoredEvent)->getTable(), 2); + $this->assertDatabaseCount((new EloquentStoredEvent())->getTable(), 2); $cart::retrieve(self::CART_UUID); @@ -87,7 +87,7 @@ public function addItem(string $name): self public function clear(): self { - $this->recordThat(new CartCleared); + $this->recordThat(new CartCleared()); return $this; } diff --git a/tests/AggregateRoots/CommandHandlerTest.php b/tests/AggregateRoots/CommandHandlerTest.php index ada466ae..d69c9bbf 100644 --- a/tests/AggregateRoots/CommandHandlerTest.php +++ b/tests/AggregateRoots/CommandHandlerTest.php @@ -69,7 +69,7 @@ public function __construct() public function clear(ClearCart $clearCart): self { - $this->recordThat(new CartClearedForCommand); + $this->recordThat(new CartClearedForCommand()); return $this; } diff --git a/tests/EloquentStoredEventRepositoryTest.php b/tests/EloquentStoredEventRepositoryTest.php index 6150ab4f..23acba5c 100644 --- a/tests/EloquentStoredEventRepositoryTest.php +++ b/tests/EloquentStoredEventRepositoryTest.php @@ -29,15 +29,15 @@ public function it_can_get_the_latest_version_id_for_a_given_aggregate_uuid() $this->assertEquals(1, $eloquentStoredEventRepository->getLatestAggregateVersion('uuid-2')); $this->assertEquals(2, $eloquentStoredEventRepository->getLatestAggregateVersion('uuid-1')); } - + /** @test */ public function it_sets_the_original_event_on_persist() { $eloquentStoredEventRepository = app(EloquentStoredEventRepository::class); - + $originalEvent = new MoneyAdded(100); $storedEvent = $eloquentStoredEventRepository->persist($originalEvent, 'uuid-1', 1); - + $this->assertSame($originalEvent, $storedEvent->event); } }