Passed
Push — master ( b0f8c9...462be0 )
by Sébastien
03:24
created

PrimeConnectionFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getSupportedDrivers() 0 3 1
A configure() 0 10 2
1
<?php
2
3
namespace Bdf\QueueBundle\ConnectionFactory;
4
5
use Bdf\Queue\Connection\ConnectionDriverInterface;
6
use Bdf\Queue\Connection\Prime\PrimeConnection;
0 ignored issues
show
Bug introduced by
The type Bdf\Queue\Connection\Prime\PrimeConnection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Bdf\Queue\Serializer\SerializerInterface;
8
use Psr\Container\ContainerInterface;
9
10
/**
11
 * Create a prime connection from "b2pweb/bdf-queue-prime-adapter".
12
 * Use "prime" key as driver to create a prime connection.
13
 * ex:
14
 *  prime://{prime_connection_name}?table={db_table}
15
 */
16
class PrimeConnectionFactory implements ConnectionDriverConfiguratorInterface
17
{
18
    /**
19
     * @var ContainerInterface
20
     */
21
    private $container;
22
23
    /**
24
     * @param ContainerInterface $container
25
     */
26 4
    public function __construct(ContainerInterface $container)
27
    {
28 4
        $this->container = $container;
29 4
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34 4
    public function getSupportedDrivers(): array
35
    {
36 4
        return ['prime'];
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42 1
    public function configure(Configuration $config, SerializerInterface $serializer): ConnectionDriverInterface
43
    {
44 1
        if (!class_exists(PrimeConnection::class)) {
45
            throw new \LogicException('Could not create the prime connection bdf-queue. Try to composer require "b2pweb/bdf-queue-prime-adapter" to add this class.');
46
        }
47
48 1
        $connection = new PrimeConnection($config->getConnection(), $serializer, $this->container->get('prime')->connections());
49 1
        $connection->setConfig($config->toArray());
50
51 1
        return $connection;
52
    }
53
}