-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- phpstan set to level 3
- Loading branch information
Showing
40 changed files
with
210 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
parameters: | ||
level: 2 | ||
level: 3 | ||
paths: | ||
- src/ | ||
- tests/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,15 +14,16 @@ | |
namespace Streak\Application; | ||
|
||
use Streak\Domain; | ||
use Streak\Domain\Exception\CommandNotSupported; | ||
use Streak\Domain\Exception; | ||
|
||
/** | ||
* @author Alan Gabriel Bem <[email protected]> | ||
*/ | ||
interface CommandBus | ||
{ | ||
/** | ||
* @throws CommandNotSupported | ||
* @throws Exception\CommandNotSupported | ||
* @throws Exception\ConcurrentWriteDetected | ||
*/ | ||
public function dispatch(Domain\Command $command): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
use Streak\Domain\Id\UUID; | ||
|
||
/** | ||
* @template T of object | ||
* | ||
* @author Alan Gabriel Bem <[email protected]> | ||
*/ | ||
interface Envelope extends ValueObject | ||
|
@@ -24,12 +26,15 @@ public function uuid(): UUID; | |
|
||
public function name(): string; | ||
|
||
/** | ||
* @return T | ||
*/ | ||
public function message(); | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return float|int|string|null | ||
* @return null|scalar | ||
*/ | ||
public function get($name); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ | |
/** | ||
* @author Alan Gabriel Bem <[email protected]> | ||
* | ||
* @template T of Event | ||
* @template TMessage as Event | ||
* @implements Domain\Envelope<TMessage> | ||
* | ||
* @see \Streak\Domain\Event\EnvelopeTest | ||
*/ | ||
|
@@ -33,26 +34,45 @@ final class Envelope implements Domain\Envelope | |
public const METADATA_PRODUCER_ID = 'producer_id'; | ||
public const METADATA_ENTITY_TYPE = 'entity_type'; | ||
public const METADATA_ENTITY_ID = 'entity_id'; | ||
private array $metadata = []; | ||
|
||
/** | ||
* @param T $message | ||
* @var-phpstan non-empty-array<non-empty-string, scalar> | ||
* @var-psalm non-empty-array<non-empty-string, scalar>&array{ | ||
* uuid: non-empty-string, | ||
* name: non-empty-string, | ||
* producer_type: class-string<Domain\Id>, | ||
* producer_id: non-empty-string, | ||
* entity_type: class-string<Domain\Id>, | ||
* entity_id: non-empty-string, | ||
* version?: positive-int, | ||
* } | ||
*/ | ||
private array $metadata; | ||
|
||
/** | ||
* @param non-empty-string $name | ||
* @param TMessage $message | ||
*/ | ||
public function __construct(UUID $uuid, string $name, private Event $message, Domain\Id $producerId, Domain\Id $entityId, ?int $version = null) | ||
{ | ||
$this->metadata[self::METADATA_UUID] = $uuid->toString(); | ||
$this->metadata[self::METADATA_NAME] = $name; | ||
$this->metadata[self::METADATA_PRODUCER_TYPE] = $producerId::class; | ||
$this->metadata[self::METADATA_PRODUCER_ID] = $producerId->toString(); | ||
$this->metadata[self::METADATA_ENTITY_TYPE] = $entityId::class; | ||
$this->metadata[self::METADATA_ENTITY_ID] = $entityId->toString(); | ||
$this->metadata = [ | ||
self::METADATA_UUID => $uuid->toString(), | ||
self::METADATA_NAME => $name, | ||
self::METADATA_PRODUCER_TYPE => $producerId::class, | ||
self::METADATA_PRODUCER_ID => $producerId->toString(), | ||
self::METADATA_ENTITY_TYPE => $entityId::class, | ||
self::METADATA_ENTITY_ID => $entityId->toString(), | ||
]; | ||
if (null !== $version) { | ||
$this->metadata[self::METADATA_VERSION] = $version; | ||
} | ||
} | ||
|
||
/** | ||
* @return Envelope<T> | ||
* @template TEvent of Event | ||
* @param TEvent $message | ||
* | ||
* @return self<TEvent> | ||
*/ | ||
public static function new(Event $message, Domain\Id $producerId, ?int $version = null): self | ||
{ | ||
|
@@ -61,55 +81,54 @@ public static function new(Event $message, Domain\Id $producerId, ?int $version | |
|
||
public function uuid(): UUID | ||
{ | ||
return new UUID($this->get(self::METADATA_UUID)); | ||
return new UUID($this->metadata[self::METADATA_UUID]); | ||
} | ||
|
||
/** | ||
* @return non-empty-string | ||
*/ | ||
public function name(): string | ||
{ | ||
return $this->get(self::METADATA_NAME); | ||
return $this->metadata[self::METADATA_NAME]; | ||
} | ||
|
||
/** | ||
* @return T | ||
*/ | ||
public function message(): Event | ||
public function message() | ||
{ | ||
return $this->message; | ||
} | ||
|
||
public function producerId(): Domain\Id | ||
{ | ||
$class = $this->get(self::METADATA_PRODUCER_TYPE); | ||
$class = $this->metadata[self::METADATA_PRODUCER_TYPE]; | ||
$id = $this->metadata[self::METADATA_PRODUCER_ID]; | ||
|
||
/** @var class-string<Domain\Id> $class */ | ||
/** @phpstan-var class-string<Domain\Id> $class */ | ||
/** @psalm-var class-string<Domain\Id> $class */ | ||
return $class::fromString($this->get(self::METADATA_PRODUCER_ID)); | ||
return $class::fromString($id); | ||
} | ||
|
||
public function entityId(): Domain\Id | ||
{ | ||
$class = $this->get(self::METADATA_ENTITY_TYPE); | ||
$class = $this->metadata[self::METADATA_ENTITY_TYPE]; | ||
$id = $this->metadata[self::METADATA_ENTITY_ID]; | ||
|
||
/** @var class-string<Domain\Id> $class */ | ||
/** @phpstan-var class-string<Domain\Id> $class */ | ||
/** @psalm-var class-string<Domain\Id> $class */ | ||
return $class::fromString($this->get(self::METADATA_ENTITY_ID)); | ||
return $class::fromString($id); | ||
} | ||
|
||
public function version(): ?int | ||
{ | ||
return $this->get(self::METADATA_VERSION); | ||
return $this->metadata[self::METADATA_VERSION] ?? null; | ||
} | ||
|
||
public function set(string $name, $value): self | ||
/** | ||
* @param non-empty-string $name | ||
* @return self<TMessage> | ||
*/ | ||
public function set(string $name, bool|float|int|string $value): self | ||
{ | ||
if (empty($name)) { | ||
if (empty($name)) { // @phpstan-ignore-line | ||
throw new \InvalidArgumentException('Name of the attribute can not be empty.'); | ||
} | ||
if (!\is_scalar($value)) { | ||
throw new \InvalidArgumentException(sprintf('Value for attribute "%s" is a scalar.', $name)); | ||
} | ||
|
||
$new = new self( | ||
$this->uuid(), | ||
|
@@ -149,6 +168,9 @@ public function equals(object $envelope): bool | |
return true; | ||
} | ||
|
||
/** | ||
* @return self<TMessage> | ||
*/ | ||
public function defineVersion(int $version): self | ||
{ | ||
return new self( | ||
|
@@ -161,6 +183,9 @@ public function defineVersion(int $version): self | |
); | ||
} | ||
|
||
/** | ||
* @return self<TMessage> | ||
*/ | ||
public function defineEntityId(Domain\Id $entityId): self | ||
{ | ||
return new self( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,20 +15,25 @@ | |
|
||
use Streak\Domain\Event; | ||
use Streak\Domain\Event\Exception\InvalidEventGiven; | ||
use Streak\Domain\Event\Listener; | ||
use Streak\Domain\Exception\InvalidIdGiven; | ||
|
||
/** | ||
* @template T of Event\Listener | ||
* | ||
* @author Alan Gabriel Bem <[email protected]> | ||
*/ | ||
interface Factory | ||
{ | ||
/** | ||
* @return T | ||
* | ||
* @throws InvalidIdGiven | ||
*/ | ||
public function create(Listener\Id $id): Listener; | ||
public function create(Event\Listener\Id $id): Event\Listener; | ||
|
||
/** | ||
* @return T | ||
* | ||
* @throws InvalidEventGiven | ||
*/ | ||
public function createFor(Event\Envelope $event): Event\Listener; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,14 @@ | |
use Streak\Domain\Event; | ||
|
||
/** | ||
* @template T of Event\Subscription | ||
* | ||
* @author Alan Gabriel Bem <[email protected]> | ||
*/ | ||
interface Factory | ||
{ | ||
/** | ||
* @return T | ||
*/ | ||
public function create(Event\Listener $listener): Event\Subscription; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.