Passed
Push — 1.x ( 774941...781dbf )
by Kevin
03:22 queued 01:44
created

TestTransportFactory::reset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Zenstruck\Messenger\Test\Transport;
4
5
use Symfony\Component\Messenger\MessageBusInterface;
6
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
7
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
8
use Symfony\Component\Messenger\Transport\TransportInterface;
9
10
/**
11
 * @author Kevin Bond <[email protected]>
12
 *
13
 * @internal
14
 */
15
final class TestTransportFactory implements TransportFactoryInterface
16
{
17
    private MessageBusInterface $bus;
18
19
    public function __construct(MessageBusInterface $bus)
20
    {
21
        $this->bus = $bus;
22
    }
23
24
    public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
25
    {
26
        return new TestTransport($options['transport_name'], $this->bus, $serializer, $this->parseDsn($dsn));
27
    }
28
29
    public function supports(string $dsn, array $options): bool
30
    {
31
        return 0 === \mb_strpos($dsn, 'test://');
32
    }
33
34
    private function parseDsn(string $dsn): array
35
    {
36
        $query = [];
37
38
        if ($queryAsString = \mb_strstr($dsn, '?')) {
39
            \parse_str(\ltrim($queryAsString, '?'), $query);
40
        }
41
42
        return [
43
            'intercept' => \filter_var($query['intercept'] ?? true, \FILTER_VALIDATE_BOOLEAN),
44
            'catch_exceptions' => \filter_var($query['catch_exceptions'] ?? true, \FILTER_VALIDATE_BOOLEAN),
45
        ];
46
    }
47
}
48