From 5c3cc30a03ef92358745cb9bdfcae46c554195b4 Mon Sep 17 00:00:00 2001 From: Sander van Thillo Date: Tue, 24 Oct 2017 09:17:51 +0200 Subject: [PATCH] PHP 7 (#317) * require PHP 7 * declare(strict_types=1); * type hints * minor cs fixes * minor improvements --- .php_cs | 1 + .travis.yml | 5 ++- composer.json | 2 +- examples/auditing/log-command-status.php | 6 ++-- examples/bootstrap.php | 2 ++ .../command-handling/command-handling.php | 2 ++ .../event-dispatcher/event-dispatcher.php | 2 ++ examples/event-handling/event-handling.php | 2 ++ examples/event-sourced-child-entity/Parts.php | 2 ++ .../event-sourced-child-entity/PartsTest.php | 2 ++ .../InvitationCommandHandlerTest.php | 2 ++ .../Invites.php | 2 ++ .../InvitesTest.php | 2 ++ .../JobSeekers.php | 2 ++ .../JobSeekersTest.php | 2 ++ examples/serializer/serializer.php | 2 ++ src/Broadway/Auditing/CommandLogger.php | 4 ++- src/Broadway/Auditing/CommandSerializer.php | 4 ++- .../Auditing/NullByteCommandSerializer.php | 4 ++- .../CommandHandling/ClosureCommandHandler.php | 2 ++ src/Broadway/CommandHandling/CommandBus.php | 2 ++ .../CommandHandling/CommandHandler.php | 2 ++ .../EventDispatchingCommandBus.php | 2 ++ .../ClosureParameterNotAnObjectException.php | 2 ++ .../Exception/CommandNotAnObjectException.php | 2 ++ .../CommandHandling/SimpleCommandBus.php | 2 ++ .../CommandHandling/SimpleCommandHandler.php | 4 ++- .../CommandHandlerScenarioTestCase.php | 6 ++-- .../CommandHandling/Testing/Scenario.php | 15 ++++---- .../Testing/TraceableCommandBus.php | 4 ++- src/Broadway/Domain/AggregateRoot.php | 6 ++-- src/Broadway/Domain/DateTime.php | 26 ++++++++------ src/Broadway/Domain/DomainEventStream.php | 4 ++- src/Broadway/Domain/DomainMessage.php | 24 +++++++------ src/Broadway/Domain/Metadata.php | 19 +++++------ .../CallableEventDispatcher.php | 6 ++-- .../EventDispatcher/EventDispatcher.php | 6 ++-- .../Testing/TraceableEventDispatcher.php | 8 +++-- src/Broadway/EventHandling/EventBus.php | 2 ++ src/Broadway/EventHandling/EventListener.php | 2 ++ src/Broadway/EventHandling/SimpleEventBus.php | 2 ++ .../EventHandling/TraceableEventBus.php | 4 ++- .../AggregateFactory/AggregateFactory.php | 9 +++-- .../NamedConstructorAggregateFactory.php | 5 ++- .../PublicConstructorAggregateFactory.php | 5 ++- .../ReflectionAggregateFactory.php | 4 ++- ...ggregateRootAlreadyRegisteredException.php | 2 ++ .../EventSourcedAggregateRoot.php | 10 +++--- .../EventSourcing/EventSourcedEntity.php | 2 ++ .../EventSourcing/EventSourcingRepository.php | 12 ++++--- .../EventSourcing/EventStreamDecorator.php | 4 ++- .../MetadataEnrichment/MetadataEnricher.php | 4 ++- .../MetadataEnrichingEventStreamDecorator.php | 4 ++- .../SimpleEventSourcedEntity.php | 6 ++-- .../Testing/AggregateRootScenarioTestCase.php | 11 +++--- .../EventSourcing/Testing/Scenario.php | 31 ++++++++--------- .../EventStore/CallableEventVisitor.php | 2 ++ .../BlacklistConcurrencyConflictResolver.php | 14 +++++--- .../ConcurrencyConflictResolver.php | 5 ++- .../WhitelistConcurrencyConflictResolver.php | 16 ++++++--- ...ConcurrencyConflictResolvingEventStore.php | 13 ++++--- src/Broadway/EventStore/EventStore.php | 8 +++-- .../EventStore/EventStoreException.php | 2 ++ .../EventStreamNotFoundException.php | 2 ++ src/Broadway/EventStore/EventVisitor.php | 2 ++ .../Exception/DuplicatePlayheadException.php | 6 ++-- .../Exception/InvalidIdentifierException.php | 2 ++ .../EventStore/InMemoryEventStore.php | 8 +++-- .../InMemoryEventStoreException.php | 2 ++ .../EventStore/Management/Criteria.php | 34 +++++++++++-------- .../CriteriaNotSupportedException.php | 2 ++ .../Management/EventStoreManagement.php | 2 ++ .../EventStoreManagementException.php | 2 ++ .../EventStore/TraceableEventStore.php | 8 +++-- src/Broadway/Processor/Processor.php | 4 ++- src/Broadway/ReadModel/Identifiable.php | 4 ++- .../ReadModel/InMemory/InMemoryRepository.php | 6 ++-- .../InMemory/InMemoryRepositoryFactory.php | 5 ++- src/Broadway/ReadModel/Projector.php | 4 ++- src/Broadway/ReadModel/Repository.php | 10 +++--- src/Broadway/ReadModel/RepositoryFactory.php | 4 ++- .../ReadModel/SerializableReadModel.php | 2 ++ .../Testing/DomainMessageScenario.php | 8 +++-- .../Testing/ProjectorScenarioTestCase.php | 6 ++-- src/Broadway/ReadModel/Testing/Scenario.php | 14 ++++---- .../Testing/SerializableReadModelTestCase.php | 4 ++- src/Broadway/ReadModel/Transferable.php | 2 ++ .../Repository/AggregateNotFoundException.php | 4 ++- src/Broadway/Repository/Repository.php | 7 ++-- src/Broadway/Serializer/Serializable.php | 4 ++- .../Serializer/SerializationException.php | 2 ++ src/Broadway/Serializer/Serializer.php | 10 ++++-- .../Serializer/SimpleInterfaceSerializer.php | 4 ++- .../Testing/SerializableEventTestCase.php | 2 ++ test/Broadway/Auditing/CommandLoggerTest.php | 2 ++ .../NullByteCommandSerializerTest.php | 2 ++ .../CommandHandling/CommandHandlerTest.php | 2 ++ .../EventDispatchingCommandBusTest.php | 2 ++ .../CommandHandling/SimpleCommandBusTest.php | 2 ++ test/Broadway/Domain/DateTimeTest.php | 2 ++ .../Broadway/Domain/DomainEventStreamTest.php | 2 ++ test/Broadway/Domain/DomainMessageTest.php | 2 ++ test/Broadway/Domain/MetadataTest.php | 2 ++ .../EventDispatcher/EventDispatcherTest.php | 2 ++ .../EventHandling/SimpleEventBusTest.php | 2 ++ .../AbstractEventSourcingRepositoryTest.php | 17 ++++++---- .../ReflectionAggregateFactoryTest.php | 6 ++-- .../EventSourcedAggregateRootTest.php | 4 ++- .../EventSourcingRepositoryTest.php | 8 +++-- ...adataEnrichingEventStreamDecoratorTest.php | 9 ++--- .../SimpleEventSourcedEntityTest.php | 9 +++-- ...acklistConcurrencyConflictResolverTest.php | 3 ++ .../ConcurrencyConflictResolverTest.php | 3 ++ .../ConcurrencyConflictResolver/Event.php | 3 ++ .../OtherEvent.php | 3 ++ ...itelistConcurrencyConflictResolverTest.php | 3 ++ .../ConflictResolvingEventStoreTest.php | 3 ++ test/Broadway/EventStore/EventStoreTest.php | 25 +++++--------- .../EventStore/InMemoryEventStoreTest.php | 2 ++ .../Management/EventStoreManagementTest.php | 16 ++++----- .../InMemoryEventStoreManagementTest.php | 2 ++ test/Broadway/Processor/ProcessorTest.php | 2 ++ .../InMemoryRepositoryFactoryTest.php | 2 ++ .../InMemory/InMemoryRepositoryTest.php | 5 ++- test/Broadway/ReadModel/ProjectorTest.php | 2 ++ .../Broadway/ReadModel/RepositoryTestCase.php | 4 ++- .../ReadModel/RepositoryTestReadModel.php | 21 +++++++++--- .../SimpleInterfaceSerializerTest.php | 7 ++-- test/Broadway/TestCase.php | 2 ++ test/bootstrap.php | 2 ++ 130 files changed, 505 insertions(+), 227 deletions(-) diff --git a/.php_cs b/.php_cs index 5f6fbdcb..ebacf5d2 100644 --- a/.php_cs +++ b/.php_cs @@ -6,5 +6,6 @@ $finder = PhpCsFixer\Finder::create() return PhpCsFixer\Config::create() ->setRules([ '@Symfony' => true, + 'declare_strict_types' => true, ]) ->setFinder($finder); diff --git a/.travis.yml b/.travis.yml index da9ffede..0abfc601 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,8 @@ cache: matrix: include: - - php: 5.5 - - php: 5.6 - - php: 7 + - php: 7.0 + - php: 7.1 - php: hhvm fast_finish: true allow_failures: diff --git a/composer.json b/composer.json index 00df9291..89cf583c 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "require": { "beberlei/assert": "~2.0", "broadway/uuid-generator": "~0.4.0", - "php": ">=5.5.9" + "php": "^7.0" }, "authors": [ { diff --git a/examples/auditing/log-command-status.php b/examples/auditing/log-command-status.php index 785ae438..559d5bb3 100644 --- a/examples/auditing/log-command-status.php +++ b/examples/auditing/log-command-status.php @@ -1,5 +1,7 @@ addListener("broadway.command_handling.command_success", [$commandAuditLogger, "onCommandHandlingSuccess"]); -$eventDispatcher->addListener("broadway.command_handling.command_failure", [$commandAuditLogger, "onCommandHandlingFailure"]); +$eventDispatcher->addListener('broadway.command_handling.command_success', [$commandAuditLogger, 'onCommandHandlingSuccess']); +$eventDispatcher->addListener('broadway.command_handling.command_failure', [$commandAuditLogger, 'onCommandHandlingFailure']); echo "Dispatching the command that will succeed.\n"; $command = new ExampleCommand('Hi from command!'); diff --git a/examples/bootstrap.php b/examples/bootstrap.php index aae96c81..9d908af4 100644 --- a/examples/bootstrap.php +++ b/examples/bootstrap.php @@ -1,5 +1,7 @@ logger->info(json_encode($messageData)); } - private function getCommandData($command) + private function getCommandData($command): array { return [ 'class' => get_class($command), diff --git a/src/Broadway/Auditing/CommandSerializer.php b/src/Broadway/Auditing/CommandSerializer.php index c88537aa..f4e6e7d0 100644 --- a/src/Broadway/Auditing/CommandSerializer.php +++ b/src/Broadway/Auditing/CommandSerializer.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Auditing; /** @@ -21,5 +23,5 @@ interface CommandSerializer * * @return array */ - public function serialize($command); + public function serialize($command): array; } diff --git a/src/Broadway/Auditing/NullByteCommandSerializer.php b/src/Broadway/Auditing/NullByteCommandSerializer.php index d5000bd8..80a94224 100644 --- a/src/Broadway/Auditing/NullByteCommandSerializer.php +++ b/src/Broadway/Auditing/NullByteCommandSerializer.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Auditing; /** @@ -22,7 +24,7 @@ final class NullByteCommandSerializer implements CommandSerializer /** * {@inheritDoc} */ - public function serialize($command) + public function serialize($command): array { $serializedCommand = []; foreach ((array) $command as $key => $value) { diff --git a/src/Broadway/CommandHandling/ClosureCommandHandler.php b/src/Broadway/CommandHandling/ClosureCommandHandler.php index 0c028cf0..50ba1c7b 100644 --- a/src/Broadway/CommandHandling/ClosureCommandHandler.php +++ b/src/Broadway/CommandHandling/ClosureCommandHandler.php @@ -1,5 +1,7 @@ $method($command); } - private function getHandleMethod($command) + private function getHandleMethod($command): string { if (! is_object($command)) { throw new CommandNotAnObjectException(); diff --git a/src/Broadway/CommandHandling/Testing/CommandHandlerScenarioTestCase.php b/src/Broadway/CommandHandling/Testing/CommandHandlerScenarioTestCase.php index d0a0e3d6..7954f5ba 100644 --- a/src/Broadway/CommandHandling/Testing/CommandHandlerScenarioTestCase.php +++ b/src/Broadway/CommandHandling/Testing/CommandHandlerScenarioTestCase.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\CommandHandling\Testing; use Broadway\CommandHandling\CommandHandler; @@ -37,7 +39,7 @@ public function setUp() /** * @return Scenario */ - protected function createScenario() + protected function createScenario(): Scenario { $eventStore = new TraceableEventStore(new InMemoryEventStore()); $eventBus = new SimpleEventBus(); @@ -54,5 +56,5 @@ protected function createScenario() * * @return CommandHandler */ - abstract protected function createCommandHandler(EventStore $eventStore, EventBus $eventBus); + abstract protected function createCommandHandler(EventStore $eventStore, EventBus $eventBus): CommandHandler; } diff --git a/src/Broadway/CommandHandling/Testing/Scenario.php b/src/Broadway/CommandHandling/Testing/Scenario.php index 518aeb90..28bcf390 100644 --- a/src/Broadway/CommandHandling/Testing/Scenario.php +++ b/src/Broadway/CommandHandling/Testing/Scenario.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\CommandHandling\Testing; use Broadway\CommandHandling\CommandHandler; @@ -43,14 +45,15 @@ public function __construct( $this->testCase = $testCase; $this->eventStore = $eventStore; $this->commandHandler = $commandHandler; - $this->aggregateId = 1; + $this->aggregateId = '1'; } /** - * @param string $aggregateId + * @param string $aggregateId + * * @return Scenario */ - public function withAggregateId($aggregateId) + public function withAggregateId(string $aggregateId): Scenario { $this->aggregateId = $aggregateId; @@ -62,7 +65,7 @@ public function withAggregateId($aggregateId) * * @return Scenario */ - public function given(array $events = null) + public function given(array $events = null): Scenario { if ($events === null) { return $this; @@ -85,7 +88,7 @@ public function given(array $events = null) * * @return Scenario */ - public function when($command) + public function when($command): Scenario { $this->eventStore->trace(); @@ -99,7 +102,7 @@ public function when($command) * * @return Scenario */ - public function then(array $events) + public function then(array $events): Scenario { $this->testCase->assertEquals($events, $this->eventStore->getEvents()); diff --git a/src/Broadway/CommandHandling/Testing/TraceableCommandBus.php b/src/Broadway/CommandHandling/Testing/TraceableCommandBus.php index 2bab1bde..229e4928 100644 --- a/src/Broadway/CommandHandling/Testing/TraceableCommandBus.php +++ b/src/Broadway/CommandHandling/Testing/TraceableCommandBus.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\CommandHandling\Testing; use Broadway\CommandHandling\CommandBus; @@ -46,7 +48,7 @@ public function dispatch($command) /** * @return array */ - public function getRecordedCommands() + public function getRecordedCommands(): array { return $this->commands; } diff --git a/src/Broadway/Domain/AggregateRoot.php b/src/Broadway/Domain/AggregateRoot.php index aae1fd89..02d2f642 100644 --- a/src/Broadway/Domain/AggregateRoot.php +++ b/src/Broadway/Domain/AggregateRoot.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Domain; /** @@ -19,10 +21,10 @@ interface AggregateRoot /** * @return DomainEventStream */ - public function getUncommittedEvents(); + public function getUncommittedEvents(): DomainEventStream; /** * @return string */ - public function getAggregateRootId(); + public function getAggregateRootId(): string; } diff --git a/src/Broadway/Domain/DateTime.php b/src/Broadway/Domain/DateTime.php index 98d88a08..fee2f132 100644 --- a/src/Broadway/Domain/DateTime.php +++ b/src/Broadway/Domain/DateTime.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Domain; use DateInterval; @@ -32,7 +34,7 @@ private function __construct(DateTimeImmutable $dateTime) /** * @return DateTime */ - public static function now() + public static function now(): DateTime { return new DateTime( DateTimeImmutable::createFromFormat( @@ -46,7 +48,7 @@ public static function now() /** * @return string */ - public function toString() + public function toString(): string { return $this->dateTime->format(self::FORMAT_STRING); } @@ -56,7 +58,7 @@ public function toString() * * @return DateTime */ - public static function fromString($dateTimeString) + public static function fromString($dateTimeString): DateTime { return new DateTime(new DateTimeImmutable($dateTimeString)); } @@ -64,16 +66,17 @@ public static function fromString($dateTimeString) /** * @return boolean */ - public function equals(DateTime $dateTime) + public function equals(DateTime $dateTime): bool { return $this->toString() === $dateTime->toString(); } /** * @param DateTime $dateTime + * * @return bool */ - public function comesAfter(DateTime $dateTime) + public function comesAfter(DateTime $dateTime): bool { return $this->dateTime > $dateTime->dateTime; } @@ -83,7 +86,7 @@ public function comesAfter(DateTime $dateTime) * * @return DateTime */ - public function add($intervalSpec) + public function add(string $intervalSpec): DateTime { $dateTime = $this->dateTime->add(new DateInterval($intervalSpec)); @@ -95,7 +98,7 @@ public function add($intervalSpec) * * @return DateTime */ - public function sub($intervalSpec) + public function sub(string $intervalSpec): DateTime { $dateTime = $this->dateTime->sub(new DateInterval($intervalSpec)); @@ -104,9 +107,10 @@ public function sub($intervalSpec) /** * @param DateTime $dateTime + * * @return DateInterval */ - public function diff(DateTime $dateTime) + public function diff(DateTime $dateTime): DateInterval { return $this->dateTime->diff($dateTime->dateTime); } @@ -114,7 +118,7 @@ public function diff(DateTime $dateTime) /** * @return DateTime */ - public function toBeginningOfWeek() + public function toBeginningOfWeek(): DateTime { return new DateTime(new DateTimeImmutable($this->dateTime->format('o-\WW-1'), new DateTimeZone('UTC'))); } @@ -122,7 +126,7 @@ public function toBeginningOfWeek() /** * @return string */ - public function toYearWeekString() + public function toYearWeekString(): string { return $this->dateTime->format('oW'); } @@ -130,7 +134,7 @@ public function toYearWeekString() /** * @return DateTimeImmutable */ - public function toNative() + public function toNative(): DateTimeImmutable { return $this->dateTime; } diff --git a/src/Broadway/Domain/DomainEventStream.php b/src/Broadway/Domain/DomainEventStream.php index 747089d0..3b4358b0 100644 --- a/src/Broadway/Domain/DomainEventStream.php +++ b/src/Broadway/Domain/DomainEventStream.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Domain; use ArrayIterator; @@ -32,7 +34,7 @@ public function __construct(array $events) /** * @return ArrayIterator */ - public function getIterator() + public function getIterator(): ArrayIterator { return new ArrayIterator($this->events); } diff --git a/src/Broadway/Domain/DomainMessage.php b/src/Broadway/Domain/DomainMessage.php index c4befd5c..32f87eff 100644 --- a/src/Broadway/Domain/DomainMessage.php +++ b/src/Broadway/Domain/DomainMessage.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Domain; /** @@ -42,15 +44,15 @@ final class DomainMessage private $recordedOn; /** - * @param string $id + * @param mixed $id * @param int $playhead * @param Metadata $metadata * @param mixed $payload * @param DateTime $recordedOn */ - public function __construct($id, $playhead, Metadata $metadata, $payload, DateTime $recordedOn) + public function __construct($id, int $playhead, Metadata $metadata, $payload, DateTime $recordedOn) { - $this->id = $id; + $this->id = (string) $id; $this->playhead = $playhead; $this->metadata = $metadata; $this->payload = $payload; @@ -60,7 +62,7 @@ public function __construct($id, $playhead, Metadata $metadata, $payload, DateTi /** * @return string */ - public function getId() + public function getId(): string { return $this->id; } @@ -68,7 +70,7 @@ public function getId() /** * @return int */ - public function getPlayhead() + public function getPlayhead(): int { return $this->playhead; } @@ -76,7 +78,7 @@ public function getPlayhead() /** * @return Metadata */ - public function getMetadata() + public function getMetadata(): Metadata { return $this->metadata; } @@ -92,7 +94,7 @@ public function getPayload() /** * @return DateTime */ - public function getRecordedOn() + public function getRecordedOn(): DateTime { return $this->recordedOn; } @@ -100,20 +102,20 @@ public function getRecordedOn() /** * @return string */ - public function getType() + public function getType(): string { return strtr(get_class($this->payload), '\\', '.'); } /** - * @param string $id + * @param mixed $id * @param int $playhead * @param Metadata $metadata * @param mixed $payload * * @return DomainMessage */ - public static function recordNow($id, $playhead, Metadata $metadata, $payload) + public static function recordNow($id, int $playhead, Metadata $metadata, $payload) { return new DomainMessage($id, $playhead, $metadata, $payload, DateTime::now()); } @@ -125,7 +127,7 @@ public static function recordNow($id, $playhead, Metadata $metadata, $payload) * * @return DomainMessage */ - public function andMetadata(Metadata $metadata) + public function andMetadata(Metadata $metadata): DomainMessage { $newMetadata = $this->metadata->merge($metadata); diff --git a/src/Broadway/Domain/Metadata.php b/src/Broadway/Domain/Metadata.php index d9811b64..12c68c62 100644 --- a/src/Broadway/Domain/Metadata.php +++ b/src/Broadway/Domain/Metadata.php @@ -7,8 +7,11 @@ * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. + * */ +declare(strict_types=1); + namespace Broadway\Domain; use Broadway\Serializer\Serializable; @@ -48,11 +51,9 @@ public static function kv($key, $value) * * @return Metadata a new instance */ - public function merge(Metadata $otherMetadata) + public function merge(Metadata $otherMetadata): Metadata { - $mergedValues = array_merge($this->values, $otherMetadata->values); - - return new Metadata($mergedValues); + return new Metadata(array_merge($this->values, $otherMetadata->values)); } /** @@ -60,7 +61,7 @@ public function merge(Metadata $otherMetadata) * * @return array */ - public function all() + public function all(): array { return $this->values; } @@ -74,17 +75,13 @@ public function all() */ public function get($key) { - if (!array_key_exists($key, $this->values)) { - return null; - } - - return $this->values[$key]; + return $this->values[$key] ?? null; } /** * {@inheritDoc} */ - public function serialize() + public function serialize(): array { return $this->values; } diff --git a/src/Broadway/EventDispatcher/CallableEventDispatcher.php b/src/Broadway/EventDispatcher/CallableEventDispatcher.php index efa0cc89..c0c822a0 100644 --- a/src/Broadway/EventDispatcher/CallableEventDispatcher.php +++ b/src/Broadway/EventDispatcher/CallableEventDispatcher.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventDispatcher; /** @@ -21,7 +23,7 @@ final class CallableEventDispatcher implements EventDispatcher /** * {@inheritDoc} */ - public function dispatch($eventName, array $arguments) + public function dispatch(string $eventName, array $arguments) { if (! isset($this->listeners[$eventName])) { return; @@ -35,7 +37,7 @@ public function dispatch($eventName, array $arguments) /** * {@inheritDoc} */ - public function addListener($eventName, /* callable */ $callable) + public function addListener(string $eventName, callable $callable) { if (! isset($this->listeners[$eventName])) { $this->listeners[$eventName] = []; diff --git a/src/Broadway/EventDispatcher/EventDispatcher.php b/src/Broadway/EventDispatcher/EventDispatcher.php index 7d9d32dc..e51fc789 100644 --- a/src/Broadway/EventDispatcher/EventDispatcher.php +++ b/src/Broadway/EventDispatcher/EventDispatcher.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventDispatcher; /** @@ -20,11 +22,11 @@ interface EventDispatcher * @param string $eventName * @param array $arguments */ - public function dispatch($eventName, array $arguments); + public function dispatch(string $eventName, array $arguments); /** * @param string $eventName * @param callable $callable */ - public function addListener($eventName, /* callable */ $callable); + public function addListener(string $eventName, callable $callable); } diff --git a/src/Broadway/EventDispatcher/Testing/TraceableEventDispatcher.php b/src/Broadway/EventDispatcher/Testing/TraceableEventDispatcher.php index 7c0ad988..e36ef847 100644 --- a/src/Broadway/EventDispatcher/Testing/TraceableEventDispatcher.php +++ b/src/Broadway/EventDispatcher/Testing/TraceableEventDispatcher.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventDispatcher\Testing; use Broadway\EventDispatcher\EventDispatcher; @@ -17,17 +19,17 @@ final class TraceableEventDispatcher implements EventDispatcher { private $dispatchedEvents = []; - public function dispatch($eventName, array $arguments) + public function dispatch(string $eventName, array $arguments) { $this->dispatchedEvents[] = ['event' => $eventName, 'arguments' => $arguments]; } - public function addListener($eventName, /* callable */ $callable) + public function addListener(string $eventName, callable $callable) { return; } - public function getDispatchedEvents() + public function getDispatchedEvents(): array { return $this->dispatchedEvents; } diff --git a/src/Broadway/EventHandling/EventBus.php b/src/Broadway/EventHandling/EventBus.php index c2d0580e..bf69cc06 100644 --- a/src/Broadway/EventHandling/EventBus.php +++ b/src/Broadway/EventHandling/EventBus.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventHandling; use Broadway\Domain\DomainEventStream; diff --git a/src/Broadway/EventHandling/EventListener.php b/src/Broadway/EventHandling/EventListener.php index bd943baf..1eb44c83 100644 --- a/src/Broadway/EventHandling/EventListener.php +++ b/src/Broadway/EventHandling/EventListener.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventHandling; use Broadway\Domain\DomainMessage; diff --git a/src/Broadway/EventHandling/SimpleEventBus.php b/src/Broadway/EventHandling/SimpleEventBus.php index 0059c8a3..bcd1e7c0 100644 --- a/src/Broadway/EventHandling/SimpleEventBus.php +++ b/src/Broadway/EventHandling/SimpleEventBus.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventHandling; use Broadway\Domain\DomainEventStream; diff --git a/src/Broadway/EventHandling/TraceableEventBus.php b/src/Broadway/EventHandling/TraceableEventBus.php index a847bd0f..3e30d614 100644 --- a/src/Broadway/EventHandling/TraceableEventBus.php +++ b/src/Broadway/EventHandling/TraceableEventBus.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventHandling; use Broadway\Domain\DomainEventStream; @@ -55,7 +57,7 @@ public function publish(DomainEventStream $domainMessages) /** * @return array Payloads of the recorded events */ - public function getEvents() + public function getEvents(): array { return array_map( function (DomainMessage $message) { diff --git a/src/Broadway/EventSourcing/AggregateFactory/AggregateFactory.php b/src/Broadway/EventSourcing/AggregateFactory/AggregateFactory.php index 0d5c9207..9370d852 100644 --- a/src/Broadway/EventSourcing/AggregateFactory/AggregateFactory.php +++ b/src/Broadway/EventSourcing/AggregateFactory/AggregateFactory.php @@ -1,16 +1,19 @@ staticConstructorMethod); diff --git a/src/Broadway/EventSourcing/AggregateFactory/PublicConstructorAggregateFactory.php b/src/Broadway/EventSourcing/AggregateFactory/PublicConstructorAggregateFactory.php index 38b51b1a..63f443b5 100644 --- a/src/Broadway/EventSourcing/AggregateFactory/PublicConstructorAggregateFactory.php +++ b/src/Broadway/EventSourcing/AggregateFactory/PublicConstructorAggregateFactory.php @@ -1,8 +1,11 @@ initializeState($domainEventStream); diff --git a/src/Broadway/EventSourcing/AggregateFactory/ReflectionAggregateFactory.php b/src/Broadway/EventSourcing/AggregateFactory/ReflectionAggregateFactory.php index c360195a..cd9a3aa2 100644 --- a/src/Broadway/EventSourcing/AggregateFactory/ReflectionAggregateFactory.php +++ b/src/Broadway/EventSourcing/AggregateFactory/ReflectionAggregateFactory.php @@ -1,5 +1,7 @@ newInstanceWithoutConstructor(); diff --git a/src/Broadway/EventSourcing/AggregateRootAlreadyRegisteredException.php b/src/Broadway/EventSourcing/AggregateRootAlreadyRegisteredException.php index 882c08e6..cb81d5d2 100644 --- a/src/Broadway/EventSourcing/AggregateRootAlreadyRegisteredException.php +++ b/src/Broadway/EventSourcing/AggregateRootAlreadyRegisteredException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing; use RuntimeException; diff --git a/src/Broadway/EventSourcing/EventSourcedAggregateRoot.php b/src/Broadway/EventSourcing/EventSourcedAggregateRoot.php index b101f324..83bde7a3 100644 --- a/src/Broadway/EventSourcing/EventSourcedAggregateRoot.php +++ b/src/Broadway/EventSourcing/EventSourcedAggregateRoot.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing; use Broadway\Domain\AggregateRoot as AggregateRootInterface; @@ -48,7 +50,7 @@ public function apply($event) /** * {@inheritDoc} */ - public function getUncommittedEvents() + public function getUncommittedEvents(): DomainEventStream { $stream = new DomainEventStream($this->uncommittedEvents); @@ -104,12 +106,12 @@ protected function handleRecursively($event) * * @return EventSourcedEntity[] */ - protected function getChildEntities() + protected function getChildEntities(): array { return []; } - private function getApplyMethod($event) + private function getApplyMethod($event): string { $classParts = explode('\\', get_class($event)); @@ -119,7 +121,7 @@ private function getApplyMethod($event) /** * @return int */ - public function getPlayhead() + public function getPlayhead(): int { return $this->playhead; } diff --git a/src/Broadway/EventSourcing/EventSourcedEntity.php b/src/Broadway/EventSourcing/EventSourcedEntity.php index 15d9a337..ba7fc7d1 100644 --- a/src/Broadway/EventSourcing/EventSourcedEntity.php +++ b/src/Broadway/EventSourcing/EventSourcedEntity.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing; /** diff --git a/src/Broadway/EventSourcing/EventSourcingRepository.php b/src/Broadway/EventSourcing/EventSourcingRepository.php index 8a61122d..d9270bf2 100644 --- a/src/Broadway/EventSourcing/EventSourcingRepository.php +++ b/src/Broadway/EventSourcing/EventSourcingRepository.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing; use Assert\Assertion as Assert; @@ -42,7 +44,7 @@ class EventSourcingRepository implements Repository public function __construct( EventStore $eventStore, EventBus $eventBus, - $aggregateClass, + string $aggregateClass, AggregateFactory $aggregateFactory, array $eventStreamDecorators = [] ) { @@ -58,7 +60,7 @@ public function __construct( /** * {@inheritDoc} */ - public function load($id) + public function load($id): AggregateRoot { try { $domainEventStream = $this->eventStore->load($id); @@ -83,7 +85,7 @@ public function save(AggregateRoot $aggregate) $this->eventBus->publish($eventStream); } - private function decorateForWrite(AggregateRoot $aggregate, DomainEventStream $eventStream) + private function decorateForWrite(AggregateRoot $aggregate, DomainEventStream $eventStream): DomainEventStream { $aggregateType = $this->getType(); $aggregateIdentifier = $aggregate->getAggregateRootId(); @@ -95,7 +97,7 @@ private function decorateForWrite(AggregateRoot $aggregate, DomainEventStream $e return $eventStream; } - private function assertExtendsEventSourcedAggregateRoot($class) + private function assertExtendsEventSourcedAggregateRoot(string $class) { Assert::subclassOf( $class, @@ -104,7 +106,7 @@ private function assertExtendsEventSourcedAggregateRoot($class) ); } - private function getType() + private function getType(): string { return $this->aggregateClass; } diff --git a/src/Broadway/EventSourcing/EventStreamDecorator.php b/src/Broadway/EventSourcing/EventStreamDecorator.php index 112db157..41125fcb 100644 --- a/src/Broadway/EventSourcing/EventStreamDecorator.php +++ b/src/Broadway/EventSourcing/EventStreamDecorator.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing; use Broadway\Domain\DomainEventStream; @@ -29,5 +31,5 @@ interface EventStreamDecorator * * @return DomainEventStream */ - public function decorateForWrite($aggregateType, $aggregateIdentifier, DomainEventStream $eventStream); + public function decorateForWrite(string $aggregateType, string $aggregateIdentifier, DomainEventStream $eventStream): DomainEventStream; } diff --git a/src/Broadway/EventSourcing/MetadataEnrichment/MetadataEnricher.php b/src/Broadway/EventSourcing/MetadataEnrichment/MetadataEnricher.php index 99239cb8..6e5d3f70 100644 --- a/src/Broadway/EventSourcing/MetadataEnrichment/MetadataEnricher.php +++ b/src/Broadway/EventSourcing/MetadataEnrichment/MetadataEnricher.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing\MetadataEnrichment; use Broadway\Domain\Metadata; @@ -21,5 +23,5 @@ interface MetadataEnricher /** * @return Metadata */ - public function enrich(Metadata $metadata); + public function enrich(Metadata $metadata): Metadata; } diff --git a/src/Broadway/EventSourcing/MetadataEnrichment/MetadataEnrichingEventStreamDecorator.php b/src/Broadway/EventSourcing/MetadataEnrichment/MetadataEnrichingEventStreamDecorator.php index d07d7ba7..33b9e626 100644 --- a/src/Broadway/EventSourcing/MetadataEnrichment/MetadataEnrichingEventStreamDecorator.php +++ b/src/Broadway/EventSourcing/MetadataEnrichment/MetadataEnrichingEventStreamDecorator.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing\MetadataEnrichment; use Broadway\Domain\DomainEventStream; @@ -38,7 +40,7 @@ public function registerEnricher(MetadataEnricher $enricher) /** * {@inheritDoc} */ - public function decorateForWrite($aggregateType, $aggregateIdentifier, DomainEventStream $eventStream) + public function decorateForWrite(string $aggregateType, string $aggregateIdentifier, DomainEventStream $eventStream): DomainEventStream { if (empty($this->metadataEnrichers)) { return $eventStream; diff --git a/src/Broadway/EventSourcing/SimpleEventSourcedEntity.php b/src/Broadway/EventSourcing/SimpleEventSourcedEntity.php index e0d11f06..da3ca696 100644 --- a/src/Broadway/EventSourcing/SimpleEventSourcedEntity.php +++ b/src/Broadway/EventSourcing/SimpleEventSourcedEntity.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing; /** @@ -72,12 +74,12 @@ protected function handle($event) * * @return EventSourcedEntity[] */ - protected function getChildEntities() + protected function getChildEntities(): array { return []; } - private function getApplyMethod($event) + private function getApplyMethod($event): string { $classParts = explode('\\', get_class($event)); diff --git a/src/Broadway/EventSourcing/Testing/AggregateRootScenarioTestCase.php b/src/Broadway/EventSourcing/Testing/AggregateRootScenarioTestCase.php index cbea2710..79748773 100644 --- a/src/Broadway/EventSourcing/Testing/AggregateRootScenarioTestCase.php +++ b/src/Broadway/EventSourcing/Testing/AggregateRootScenarioTestCase.php @@ -9,8 +9,11 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing\Testing; +use Broadway\EventSourcing\AggregateFactory\AggregateFactory; use Broadway\EventSourcing\AggregateFactory\PublicConstructorAggregateFactory; use PHPUnit_Framework_TestCase as TestCase; @@ -32,7 +35,7 @@ public function setUp() /** * @return Scenario */ - protected function createScenario() + protected function createScenario(): Scenario { $aggregateRootClass = $this->getAggregateRootClass(); $factory = $this->getAggregateRootFactory(); @@ -45,14 +48,14 @@ protected function createScenario() * * @return string AggregateRoot */ - abstract protected function getAggregateRootClass(); + abstract protected function getAggregateRootClass(): string; /** * Returns a factory for instantiating an aggregate * - * @return \Broadway\EventSourcing\AggregateFactory\AggregateFactory $factory + * @return AggregateFactory $factory */ - protected function getAggregateRootFactory() + protected function getAggregateRootFactory(): AggregateFactory { return new PublicConstructorAggregateFactory(); } diff --git a/src/Broadway/EventSourcing/Testing/Scenario.php b/src/Broadway/EventSourcing/Testing/Scenario.php index 23155a08..c7a642dc 100644 --- a/src/Broadway/EventSourcing/Testing/Scenario.php +++ b/src/Broadway/EventSourcing/Testing/Scenario.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing\Testing; use Broadway\Domain\DomainEventStream; @@ -40,21 +42,21 @@ class Scenario * @param PHPUnit_Framework_TestCase $testCase * @param AggregateFactory $factory * @param string $aggregateRootClass - * @internal param PHPUnit_Framework_TestCase $testcase */ - public function __construct(PHPUnit_Framework_TestCase $testCase, AggregateFactory $factory, $aggregateRootClass) + public function __construct(PHPUnit_Framework_TestCase $testCase, AggregateFactory $factory, string $aggregateRootClass) { $this->testCase = $testCase; $this->factory = $factory; $this->aggregateRootClass = $aggregateRootClass; - $this->aggregateId = 1; + $this->aggregateId = '1'; } /** - * @param string $aggregateId + * @param string $aggregateId + * * @return Scenario */ - public function withAggregateId($aggregateId) + public function withAggregateId(string $aggregateId): Scenario { $this->aggregateId = $aggregateId; @@ -66,7 +68,7 @@ public function withAggregateId($aggregateId) * * @return Scenario */ - public function given(array $givens = null) + public function given(array $givens = null): Scenario { if ($givens === null) { return $this; @@ -93,7 +95,7 @@ public function given(array $givens = null) * * @return Scenario */ - public function when(/* callable */ $when) + public function when(callable $when): Scenario { if (! is_callable($when)) { return $this; @@ -115,7 +117,7 @@ public function when(/* callable */ $when) * * @return Scenario */ - public function then(array $thens) + public function then(array $thens): Scenario { $this->testCase->assertEquals($thens, $this->getEvents()); @@ -125,15 +127,10 @@ public function then(array $thens) /** * @return array Payloads of the recorded events */ - private function getEvents() + private function getEvents(): array { - $recordedEvents = $this->aggregateRootInstance->getUncommittedEvents(); - $events = []; - - foreach ($recordedEvents as $message) { - $events[] = $message->getPayload(); - } - - return $events; + return array_map(function (DomainMessage $message) { + return $message->getPayload(); + }, $this->aggregateRootInstance->getUncommittedEvents()); } } diff --git a/src/Broadway/EventStore/CallableEventVisitor.php b/src/Broadway/EventStore/CallableEventVisitor.php index 434c6826..003cb735 100644 --- a/src/Broadway/EventStore/CallableEventVisitor.php +++ b/src/Broadway/EventStore/CallableEventVisitor.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore; use Broadway\Domain\DomainMessage; diff --git a/src/Broadway/EventStore/ConcurrencyConflictResolver/BlacklistConcurrencyConflictResolver.php b/src/Broadway/EventStore/ConcurrencyConflictResolver/BlacklistConcurrencyConflictResolver.php index 5221180f..1504c9e8 100644 --- a/src/Broadway/EventStore/ConcurrencyConflictResolver/BlacklistConcurrencyConflictResolver.php +++ b/src/Broadway/EventStore/ConcurrencyConflictResolver/BlacklistConcurrencyConflictResolver.php @@ -1,4 +1,7 @@ conflictingEvents[$eventClass1][$eventClass2] = true; $this->conflictingEvents[$eventClass2][$eventClass1] = true; } - public function conflictsWith(DomainMessage $event1, DomainMessage $event2) + /** + * {@inheritdoc} + */ + public function conflictsWith(DomainMessage $event1, DomainMessage $event2): bool { return isset($this->conflictingEvents[get_class($event1->getPayload())][get_class($event2->getPayload())]); } diff --git a/src/Broadway/EventStore/ConcurrencyConflictResolver/ConcurrencyConflictResolver.php b/src/Broadway/EventStore/ConcurrencyConflictResolver/ConcurrencyConflictResolver.php index 7260bdea..b7005fad 100644 --- a/src/Broadway/EventStore/ConcurrencyConflictResolver/ConcurrencyConflictResolver.php +++ b/src/Broadway/EventStore/ConcurrencyConflictResolver/ConcurrencyConflictResolver.php @@ -1,9 +1,12 @@ independentEvents[$eventClass1][$eventClass2] = true; $this->independentEvents[$eventClass2][$eventClass1] = true; } - public function conflictsWith(DomainMessage $event1, DomainMessage $event2) + /** + * {@inheritdoc} + */ + public function conflictsWith(DomainMessage $event1, DomainMessage $event2): bool { - return !isset($this->independentEvents[get_class($event1->getPayload())][get_class($event2->getPayload())]); + return ! isset($this->independentEvents[get_class($event1->getPayload())][get_class($event2->getPayload())]); } } diff --git a/src/Broadway/EventStore/ConcurrencyConflictResolvingEventStore.php b/src/Broadway/EventStore/ConcurrencyConflictResolvingEventStore.php index fa3501d4..b4b23ab4 100644 --- a/src/Broadway/EventStore/ConcurrencyConflictResolvingEventStore.php +++ b/src/Broadway/EventStore/ConcurrencyConflictResolvingEventStore.php @@ -1,4 +1,7 @@ eventStore->load($id); } @@ -73,7 +76,7 @@ public function load($id) /** * {@inheritDoc} */ - public function loadFromPlayhead($id, $playhead) + public function loadFromPlayhead($id, int $playhead): DomainEventStream { return $this->eventStore->loadFromPlayhead($id, $playhead); } @@ -81,7 +84,7 @@ public function loadFromPlayhead($id, $playhead) /** * @return int */ - private function getCurrentPlayhead(DomainEventStream $committedEvents) + private function getCurrentPlayhead(DomainEventStream $committedEvents): int { $events = iterator_to_array($committedEvents); /** @var DomainMessage $lastEvent */ @@ -97,7 +100,7 @@ private function getCurrentPlayhead(DomainEventStream $committedEvents) private function getConflictingEvents( DomainEventStream $uncommittedEvents, DomainEventStream $committedEvents - ) { + ): array { $conflictingEvents = []; /** @var DomainMessage $committedEvent */ diff --git a/src/Broadway/EventStore/EventStore.php b/src/Broadway/EventStore/EventStore.php index cf31f4ac..3d76d3a8 100644 --- a/src/Broadway/EventStore/EventStore.php +++ b/src/Broadway/EventStore/EventStore.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore; use Broadway\Domain\DomainEventStream; @@ -24,13 +26,15 @@ interface EventStore * * @return DomainEventStream */ - public function load($id); + public function load($id): DomainEventStream; /** * @param mixed $id * @param int $playhead + * + * @return DomainEventStream */ - public function loadFromPlayhead($id, $playhead); + public function loadFromPlayhead($id, int $playhead): DomainEventStream; /** * @param mixed $id diff --git a/src/Broadway/EventStore/EventStoreException.php b/src/Broadway/EventStore/EventStoreException.php index 7c7dbdca..99ed0999 100644 --- a/src/Broadway/EventStore/EventStoreException.php +++ b/src/Broadway/EventStore/EventStoreException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore; use RuntimeException; diff --git a/src/Broadway/EventStore/EventStreamNotFoundException.php b/src/Broadway/EventStore/EventStreamNotFoundException.php index b1f692c4..406f6eff 100644 --- a/src/Broadway/EventStore/EventStreamNotFoundException.php +++ b/src/Broadway/EventStore/EventStreamNotFoundException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore; /** diff --git a/src/Broadway/EventStore/EventVisitor.php b/src/Broadway/EventStore/EventVisitor.php index 7cb3120f..8ae016f0 100644 --- a/src/Broadway/EventStore/EventVisitor.php +++ b/src/Broadway/EventStore/EventVisitor.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore; use Broadway\Domain\DomainMessage; diff --git a/src/Broadway/EventStore/Exception/DuplicatePlayheadException.php b/src/Broadway/EventStore/Exception/DuplicatePlayheadException.php index ef48169a..f09523db 100644 --- a/src/Broadway/EventStore/Exception/DuplicatePlayheadException.php +++ b/src/Broadway/EventStore/Exception/DuplicatePlayheadException.php @@ -1,5 +1,7 @@ eventStream = $eventStream; } @@ -27,7 +29,7 @@ public function __construct(DomainEventStream $eventStream, $previous = null) /** * @return DomainEventStream */ - public function getEventStream() + public function getEventStream(): DomainEventStream { return $this->eventStream; } diff --git a/src/Broadway/EventStore/Exception/InvalidIdentifierException.php b/src/Broadway/EventStore/Exception/InvalidIdentifierException.php index 14c3317e..7119f528 100644 --- a/src/Broadway/EventStore/Exception/InvalidIdentifierException.php +++ b/src/Broadway/EventStore/Exception/InvalidIdentifierException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore\Exception; /** diff --git a/src/Broadway/EventStore/InMemoryEventStore.php b/src/Broadway/EventStore/InMemoryEventStore.php index b5ce30fc..035a3795 100644 --- a/src/Broadway/EventStore/InMemoryEventStore.php +++ b/src/Broadway/EventStore/InMemoryEventStore.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore; use Broadway\Domain\DomainEventStream; @@ -29,7 +31,7 @@ final class InMemoryEventStore implements EventStore, EventStoreManagement /** * {@inheritDoc} */ - public function load($id) + public function load($id): DomainEventStream { $id = (string) $id; @@ -43,7 +45,7 @@ public function load($id) /** * {@inheritDoc} */ - public function loadFromPlayhead($id, $playhead) + public function loadFromPlayhead($id, int $playhead): DomainEventStream { $id = (string) $id; @@ -88,7 +90,7 @@ public function append($id, DomainEventStream $eventStream) * @param DomainMessage[] $events * @param DomainEventStream $eventsToAppend */ - private function assertStream($events, $eventsToAppend) + private function assertStream(array $events, DomainEventStream $eventsToAppend) { /** @var DomainMessage $event */ foreach ($eventsToAppend as $event) { diff --git a/src/Broadway/EventStore/InMemoryEventStoreException.php b/src/Broadway/EventStore/InMemoryEventStoreException.php index 996794fc..3af7f392 100644 --- a/src/Broadway/EventStore/InMemoryEventStoreException.php +++ b/src/Broadway/EventStore/InMemoryEventStoreException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore; /** diff --git a/src/Broadway/EventStore/Management/Criteria.php b/src/Broadway/EventStore/Management/Criteria.php index 9757df11..9e71cfb5 100644 --- a/src/Broadway/EventStore/Management/Criteria.php +++ b/src/Broadway/EventStore/Management/Criteria.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore\Management; use Broadway\Domain\DomainMessage; @@ -22,10 +24,11 @@ final class Criteria /** * Create a new criteria with the specified aggregate root types * - * @param array $aggregateRootTypes - * @return static + * @param array $aggregateRootTypes + * + * @return Criteria */ - public function withAggregateRootTypes(array $aggregateRootTypes) + public function withAggregateRootTypes(array $aggregateRootTypes): Criteria { $instance = clone($this); $instance->aggregateRootTypes = $aggregateRootTypes; @@ -36,10 +39,11 @@ public function withAggregateRootTypes(array $aggregateRootTypes) /** * Create a new criteria with the specified aggregate root IDs * - * @param array $aggregateRootIds + * @param array $aggregateRootIds + * * @return Criteria */ - public function withAggregateRootIds(array $aggregateRootIds) + public function withAggregateRootIds(array $aggregateRootIds): Criteria { $instance = clone($this); $instance->aggregateRootIds = $aggregateRootIds; @@ -50,10 +54,11 @@ public function withAggregateRootIds(array $aggregateRootIds) /** * Create a new criteria with the specified event types * - * @param array $eventTypes + * @param array $eventTypes + * * @return Criteria */ - public function withEventTypes(array $eventTypes) + public function withEventTypes(array $eventTypes): Criteria { $instance = clone($this); $instance->eventTypes = $eventTypes; @@ -66,7 +71,7 @@ public function withEventTypes(array $eventTypes) * * @return string[] */ - public function getAggregateRootTypes() + public function getAggregateRootTypes(): array { return $this->aggregateRootTypes; } @@ -76,7 +81,7 @@ public function getAggregateRootTypes() * * @return array */ - public function getAggregateRootIds() + public function getAggregateRootIds(): array { return $this->aggregateRootIds; } @@ -86,7 +91,7 @@ public function getAggregateRootIds() * * @return array */ - public function getEventTypes() + public function getEventTypes(): array { return $this->eventTypes; } @@ -94,9 +99,9 @@ public function getEventTypes() /** * Create a new criteria * - * @return static + * @return Criteria */ - public static function create() + public static function create(): Criteria { return new static(); } @@ -104,10 +109,11 @@ public static function create() /** * Determine if a domain message is matched by this criteria * - * @param DomainMessage $domainMessage + * @param DomainMessage $domainMessage + * * @return bool */ - public function isMatchedBy(DomainMessage $domainMessage) + public function isMatchedBy(DomainMessage $domainMessage): bool { if ($this->aggregateRootTypes) { throw new CriteriaNotSupportedException( diff --git a/src/Broadway/EventStore/Management/CriteriaNotSupportedException.php b/src/Broadway/EventStore/Management/CriteriaNotSupportedException.php index f97f4f3b..8c719fb2 100644 --- a/src/Broadway/EventStore/Management/CriteriaNotSupportedException.php +++ b/src/Broadway/EventStore/Management/CriteriaNotSupportedException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore\Management; /** diff --git a/src/Broadway/EventStore/Management/EventStoreManagement.php b/src/Broadway/EventStore/Management/EventStoreManagement.php index dc9264a3..e23319d8 100644 --- a/src/Broadway/EventStore/Management/EventStoreManagement.php +++ b/src/Broadway/EventStore/Management/EventStoreManagement.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore\Management; use Broadway\EventStore\EventVisitor; diff --git a/src/Broadway/EventStore/Management/EventStoreManagementException.php b/src/Broadway/EventStore/Management/EventStoreManagementException.php index c2945753..a4be173b 100644 --- a/src/Broadway/EventStore/Management/EventStoreManagementException.php +++ b/src/Broadway/EventStore/Management/EventStoreManagementException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore\Management; use RuntimeException; diff --git a/src/Broadway/EventStore/TraceableEventStore.php b/src/Broadway/EventStore/TraceableEventStore.php index 7976fac7..436a1d3a 100644 --- a/src/Broadway/EventStore/TraceableEventStore.php +++ b/src/Broadway/EventStore/TraceableEventStore.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore; use Broadway\Domain\DomainEventStream; @@ -47,7 +49,7 @@ public function append($id, DomainEventStream $eventStream) /** * @return array Appended events */ - public function getEvents() + public function getEvents(): array { return array_map( function (DomainMessage $message) { @@ -60,7 +62,7 @@ function (DomainMessage $message) { /** * {@inheritDoc} */ - public function load($id) + public function load($id): DomainEventStream { return $this->eventStore->load($id); } @@ -68,7 +70,7 @@ public function load($id) /** * {@inheritDoc} */ - public function loadFromPlayhead($id, $playhead) + public function loadFromPlayhead($id, int $playhead): DomainEventStream { return $this->eventStore->loadFromPlayhead($id, $playhead); } diff --git a/src/Broadway/Processor/Processor.php b/src/Broadway/Processor/Processor.php index 0bfe35d6..9c0d221b 100644 --- a/src/Broadway/Processor/Processor.php +++ b/src/Broadway/Processor/Processor.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Processor; use Broadway\Domain\DomainMessage; @@ -34,7 +36,7 @@ public function handle(DomainMessage $domainMessage) $this->$method($event, $domainMessage); } - private function getHandleMethod($event) + private function getHandleMethod($event): string { $classParts = explode('\\', get_class($event)); diff --git a/src/Broadway/ReadModel/Identifiable.php b/src/Broadway/ReadModel/Identifiable.php index 432e8e8c..3c2aab03 100644 --- a/src/Broadway/ReadModel/Identifiable.php +++ b/src/Broadway/ReadModel/Identifiable.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel; /** @@ -19,5 +21,5 @@ interface Identifiable /** * @return string */ - public function getId(); + public function getId(): string; } diff --git a/src/Broadway/ReadModel/InMemory/InMemoryRepository.php b/src/Broadway/ReadModel/InMemory/InMemoryRepository.php index 1c1f6e11..28b2ea5a 100644 --- a/src/Broadway/ReadModel/InMemory/InMemoryRepository.php +++ b/src/Broadway/ReadModel/InMemory/InMemoryRepository.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel\InMemory; use Broadway\ReadModel\Identifiable; @@ -48,7 +50,7 @@ public function find($id) /** * {@inheritDoc} */ - public function findBy(array $fields) + public function findBy(array $fields): array { if (! $fields) { return []; @@ -74,7 +76,7 @@ public function findBy(array $fields) /** * {@inheritDoc} */ - public function findAll() + public function findAll(): array { return array_values($this->data); } diff --git a/src/Broadway/ReadModel/InMemory/InMemoryRepositoryFactory.php b/src/Broadway/ReadModel/InMemory/InMemoryRepositoryFactory.php index c9e69140..fec2ac69 100644 --- a/src/Broadway/ReadModel/InMemory/InMemoryRepositoryFactory.php +++ b/src/Broadway/ReadModel/InMemory/InMemoryRepositoryFactory.php @@ -9,8 +9,11 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel\InMemory; +use Broadway\ReadModel\Repository; use Broadway\ReadModel\RepositoryFactory; /** @@ -21,7 +24,7 @@ final class InMemoryRepositoryFactory implements RepositoryFactory /** * {@inheritDoc} */ - public function create($name, $class) + public function create(string $name, string $class): Repository { return new InMemoryRepository(); } diff --git a/src/Broadway/ReadModel/Projector.php b/src/Broadway/ReadModel/Projector.php index a5638136..d17c3ae5 100644 --- a/src/Broadway/ReadModel/Projector.php +++ b/src/Broadway/ReadModel/Projector.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel; use Broadway\Domain\DomainMessage; @@ -34,7 +36,7 @@ public function handle(DomainMessage $domainMessage) $this->$method($event, $domainMessage); } - private function getHandleMethod($event) + private function getHandleMethod($event): string { $classParts = explode('\\', get_class($event)); diff --git a/src/Broadway/ReadModel/Repository.php b/src/Broadway/ReadModel/Repository.php index 78f2f32c..c713027f 100644 --- a/src/Broadway/ReadModel/Repository.php +++ b/src/Broadway/ReadModel/Repository.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel; /** @@ -19,7 +21,7 @@ interface Repository public function save(Identifiable $data); /** - * @param string $id + * @param mixed $id * * @return Identifiable|null */ @@ -30,15 +32,15 @@ public function find($id); * * @return Identifiable[] */ - public function findBy(array $fields); + public function findBy(array $fields): array; /** * @return Identifiable[] */ - public function findAll(); + public function findAll(): array; /** - * @param string $id + * @param mixed $id */ public function remove($id); } diff --git a/src/Broadway/ReadModel/RepositoryFactory.php b/src/Broadway/ReadModel/RepositoryFactory.php index 294d046d..3f97341c 100644 --- a/src/Broadway/ReadModel/RepositoryFactory.php +++ b/src/Broadway/ReadModel/RepositoryFactory.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel; /** @@ -22,5 +24,5 @@ interface RepositoryFactory * * @return Repository */ - public function create($name, $class); + public function create(string $name, string $class): Repository; } diff --git a/src/Broadway/ReadModel/SerializableReadModel.php b/src/Broadway/ReadModel/SerializableReadModel.php index 6c47d11e..a87860ca 100644 --- a/src/Broadway/ReadModel/SerializableReadModel.php +++ b/src/Broadway/ReadModel/SerializableReadModel.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel; use Broadway\Serializer\Serializable; diff --git a/src/Broadway/ReadModel/Testing/DomainMessageScenario.php b/src/Broadway/ReadModel/Testing/DomainMessageScenario.php index 6d5b2d02..76bc5562 100644 --- a/src/Broadway/ReadModel/Testing/DomainMessageScenario.php +++ b/src/Broadway/ReadModel/Testing/DomainMessageScenario.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel\Testing; use Assert\Assertion; @@ -48,7 +50,7 @@ public function __construct( * * @return DomainMessageScenario */ - public function given(array $domainMessages = []) + public function given(array $domainMessages = []): DomainMessageScenario { Assertion::allIsInstanceOf($domainMessages, DomainMessage::class); @@ -64,7 +66,7 @@ public function given(array $domainMessages = []) * * @return DomainMessageScenario */ - public function when(DomainMessage $domainMessage) + public function when(DomainMessage $domainMessage): DomainMessageScenario { $this->projector->handle($domainMessage); @@ -76,7 +78,7 @@ public function when(DomainMessage $domainMessage) * * @return DomainMessageScenario */ - public function then(array $expectedData) + public function then(array $expectedData): DomainMessageScenario { $this->testCase->assertEquals($expectedData, $this->repository->findAll()); diff --git a/src/Broadway/ReadModel/Testing/ProjectorScenarioTestCase.php b/src/Broadway/ReadModel/Testing/ProjectorScenarioTestCase.php index 787a4b61..a1734a59 100644 --- a/src/Broadway/ReadModel/Testing/ProjectorScenarioTestCase.php +++ b/src/Broadway/ReadModel/Testing/ProjectorScenarioTestCase.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel\Testing; use Broadway\ReadModel\InMemory\InMemoryRepository; @@ -33,7 +35,7 @@ public function setUp() /** * @return Scenario */ - protected function createScenario() + protected function createScenario(): Scenario { $repository = new InMemoryRepository(); @@ -43,5 +45,5 @@ protected function createScenario() /** * @return Projector */ - abstract protected function createProjector(InMemoryRepository $repository); + abstract protected function createProjector(InMemoryRepository $repository): Projector; } diff --git a/src/Broadway/ReadModel/Testing/Scenario.php b/src/Broadway/ReadModel/Testing/Scenario.php index f0651695..68562671 100644 --- a/src/Broadway/ReadModel/Testing/Scenario.php +++ b/src/Broadway/ReadModel/Testing/Scenario.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel\Testing; use Broadway\Domain\DateTime; @@ -46,7 +48,7 @@ public function __construct( $this->repository = $repository; $this->projector = $projector; $this->playhead = -1; - $this->aggregateId = 1; + $this->aggregateId = '1'; $this->dateTimeGenerator = function($event) { return DateTime::now(); }; @@ -57,7 +59,7 @@ public function __construct( * * @return Scenario */ - public function withAggregateId($aggregateId) + public function withAggregateId(string $aggregateId): Scenario { $this->aggregateId = $aggregateId; @@ -67,7 +69,7 @@ public function withAggregateId($aggregateId) /** * @return Scenario */ - public function withDateTimeGenerator(callable $dateTimeGenerator) + public function withDateTimeGenerator(callable $dateTimeGenerator): Scenario { $this->dateTimeGenerator = $dateTimeGenerator; @@ -79,7 +81,7 @@ public function withDateTimeGenerator(callable $dateTimeGenerator) * * @return Scenario */ - public function given(array $events = []) + public function given(array $events = []): Scenario { foreach ($events as $given) { $this->projector->handle($this->createDomainMessageForEvent($given)); @@ -93,7 +95,7 @@ public function given(array $events = []) * * @return Scenario */ - public function when($event, DateTime $occurredOn = null) + public function when($event, DateTime $occurredOn = null): Scenario { $this->projector->handle($this->createDomainMessageForEvent($event, $occurredOn)); @@ -105,7 +107,7 @@ public function when($event, DateTime $occurredOn = null) * * @return Scenario */ - public function then(array $expectedData) + public function then(array $expectedData): Scenario { $this->testCase->assertEquals($expectedData, $this->repository->findAll()); diff --git a/src/Broadway/ReadModel/Testing/SerializableReadModelTestCase.php b/src/Broadway/ReadModel/Testing/SerializableReadModelTestCase.php index 33a011d0..3d7492bd 100644 --- a/src/Broadway/ReadModel/Testing/SerializableReadModelTestCase.php +++ b/src/Broadway/ReadModel/Testing/SerializableReadModelTestCase.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel\Testing; use Broadway\ReadModel\SerializableReadModel; @@ -46,5 +48,5 @@ public function serializing_and_deserializing_yields_the_same_object() /** * @return SerializableReadModel */ - abstract protected function createSerializableReadModel(); + abstract protected function createSerializableReadModel(): SerializableReadModel; } diff --git a/src/Broadway/ReadModel/Transferable.php b/src/Broadway/ReadModel/Transferable.php index f3f4226a..5c16b931 100644 --- a/src/Broadway/ReadModel/Transferable.php +++ b/src/Broadway/ReadModel/Transferable.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel; /** diff --git a/src/Broadway/Repository/AggregateNotFoundException.php b/src/Broadway/Repository/AggregateNotFoundException.php index 0c1d75a2..6496a7ab 100644 --- a/src/Broadway/Repository/AggregateNotFoundException.php +++ b/src/Broadway/Repository/AggregateNotFoundException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Repository; use Exception; @@ -25,7 +27,7 @@ final class AggregateNotFoundException extends RuntimeException * * @return AggregateNotFoundException */ - public static function create($id, Exception $previous = null) + public static function create($id, Exception $previous = null): AggregateNotFoundException { return new self(sprintf("Aggregate with id '%s' not found", $id), 0, $previous); } diff --git a/src/Broadway/Repository/Repository.php b/src/Broadway/Repository/Repository.php index 46e542e7..3fe63309 100644 --- a/src/Broadway/Repository/Repository.php +++ b/src/Broadway/Repository/Repository.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Repository; use Broadway\Domain\AggregateRoot; @@ -30,9 +32,10 @@ public function save(AggregateRoot $aggregate); * * @param mixed $id * + * @throws AggregateNotFoundException + * * @return AggregateRoot * - * @throws AggregateNotFoundException */ - public function load($id); + public function load($id): AggregateRoot; } diff --git a/src/Broadway/Serializer/Serializable.php b/src/Broadway/Serializer/Serializable.php index 58bbf3c8..a6d10a94 100644 --- a/src/Broadway/Serializer/Serializable.php +++ b/src/Broadway/Serializer/Serializable.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Serializer; /** @@ -24,5 +26,5 @@ public static function deserialize(array $data); /** * @return array */ - public function serialize(); + public function serialize(): array; } diff --git a/src/Broadway/Serializer/SerializationException.php b/src/Broadway/Serializer/SerializationException.php index 2389ccb9..b970035c 100644 --- a/src/Broadway/Serializer/SerializationException.php +++ b/src/Broadway/Serializer/SerializationException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Serializer; use RuntimeException; diff --git a/src/Broadway/Serializer/Serializer.php b/src/Broadway/Serializer/Serializer.php index 7749a465..cb23fc56 100644 --- a/src/Broadway/Serializer/Serializer.php +++ b/src/Broadway/Serializer/Serializer.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Serializer; /** @@ -18,18 +20,20 @@ interface Serializer { /** + * @throws SerializationException + * * @return array * - * @throws SerializationException */ - public function serialize($object); + public function serialize($object): array; /** * @param array $serializedObject * + * @throws SerializationException + * * @return mixed * - * @throws SerializationException */ public function deserialize(array $serializedObject); } diff --git a/src/Broadway/Serializer/SimpleInterfaceSerializer.php b/src/Broadway/Serializer/SimpleInterfaceSerializer.php index a9d03272..599e0715 100644 --- a/src/Broadway/Serializer/SimpleInterfaceSerializer.php +++ b/src/Broadway/Serializer/SimpleInterfaceSerializer.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Serializer; use Assert\Assertion as Assert; @@ -21,7 +23,7 @@ final class SimpleInterfaceSerializer implements Serializer /** * {@inheritDoc} */ - public function serialize($object) + public function serialize($object): array { if (! $object instanceof Serializable) { throw new SerializationException(sprintf( diff --git a/src/Broadway/Serializer/Testing/SerializableEventTestCase.php b/src/Broadway/Serializer/Testing/SerializableEventTestCase.php index a917cd3f..47fe2414 100644 --- a/src/Broadway/Serializer/Testing/SerializableEventTestCase.php +++ b/src/Broadway/Serializer/Testing/SerializableEventTestCase.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Serializer\Testing; use Broadway\Serializer\Serializable; diff --git a/test/Broadway/Auditing/CommandLoggerTest.php b/test/Broadway/Auditing/CommandLoggerTest.php index 8b7680ce..c0121341 100644 --- a/test/Broadway/Auditing/CommandLoggerTest.php +++ b/test/Broadway/Auditing/CommandLoggerTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Auditing; use Broadway\TestCase; diff --git a/test/Broadway/Auditing/NullByteCommandSerializerTest.php b/test/Broadway/Auditing/NullByteCommandSerializerTest.php index 103fe668..84c81c70 100644 --- a/test/Broadway/Auditing/NullByteCommandSerializerTest.php +++ b/test/Broadway/Auditing/NullByteCommandSerializerTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Auditing; use Broadway\TestCase; diff --git a/test/Broadway/CommandHandling/CommandHandlerTest.php b/test/Broadway/CommandHandling/CommandHandlerTest.php index 49cf9b69..2c76d0c7 100644 --- a/test/Broadway/CommandHandling/CommandHandlerTest.php +++ b/test/Broadway/CommandHandling/CommandHandlerTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\CommandHandling; use Broadway\TestCase; diff --git a/test/Broadway/CommandHandling/EventDispatchingCommandBusTest.php b/test/Broadway/CommandHandling/EventDispatchingCommandBusTest.php index 744a1e3d..2f04085e 100644 --- a/test/Broadway/CommandHandling/EventDispatchingCommandBusTest.php +++ b/test/Broadway/CommandHandling/EventDispatchingCommandBusTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\CommandHandling; use Broadway\TestCase; diff --git a/test/Broadway/CommandHandling/SimpleCommandBusTest.php b/test/Broadway/CommandHandling/SimpleCommandBusTest.php index 44a13548..5ec8b712 100644 --- a/test/Broadway/CommandHandling/SimpleCommandBusTest.php +++ b/test/Broadway/CommandHandling/SimpleCommandBusTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\CommandHandling; use Broadway\TestCase; diff --git a/test/Broadway/Domain/DateTimeTest.php b/test/Broadway/Domain/DateTimeTest.php index 6ffe4483..ff863221 100644 --- a/test/Broadway/Domain/DateTimeTest.php +++ b/test/Broadway/Domain/DateTimeTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Domain; use Broadway\TestCase; diff --git a/test/Broadway/Domain/DomainEventStreamTest.php b/test/Broadway/Domain/DomainEventStreamTest.php index 65515760..160fa00d 100644 --- a/test/Broadway/Domain/DomainEventStreamTest.php +++ b/test/Broadway/Domain/DomainEventStreamTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Domain; use Broadway\TestCase; diff --git a/test/Broadway/Domain/DomainMessageTest.php b/test/Broadway/Domain/DomainMessageTest.php index d9021e68..27135f3b 100644 --- a/test/Broadway/Domain/DomainMessageTest.php +++ b/test/Broadway/Domain/DomainMessageTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Domain; use Broadway\TestCase; diff --git a/test/Broadway/Domain/MetadataTest.php b/test/Broadway/Domain/MetadataTest.php index 0fb91d8b..bb41ac16 100644 --- a/test/Broadway/Domain/MetadataTest.php +++ b/test/Broadway/Domain/MetadataTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Domain; use Broadway\TestCase; diff --git a/test/Broadway/EventDispatcher/EventDispatcherTest.php b/test/Broadway/EventDispatcher/EventDispatcherTest.php index 838e7308..7e51f1ab 100644 --- a/test/Broadway/EventDispatcher/EventDispatcherTest.php +++ b/test/Broadway/EventDispatcher/EventDispatcherTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventDispatcher; use Broadway\TestCase; diff --git a/test/Broadway/EventHandling/SimpleEventBusTest.php b/test/Broadway/EventHandling/SimpleEventBusTest.php index c8228cf3..fd8b4619 100644 --- a/test/Broadway/EventHandling/SimpleEventBusTest.php +++ b/test/Broadway/EventHandling/SimpleEventBusTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventHandling; use Broadway\Domain\DomainEventStream; diff --git a/test/Broadway/EventSourcing/AbstractEventSourcingRepositoryTest.php b/test/Broadway/EventSourcing/AbstractEventSourcingRepositoryTest.php index 07945b55..826bb61c 100644 --- a/test/Broadway/EventSourcing/AbstractEventSourcingRepositoryTest.php +++ b/test/Broadway/EventSourcing/AbstractEventSourcingRepositoryTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing; use Broadway\Domain\AggregateRoot; @@ -202,21 +204,22 @@ public function __construct($number) class AnotherTestEventSourcedAggregate extends EventSourcedAggregateRoot { - public function getAggregateRootId() + public function getAggregateRootId(): string { - return 1337; + return '1337'; } } class TestAggregate implements AggregateRoot { - public function getAggregateRootId() + public function getAggregateRootId(): string { - return 42; + return '42'; } - public function getUncommittedEvents() + public function getUncommittedEvents(): DomainEventStream { + return new DomainEventStream([]); } } @@ -225,7 +228,7 @@ class TraceableEventstoreDecorator implements EventStreamDecorator private $tracing = false; private $calls; - public function decorateForWrite($aggregateType, $aggregateIdentifier, DomainEventStream $eventStream) + public function decorateForWrite(string $aggregateType, string $aggregateIdentifier, DomainEventStream $eventStream): DomainEventStream { if ($this->tracing) { $this->calls[] = ['aggregateType' => $aggregateType, 'aggregateIdentifier' => $aggregateIdentifier, 'eventStream' => $eventStream]; @@ -256,7 +259,7 @@ public function getLastCall() class TestDecorationMetadataEnricher implements MetadataEnricher { - public function enrich(Metadata $metadata) + public function enrich(Metadata $metadata): Metadata { return new Metadata(['decoration_test' => 'I am a decorated test']); } diff --git a/test/Broadway/EventSourcing/AggregateFactory/ReflectionAggregateFactoryTest.php b/test/Broadway/EventSourcing/AggregateFactory/ReflectionAggregateFactoryTest.php index 22a8054e..b67f6676 100644 --- a/test/Broadway/EventSourcing/AggregateFactory/ReflectionAggregateFactoryTest.php +++ b/test/Broadway/EventSourcing/AggregateFactory/ReflectionAggregateFactoryTest.php @@ -1,5 +1,7 @@ instantiatedThrough = $instantiatedThrough; } - public function getAggregateRootId() + public function getAggregateRootId(): string { return 'y0l0'; } diff --git a/test/Broadway/EventSourcing/MetadataEnrichment/MetadataEnrichingEventStreamDecoratorTest.php b/test/Broadway/EventSourcing/MetadataEnrichment/MetadataEnrichingEventStreamDecoratorTest.php index fb594fcb..a0d5b368 100644 --- a/test/Broadway/EventSourcing/MetadataEnrichment/MetadataEnrichingEventStreamDecoratorTest.php +++ b/test/Broadway/EventSourcing/MetadataEnrichment/MetadataEnrichingEventStreamDecoratorTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing\MetadataEnrichment; use Broadway\Domain\DomainEventStream; @@ -80,8 +82,7 @@ public function it_calls_the_enricher_when_registered_later() $decorator = new MetadataEnrichingEventStreamDecorator([$constructorEnricher]); $decorator->registerEnricher($newlyRegisteredEnricher); - $eventStream = $this->createDomainEventStream(); - $newEventStream = $decorator->decorateForWrite('id', 'type', $eventStream); + $decorator->decorateForWrite('id', 'type', $this->createDomainEventStream()); $this->assertEquals(2, $constructorEnricher->callCount()); $this->assertEquals(2, $newlyRegisteredEnricher->callCount()); @@ -100,14 +101,14 @@ class TracableMetadataEnricher implements MetadataEnricher { private $calls; - public function enrich(Metadata $metadata) + public function enrich(Metadata $metadata): Metadata { $this->calls[] = $metadata; return $metadata->merge(Metadata::kv('traced', true)); } - public function callCount() + public function callCount(): int { return count($this->calls); } diff --git a/test/Broadway/EventSourcing/SimpleEventSourcedEntityTest.php b/test/Broadway/EventSourcing/SimpleEventSourcedEntityTest.php index c85d15fd..418413a4 100644 --- a/test/Broadway/EventSourcing/SimpleEventSourcedEntityTest.php +++ b/test/Broadway/EventSourcing/SimpleEventSourcedEntityTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventSourcing; use Broadway\TestCase; @@ -77,7 +79,7 @@ class Aggregate extends EventSourcedAggregateRoot { private $children = []; - protected function getChildEntities() + protected function getChildEntities(): array { return $this->children; } @@ -97,8 +99,9 @@ public function doHandleRecursively() $this->handleRecursively(new Event()); } - public function getAggregateRootId() + public function getAggregateRootId(): string { + return '42'; } } @@ -106,7 +109,7 @@ class Entity extends SimpleEventSourcedEntity { private $children = []; - protected function getChildEntities() + protected function getChildEntities(): array { return $this->children; } diff --git a/test/Broadway/EventStore/ConcurrencyConflictResolver/BlacklistConcurrencyConflictResolverTest.php b/test/Broadway/EventStore/ConcurrencyConflictResolver/BlacklistConcurrencyConflictResolverTest.php index 3578bf01..91e9d186 100644 --- a/test/Broadway/EventStore/ConcurrencyConflictResolver/BlacklistConcurrencyConflictResolverTest.php +++ b/test/Broadway/EventStore/ConcurrencyConflictResolver/BlacklistConcurrencyConflictResolverTest.php @@ -1,4 +1,7 @@ createDomainMessage($id, 0); - $baseStream = new DomainEventStream([$domainMessage]); - $this->eventStore->append($id, $baseStream); - $appendedEventStream = new DomainEventStream([$domainMessage]); + $eventStream = new DomainEventStream([$this->createDomainMessage(42, 0)]); - $this->eventStore->append($id, $appendedEventStream); + $this->eventStore->append(42, $eventStream); + $this->eventStore->append(42, $eventStream); } /** @@ -111,14 +111,7 @@ public function it_throws_an_exception_when_an_id_cannot_be_converted_to_a_strin 'Yolntbyaac' //You only live nine times because you are a cat ); - $domainEventStream = new DomainEventStream([ - $this->createDomainMessage($id, 0), - $this->createDomainMessage($id, 1), - $this->createDomainMessage($id, 2), - $this->createDomainMessage($id, 3), - ]); - - $this->eventStore->append($id, $domainEventStream); + $this->eventStore->append($id, new DomainEventStream([])); } /** @@ -181,7 +174,7 @@ public function idDataProvider() ]; } - protected function createDomainMessage($id, $playhead, $recordedOn = null) + protected function createDomainMessage($id, int $playhead, DateTime $recordedOn = null) { return new DomainMessage($id, $playhead, new MetaData([]), new Event(), $recordedOn ? $recordedOn : DateTime::now()); } @@ -194,7 +187,7 @@ public static function deserialize(array $data) return new Event(); } - public function serialize() + public function serialize(): array { return []; } diff --git a/test/Broadway/EventStore/InMemoryEventStoreTest.php b/test/Broadway/EventStore/InMemoryEventStoreTest.php index 9ab37ed0..6f4153f6 100644 --- a/test/Broadway/EventStore/InMemoryEventStoreTest.php +++ b/test/Broadway/EventStore/InMemoryEventStoreTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore; class InMemoryEventStoreTest extends EventStoreTest diff --git a/test/Broadway/EventStore/Management/EventStoreManagementTest.php b/test/Broadway/EventStore/Management/EventStoreManagementTest.php index a8258578..85e22eef 100644 --- a/test/Broadway/EventStore/Management/EventStoreManagementTest.php +++ b/test/Broadway/EventStore/Management/EventStoreManagementTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore\Management; use Broadway\Domain\DateTime; @@ -167,18 +169,16 @@ protected function getEventFixtures() ]; } - private function createDomainMessage($id, $playhead, $event) + private function createDomainMessage($id, int $playhead, $event) { $id = $this->getId($id); - return new DomainMessage((string) $id, (string) $playhead, new Metadata([]), $event, $this->now); + return new DomainMessage((string) $id, $playhead, new Metadata([]), $event, $this->now); } - private function getId($id) + private function getId($id): string { - $uuid = sprintf('%08d-%04d-4%03d-%04d-%012d', $id, $id, $id, $id, $id); - - return $uuid; + return sprintf('%08d-%04d-4%03d-%04d-%012d', $id, $id, $id, $id, $id); } private function assertVisitedEventsArEquals(array $expectedEvents, array $actualEvents) @@ -244,7 +244,7 @@ public static function deserialize(array $data) return new static(); } - public function serialize() + public function serialize(): array { return []; } @@ -267,7 +267,7 @@ public static function deserialize(array $data) return new static($data['position']); } - public function serialize() + public function serialize(): array { return [ 'position' => $this->position, diff --git a/test/Broadway/EventStore/Management/InMemoryEventStoreManagementTest.php b/test/Broadway/EventStore/Management/InMemoryEventStoreManagementTest.php index e45c28b3..6f9e8813 100644 --- a/test/Broadway/EventStore/Management/InMemoryEventStoreManagementTest.php +++ b/test/Broadway/EventStore/Management/InMemoryEventStoreManagementTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\EventStore\Management; use Broadway\EventStore\InMemoryEventStore; diff --git a/test/Broadway/Processor/ProcessorTest.php b/test/Broadway/Processor/ProcessorTest.php index 5fcb1c85..bb9f2509 100644 --- a/test/Broadway/Processor/ProcessorTest.php +++ b/test/Broadway/Processor/ProcessorTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Processor; use Broadway\Domain\DomainMessage; diff --git a/test/Broadway/ReadModel/InMemory/InMemoryRepositoryFactoryTest.php b/test/Broadway/ReadModel/InMemory/InMemoryRepositoryFactoryTest.php index bb1727e2..caca8659 100644 --- a/test/Broadway/ReadModel/InMemory/InMemoryRepositoryFactoryTest.php +++ b/test/Broadway/ReadModel/InMemory/InMemoryRepositoryFactoryTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel\InMemory; use Broadway\TestCase; diff --git a/test/Broadway/ReadModel/InMemory/InMemoryRepositoryTest.php b/test/Broadway/ReadModel/InMemory/InMemoryRepositoryTest.php index f4d12690..8c8c64e8 100644 --- a/test/Broadway/ReadModel/InMemory/InMemoryRepositoryTest.php +++ b/test/Broadway/ReadModel/InMemory/InMemoryRepositoryTest.php @@ -9,14 +9,17 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel\InMemory; +use Broadway\ReadModel\Repository; use Broadway\ReadModel\RepositoryTestCase; use Broadway\ReadModel\RepositoryTestReadModel; class InMemoryRepositoryTest extends RepositoryTestCase { - protected function createRepository() + protected function createRepository(): Repository { return new InMemoryRepository(); } diff --git a/test/Broadway/ReadModel/ProjectorTest.php b/test/Broadway/ReadModel/ProjectorTest.php index 91e2e499..8e618759 100644 --- a/test/Broadway/ReadModel/ProjectorTest.php +++ b/test/Broadway/ReadModel/ProjectorTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel; use Broadway\Domain\DomainMessage; diff --git a/test/Broadway/ReadModel/RepositoryTestCase.php b/test/Broadway/ReadModel/RepositoryTestCase.php index 1f2edf32..17ca366d 100644 --- a/test/Broadway/ReadModel/RepositoryTestCase.php +++ b/test/Broadway/ReadModel/RepositoryTestCase.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel; use Broadway\TestCase; @@ -22,7 +24,7 @@ public function setUp() $this->repository = $this->createRepository(); } - abstract protected function createRepository(); + abstract protected function createRepository(): Repository; /** * @test diff --git a/test/Broadway/ReadModel/RepositoryTestReadModel.php b/test/Broadway/ReadModel/RepositoryTestReadModel.php index 3858ceeb..cdce4810 100644 --- a/test/Broadway/ReadModel/RepositoryTestReadModel.php +++ b/test/Broadway/ReadModel/RepositoryTestReadModel.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\ReadModel; class RepositoryTestReadModel implements SerializableReadModel @@ -18,7 +20,13 @@ class RepositoryTestReadModel implements SerializableReadModel private $foo; private $array; - public function __construct($id, $name, $foo, array $array) + /** + * @param mixed $id + * @param string $name + * @param mixed $foo + * @param array $array + */ + public function __construct($id, string $name, $foo, array $array) { $this->id = (string) $id; $this->name = $name; @@ -26,27 +34,30 @@ public function __construct($id, $name, $foo, array $array) $this->array = $array; } - public function getId() + public function getId(): string { return $this->id; } - public function getName() + public function getName(): string { return $this->name; } + /** + * @return mixed + */ public function getFoo() { return $this->foo; } - public function getArray() + public function getArray(): array { return $this->array; } - public function serialize() + public function serialize(): array { return get_object_vars($this); } diff --git a/test/Broadway/Serializer/SimpleInterfaceSerializerTest.php b/test/Broadway/Serializer/SimpleInterfaceSerializerTest.php index 3c72a0b7..36281017 100644 --- a/test/Broadway/Serializer/SimpleInterfaceSerializerTest.php +++ b/test/Broadway/Serializer/SimpleInterfaceSerializerTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway\Serializer; use Broadway\TestCase; @@ -36,6 +38,7 @@ public function it_throws_an_exception_if_an_object_does_not_implement_Serializa * @test * @expectedException Assert\InvalidArgumentException * @expectedExceptionMessage Key 'class' should be set + * * @todo custom exception */ public function it_throws_an_exception_if_class_not_set_in_data() @@ -109,9 +112,9 @@ public static function deserialize(array $data) } /** - * @return array + * {@inheritdoc} */ - public function serialize() + public function serialize(): array { return ['foo' => $this->foo]; } diff --git a/test/Broadway/TestCase.php b/test/Broadway/TestCase.php index 3eb82cb3..487a2355 100644 --- a/test/Broadway/TestCase.php +++ b/test/Broadway/TestCase.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Broadway; use PHPUnit_Framework_TestCase; diff --git a/test/bootstrap.php b/test/bootstrap.php index b679c36b..f3f1e8b2 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + if (file_exists($file = __DIR__ . '/../vendor/autoload.php')) { $loader = require $file; $loader->add('Broadway', __DIR__);