-
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.
- psalm set to level 3 - [WiP] phpstan set to level 6
- Loading branch information
Showing
26 changed files
with
142 additions
and
66 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
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,14 +26,20 @@ 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); | ||
|
||
/** | ||
* @return array<scalar, scalar> | ||
*/ | ||
public function metadata(): array; | ||
} |
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,44 @@ 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: non-empty-string, | ||
* producer_id: non-empty-string, | ||
* entity_type: non-empty-string, | ||
* entity_id: non-empty-string, | ||
* version?: positive-int, | ||
* } | ||
*/ | ||
private array $metadata; | ||
|
||
/** | ||
* @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,18 +80,15 @@ 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]); | ||
} | ||
|
||
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; | ||
} | ||
|
@@ -84,7 +100,7 @@ public function producerId(): Domain\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((string) $this->get(self::METADATA_PRODUCER_ID)); | ||
} | ||
|
||
public function entityId(): Domain\Id | ||
|
@@ -94,12 +110,12 @@ public function entityId(): Domain\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((string) $this->get(self::METADATA_ENTITY_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 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
|
||
/** | ||
* @author Alan Gabriel Bem <[email protected]> | ||
* | ||
* @psalm-immutable | ||
*/ | ||
interface Stream extends \Traversable | ||
{ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
|
||
/** | ||
* @author Alan Gabriel Bem <[email protected]> | ||
* | ||
* @see \Streak\Infrastructure\Domain\AggregateRoot\Snapshotter\Storage\RedisStorageTest | ||
*/ | ||
final class RedisStorage implements Storage, Resettable | ||
{ | ||
|
@@ -38,12 +40,17 @@ public function find(AggregateRoot $aggregate): string | |
throw new SnapshotNotFound($aggregate); | ||
} | ||
|
||
// Redis::get() can return Redis instance when it's in multi() mode. | ||
if ($snapshot instanceof \Redis) { | ||
throw new SnapshotNotFound($aggregate); | ||
} | ||
|
||
return $snapshot; | ||
} | ||
|
||
public function store(AggregateRoot $aggregate, string $snapshot): void | ||
{ | ||
$this->redis->set($this->key($aggregate), (string) $snapshot); | ||
$this->redis->set($this->key($aggregate), $snapshot); | ||
} | ||
|
||
public function reset(): bool | ||
|
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 |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
/** | ||
* @author Alan Gabriel Bem <[email protected]> | ||
* | ||
* @psalm-immutable | ||
* | ||
* @see \Streak\Infrastructure\Domain\Event\InMemoryStreamTest | ||
*/ | ||
final class InMemoryStream implements \IteratorAggregate, Event\Stream | ||
|
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 |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
use Streak\Infrastructure\Domain\Event\LoggingListener; | ||
|
||
/** | ||
* @implements Event\Listener\Factory<LoggingListener> | ||
* | ||
* @author Alan Gabriel Bem <[email protected]> | ||
* | ||
* @see \Streak\Infrastructure\Domain\Event\LoggingListener\FactoryTest | ||
|
@@ -28,14 +30,14 @@ public function __construct(private Event\Listener\Factory $factory, private Log | |
{ | ||
} | ||
|
||
public function create(Event\Listener\Id $id): Event\Listener | ||
public function create(Event\Listener\Id $id): LoggingListener | ||
{ | ||
$saga = $this->factory->create($id); | ||
|
||
return new LoggingListener($saga, $this->logger); | ||
} | ||
|
||
public function createFor(Event\Envelope $event): Event\Listener | ||
public function createFor(Event\Envelope $event): LoggingListener | ||
{ | ||
$listener = $this->factory->createFor($event); | ||
|
||
|
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 |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
use Streak\Infrastructure\Domain\UnitOfWork; | ||
|
||
/** | ||
* @implements Event\Subscription\Factory<CommittingSubscription> | ||
* | ||
* @author Alan Gabriel Bem <[email protected]> | ||
* | ||
* @see \Streak\Infrastructure\Domain\Event\Subscription\CommittingSubscription\FactoryTest | ||
|
@@ -29,7 +31,7 @@ public function __construct(private Subscription\Factory $factory, private UnitO | |
{ | ||
} | ||
|
||
public function create(Event\Listener $listener): Event\Subscription | ||
public function create(Event\Listener $listener): CommittingSubscription | ||
{ | ||
$subscription = $this->factory->create($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
Oops, something went wrong.