EventSourcedUseCaseBehaviorTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 20
dl 0
loc 55
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 0 4 1
A getAppliedEvents() 0 7 1
A getDomainIds() 0 5 1
A applyEventInUseCase() 0 6 2
A reconstitute() 0 10 2
A getLastEventId() 0 3 1
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
Bug introduced by
The type Gember\EventSourcing\UseCase\list 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
     */
17
    private array $appliedEvents = [];
18
19 5
    public function apply(object $event): void
20
    {
21 5
        $this->appliedEvents[] = $event;
22 5
        $this->applyEventInUseCase($event);
23
    }
24
25 3
    public function getDomainIds(): array
26
    {
27 3
        return array_map(
28 3
            fn($property) => $this->{$property},
29 3
            UseCaseAttributeRegistry::getDomainIdPropertiesForUseCase($this::class),
30 3
        );
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
Documentation Bug introduced by
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
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

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 8
    private function applyEventInUseCase(object $event): void
60
    {
61 8
        $method = UseCaseAttributeRegistry::getUseCaseSubscriberMethodForEvent($this::class, $event::class);
62
63 8
        if ($method !== null) {
64 6
            $this->{$method}($event);
65
        }
66
    }
67
}
68