diff --git a/src/Attribute/Aggregate.php b/src/Attribute/Aggregate.php index f843ac22d..8f7e4280c 100644 --- a/src/Attribute/Aggregate.php +++ b/src/Attribute/Aggregate.php @@ -10,12 +10,7 @@ final class Aggregate { public function __construct( - private string $name, + public readonly string $name, ) { } - - public function name(): string - { - return $this->name; - } } diff --git a/src/Attribute/Apply.php b/src/Attribute/Apply.php index 7796f32ba..e3e39a5bf 100644 --- a/src/Attribute/Apply.php +++ b/src/Attribute/Apply.php @@ -11,13 +11,7 @@ final class Apply { /** @param class-string|null $eventClass */ public function __construct( - private string|null $eventClass = null, + public readonly string|null $eventClass = null, ) { } - - /** @return class-string|null */ - public function eventClass(): string|null - { - return $this->eventClass; - } } diff --git a/src/Attribute/Event.php b/src/Attribute/Event.php index d127791eb..fdcafe900 100644 --- a/src/Attribute/Event.php +++ b/src/Attribute/Event.php @@ -10,12 +10,7 @@ final class Event { public function __construct( - private string $name, + public readonly string $name, ) { } - - public function name(): string - { - return $this->name; - } } diff --git a/src/Attribute/Projector.php b/src/Attribute/Projector.php index 04c3ca079..c5c02cdd4 100644 --- a/src/Attribute/Projector.php +++ b/src/Attribute/Projector.php @@ -10,18 +10,8 @@ final class Projector { public function __construct( - private string $name, - private int $version = 0, + public readonly string $name, + public readonly int $version = 0, ) { } - - public function name(): string - { - return $this->name; - } - - public function version(): int - { - return $this->version; - } } diff --git a/src/Attribute/Snapshot.php b/src/Attribute/Snapshot.php index ced487637..571ca11fb 100644 --- a/src/Attribute/Snapshot.php +++ b/src/Attribute/Snapshot.php @@ -10,24 +10,9 @@ final class Snapshot { public function __construct( - private string $name, - private int|null $batch = null, - private string|null $version = null, + public readonly string $name, + public readonly int|null $batch = null, + public readonly string|null $version = null, ) { } - - public function name(): string - { - return $this->name; - } - - public function batch(): int|null - { - return $this->batch; - } - - public function version(): string|null - { - return $this->version; - } } diff --git a/src/Attribute/Subscribe.php b/src/Attribute/Subscribe.php index 780c73dc8..78fc19415 100644 --- a/src/Attribute/Subscribe.php +++ b/src/Attribute/Subscribe.php @@ -11,13 +11,7 @@ final class Subscribe { /** @param class-string $eventClass */ public function __construct( - private string $eventClass, + public readonly string $eventClass, ) { } - - /** @return class-string */ - public function eventClass(): string - { - return $this->eventClass; - } } diff --git a/src/Attribute/SuppressMissingApply.php b/src/Attribute/SuppressMissingApply.php index 0abd54a1b..8e234de4b 100644 --- a/src/Attribute/SuppressMissingApply.php +++ b/src/Attribute/SuppressMissingApply.php @@ -12,29 +12,20 @@ final class SuppressMissingApply public const ALL = '*'; /** @var list */ - private array $suppressEvents = []; - private bool $suppressAll = false; + public readonly array $suppressEvents; + public readonly bool $suppressAll; /** @param list|self::ALL $suppress */ public function __construct(string|array $suppress) { if ($suppress === self::ALL) { + $this->suppressEvents = []; $this->suppressAll = true; return; } $this->suppressEvents = $suppress; - } - - /** @return list */ - public function suppressEvents(): array - { - return $this->suppressEvents; - } - - public function suppressAll(): bool - { - return $this->suppressAll; + $this->suppressAll = false; } } diff --git a/src/EventBus/Subscriber.php b/src/EventBus/Subscriber.php index a1e02ceb5..994bdfacf 100644 --- a/src/EventBus/Subscriber.php +++ b/src/EventBus/Subscriber.php @@ -41,7 +41,7 @@ private function init(): void foreach ($attributes as $attribute) { $instance = $attribute->newInstance(); - $eventClass = $instance->eventClass(); + $eventClass = $instance->eventClass; if (array_key_exists($eventClass, $this->subscribeMethods)) { throw new DuplicateSubscribeMethod( diff --git a/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php b/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php index 99a03aaa6..e2c351c08 100644 --- a/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php +++ b/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php @@ -73,13 +73,13 @@ private function findSuppressMissingApply(ReflectionClass $reflector): array foreach ($attributes as $attribute) { $instance = $attribute->newInstance(); - if ($instance->suppressAll()) { + if ($instance->suppressAll) { $suppressAll = true; continue; } - foreach ($instance->suppressEvents() as $event) { + foreach ($instance->suppressEvents as $event) { $suppressEvents[$event] = true; } } @@ -97,7 +97,7 @@ private function findAggregateName(ReflectionClass $reflector): string $aggregateAttribute = $attributeReflectionList[0]->newInstance(); - return $aggregateAttribute->name(); + return $aggregateAttribute->name; } private function findIdProperty(ReflectionClass $reflector): string @@ -128,9 +128,9 @@ private function findSnapshot(ReflectionClass $reflector): Snapshot|null $attribute = $attributeReflectionList[0]->newInstance(); return new Snapshot( - $attribute->name(), - $attribute->batch(), - $attribute->version(), + $attribute->name, + $attribute->batch, + $attribute->version, ); } @@ -159,7 +159,7 @@ private function findApplyMethods(ReflectionClass $reflector, string $aggregate) foreach ($attributes as $attribute) { $applyAttribute = $attribute->newInstance(); - $eventClass = $applyAttribute->eventClass(); + $eventClass = $applyAttribute->eventClass; if ($eventClass !== null) { $hasOneNonEmptyApply = true; diff --git a/src/Metadata/AggregateRoot/AttributeAggregateRootRegistryFactory.php b/src/Metadata/AggregateRoot/AttributeAggregateRootRegistryFactory.php index 4bb1b1cfa..d309f9e24 100644 --- a/src/Metadata/AggregateRoot/AttributeAggregateRootRegistryFactory.php +++ b/src/Metadata/AggregateRoot/AttributeAggregateRootRegistryFactory.php @@ -33,7 +33,7 @@ public function create(array $paths): AggregateRootRegistry throw new NoAggregateRoot($class); } - $aggregateName = $attributes[0]->newInstance()->name(); + $aggregateName = $attributes[0]->newInstance()->name; $result[$aggregateName] = $class; } diff --git a/src/Metadata/Event/AttributeEventMetadataFactory.php b/src/Metadata/Event/AttributeEventMetadataFactory.php index 2f2763fdd..5245fb4ca 100644 --- a/src/Metadata/Event/AttributeEventMetadataFactory.php +++ b/src/Metadata/Event/AttributeEventMetadataFactory.php @@ -32,10 +32,9 @@ public function metadata(string $event): EventMetadata } $eventAttribute = $attributeReflectionList[0]->newInstance(); - $eventName = $eventAttribute->name(); $this->eventMetadata[$event] = new EventMetadata( - $eventName, + $eventAttribute->name, $this->splitStream($reflectionClass), ); diff --git a/src/Metadata/Event/AttributeEventRegistryFactory.php b/src/Metadata/Event/AttributeEventRegistryFactory.php index 240225a2f..591d75cb8 100644 --- a/src/Metadata/Event/AttributeEventRegistryFactory.php +++ b/src/Metadata/Event/AttributeEventRegistryFactory.php @@ -27,7 +27,7 @@ public function create(array $paths): EventRegistry continue; } - $eventName = $attributes[0]->newInstance()->name(); + $eventName = $attributes[0]->newInstance()->name; $result[$eventName] = $class; } diff --git a/src/Metadata/Projector/AttributeProjectorMetadataFactory.php b/src/Metadata/Projector/AttributeProjectorMetadataFactory.php index 01ce448ad..aa0c2a72b 100644 --- a/src/Metadata/Projector/AttributeProjectorMetadataFactory.php +++ b/src/Metadata/Projector/AttributeProjectorMetadataFactory.php @@ -32,7 +32,7 @@ public function metadata(string $projector): ProjectorMetadata throw new ClassIsNotAProjector($projector); } - $projection = $attributes[0]->newInstance(); + $projectorInfo = $attributes[0]->newInstance(); $methods = $reflector->getMethods(); @@ -45,7 +45,7 @@ public function metadata(string $projector): ProjectorMetadata foreach ($attributes as $attribute) { $instance = $attribute->newInstance(); - $eventClass = $instance->eventClass(); + $eventClass = $instance->eventClass; if (array_key_exists($eventClass, $subscribeMethods)) { throw new DuplicateSubscribeMethod( @@ -87,8 +87,8 @@ public function metadata(string $projector): ProjectorMetadata } $metadata = new ProjectorMetadata( - $projection->name(), - $projection->version(), + $projectorInfo->name, + $projectorInfo->version, $subscribeMethods, $createMethod, $dropMethod, diff --git a/tests/Unit/Attribute/SuppressMissingApplyTest.php b/tests/Unit/Attribute/SuppressMissingApplyTest.php index ad0d251d6..f7ea6f865 100644 --- a/tests/Unit/Attribute/SuppressMissingApplyTest.php +++ b/tests/Unit/Attribute/SuppressMissingApplyTest.php @@ -15,15 +15,15 @@ public function testSuppressEvents(): void { $attribute = new SuppressMissingApply([ProfileCreated::class]); - self::assertSame([ProfileCreated::class], $attribute->suppressEvents()); - self::assertSame(false, $attribute->suppressAll()); + self::assertSame([ProfileCreated::class], $attribute->suppressEvents); + self::assertSame(false, $attribute->suppressAll); } public function testSuppressAll(): void { $attribute = new SuppressMissingApply(SuppressMissingApply::ALL); - self::assertSame([], $attribute->suppressEvents()); - self::assertSame(true, $attribute->suppressAll()); + self::assertSame([], $attribute->suppressEvents); + self::assertSame(true, $attribute->suppressAll); } }