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

QueueTransportFactory::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 2
nc 1
nop 2
crap 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