| Total Complexity | 5 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | final class TypeValidatingEventSerializer implements EventSerializer |
||
| 8 | { |
||
| 9 | private $serializer; |
||
| 10 | private $eventClassName; |
||
| 11 | |||
| 12 | 5 | public function __construct( |
|
| 13 | EventSerializer $serializer, |
||
| 14 | string $eventClassName |
||
| 15 | ) { |
||
| 16 | 5 | $this->serializer = $serializer; |
|
| 17 | 5 | $this->eventClassName = $eventClassName; |
|
| 18 | 5 | } |
|
| 19 | |||
| 20 | 2 | public function serializeEvent(object $event): array |
|
| 21 | { |
||
| 22 | 2 | if ( ! $event instanceof $this->eventClassName) { |
|
| 23 | 1 | throw new \InvalidArgumentException(sprintf( |
|
| 24 | 1 | 'Cannot serialize event that does not implement "%s".', |
|
| 25 | 1 | $this->eventClassName |
|
| 26 | )); |
||
| 27 | } |
||
| 28 | |||
| 29 | 1 | return $this->serializer->serializeEvent($event); |
|
| 30 | } |
||
| 31 | |||
| 32 | 2 | public function unserializePayload(string $className, array $payload): object |
|
| 42 | } |
||
| 43 | } |
||
| 44 |