Lines 100.00% 9 / 9
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 create 100.00% 8 / 8 100.00% 1 / 1 4
26final readonly class MessageBusFactory
27{
28    public function __construct(
29        private Configuration $configuration,
30        private DatabaseTransport $databaseTransport,
31    ) {
32    }
33
34    public function create(): DatabaseMessageBus
35    {
36        $transport = strtolower((string) ($this->configuration->get('queue.transport') ?? 'database'));
37
38        return match ($transport) {
39            'database' => new DatabaseMessageBus($this->databaseTransport),
40            'redis', 'amqp' => throw new RuntimeException(sprintf(
41                'Queue transport "%s" is not implemented yet.',
42                $transport,
43            )),
44            default => throw new RuntimeException('Unsupported queue transport: ' . $transport),
45        };
46    }
47}