GemberPHP /
event-sourcing
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Gember\EventSourcing\UseCase; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * @phpstan-require-implements EventSourcedUseCase |
||
| 9 | */ |
||
| 10 | trait EventSourcedUseCaseBehaviorTrait |
||
| 11 | { |
||
| 12 | private ?string $lastEventId = null; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var list<object> |
||
|
0 ignored issues
–
show
|
|||
| 16 | */ |
||
| 17 | private array $appliedEvents = []; |
||
| 18 | |||
| 19 | 6 | public function apply(object $event): void |
|
| 20 | { |
||
| 21 | 6 | $this->appliedEvents[] = $event; |
|
| 22 | 6 | $this->applyEventInUseCase($event); |
|
| 23 | } |
||
| 24 | |||
| 25 | 5 | public function getDomainTags(): array |
|
| 26 | { |
||
| 27 | 5 | return array_map( |
|
| 28 | 5 | fn($domainTagDefinition) => $this->{$domainTagDefinition->domainTagName}, |
|
| 29 | 5 | UseCaseAttributeRegistry::getUseCaseDefinition($this::class)->domainTags, |
|
| 30 | 5 | ); |
|
| 31 | } |
||
| 32 | |||
| 33 | 2 | public function getLastEventId(): ?string |
|
| 34 | { |
||
| 35 | 2 | return $this->lastEventId; |
|
| 36 | } |
||
| 37 | |||
| 38 | 3 | public function getAppliedEvents(): array |
|
| 39 | { |
||
| 40 | 3 | $appliedEvents = $this->appliedEvents; |
|
|
0 ignored issues
–
show
It seems like
$this->appliedEvents of type array is incompatible with the declared type Gember\EventSourcing\UseCase\list of property $appliedEvents.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 41 | |||
| 42 | 3 | $this->appliedEvents = []; |
|
| 43 | |||
| 44 | 3 | return $appliedEvents; |
|
| 45 | } |
||
| 46 | |||
| 47 | 3 | public static function reconstitute(DomainEventEnvelope ...$envelopes): self |
|
|
0 ignored issues
–
show
The type
Gember\EventSourcing\UseCase\DomainEventEnvelope was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 48 | { |
||
| 49 | 3 | $useCase = new self(); |
|
| 50 | |||
| 51 | 3 | foreach ($envelopes as $envelope) { |
|
| 52 | 3 | $useCase->applyEventInUseCase($envelope->event); |
|
| 53 | 3 | $useCase->lastEventId = $envelope->eventId; |
|
| 54 | } |
||
| 55 | |||
| 56 | 3 | return $useCase; |
|
| 57 | } |
||
| 58 | |||
| 59 | 9 | private function applyEventInUseCase(object $event): void |
|
| 60 | { |
||
| 61 | 9 | $useCaseDefinition = UseCaseAttributeRegistry::getUseCaseDefinition($this::class); |
|
| 62 | 9 | foreach ($useCaseDefinition->eventSubscribers as $eventSubscriber) { |
|
| 63 | 8 | if ($eventSubscriber->eventClassName !== $event::class) { |
|
| 64 | 6 | continue; |
|
| 65 | } |
||
| 66 | |||
| 67 | 6 | $this->{$eventSubscriber->methodName}($event); |
|
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths