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

PrimeConnectionFactory::getSupportedDrivers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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