Issues (135)

Resolver/Saga/SagaEventSubscriberDefinition.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gember\EventSourcing\Resolver\Saga;
6
7
use Gember\EventSourcing\Common\CreationPolicy;
8
use Gember\EventSourcing\Util\Serialization\Serializable;
9
10
/**
11
 * @phpstan-type SagaEventSubscriberDefinitionPayload array{
12
 *     eventClassName: class-string,
13
 *     methodName: string,
14
 *     policy: string
15
 * }
16
 *
17
 * @implements Serializable<SagaEventSubscriberDefinitionPayload, SagaEventSubscriberDefinition>
18
 */
19
final readonly class SagaEventSubscriberDefinition implements Serializable
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 19 at column 6
Loading history...
20
{
21
    /**
22
     * @param class-string $eventClassName
23
     */
24 18
    public function __construct(
25
        public string $eventClassName,
26
        public string $methodName,
27
        public CreationPolicy $policy,
28 18
    ) {}
29
30 5
    public function toPayload(): array
31
    {
32 5
        return [
33 5
            'eventClassName' => $this->eventClassName,
34 5
            'methodName' => $this->methodName,
35 5
            'policy' => $this->policy->value,
36 5
        ];
37
    }
38
39 5
    public static function fromPayload(array $payload): self
40
    {
41 5
        return new self(
42 5
            $payload['eventClassName'],
43 5
            $payload['methodName'],
44 5
            CreationPolicy::from($payload['policy']),
45 5
        );
46
    }
47
}
48