Passed
Branch master (6c6bd5)
by Sébastien
03:15
created

QueueTransportFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 40
ccs 9
cts 9
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createTransport() 0 5 1
A supports() 0 3 1
A __construct() 0 4 2
1
<?php
2
3
namespace Bdf\QueueMessengerBundle\Transport;
4
5
use Bdf\Dsn\Dsn;
6
use Bdf\Queue\Destination\DestinationManager;
7
use Bdf\QueueMessengerBundle\Transport\Stamp\PhpStampsSerializer;
8
use Bdf\QueueMessengerBundle\Transport\Stamp\StampsSerializerInterface;
9
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
10
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
11
use Symfony\Component\Messenger\Transport\TransportInterface;
12
13
/**
14
 *
15
 */
16
class QueueTransportFactory implements TransportFactoryInterface
17
{
18
    private $manager;
19
    private $stampsSerializer;
20
21
    /**
22
     * QueueTransportFactory constructor.
23
     *
24
     * @param DestinationManager $manager
25
     * @param StampsSerializerInterface|null $stampsSerializer
26
     */
27 2
    public function __construct(DestinationManager $manager, StampsSerializerInterface $stampsSerializer = null)
28
    {
29 2
        $this->manager = $manager;
30 2
        $this->stampsSerializer = $stampsSerializer ?: new PhpStampsSerializer();
31 2
    }
32
33
    /**
34
     * @param string $dsn
35
     * @param array $options
36
     * @param SerializerInterface $serializer
37
     *
38
     * @return TransportInterface
39
     */
40 1
    public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
41
    {
42 1
        $request = Dsn::parse($dsn);
43
44 1
        return new QueueTransport($this->manager->guess($request->getHost()), $this->stampsSerializer, $request->query('consumer_timeout', 1));
45
    }
46
47
    /**
48
     * @param string $dsn
49
     * @param array $options
50
     *
51
     * @return bool
52
     */
53 1
    public function supports(string $dsn, array $options): bool
54
    {
55 1
        return 0 === strpos($dsn, 'bdfqueue');
56
    }
57
}
58