Test Failed
Push — master ( 2530ac...3f2955 )
by Vincent
10:10 queued 07:25
created

Configuration   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 82.61%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 17
c 1
b 1
f 0
dl 0
loc 69
ccs 19
cts 23
cp 0.8261
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 3 1
A getDriver() 0 3 1
A __construct() 0 3 1
A get() 0 3 1
A getConnection() 0 3 1
A has() 0 3 1
A createConfiguration() 0 17 3
1
<?php
2
3
namespace Bdf\QueueBundle\ConnectionFactory;
4
5
use Bdf\Queue\Connection\Factory\ResolverConnectionDriverFactory;
6
7
/**
8
 * Configuration
9
 */
10
final class Configuration
11
{
12
    private $config;
13
14 1
    public function __construct(array $config)
15
    {
16 1
        $this->config = $config;
17 1
    }
18
19
    /**
20
     * Get the driver name
21
     */
22 1
    public function getDriver(): string
23
    {
24 1
        return $this->config['driver'];
25
    }
26
27
    /**
28
     * Get the connection name
29
     */
30 1
    public function getConnection(): string
31
    {
32 1
        return $this->config['connection'];
33
    }
34
35
    /**
36
     * Get a configuration key
37
     */
38
    public function get(string $key, $default = null)
39
    {
40
        return $this->config[$key] ?? $default;
41
    }
42
43
    /**
44
     * Check whether a configuration key exists
45
     */
46
    public function has(string $key): bool
47
    {
48
        return isset($this->config[$key]);
49
    }
50
51
    /**
52
     * Get the array config
53
     */
54 1
    public function toArray(): array
55
    {
56 1
        return $this->config;
57
    }
58
59
    /**
60
     * Create the configuration of the connection driver
61
     */
62 1
    public static function createConfiguration(string $name, array $options): self
63
    {
64
        // pre format driver options
65 1
        $preparedConfig = [];
66
67 1
        if (isset($options['url'])) {
68 1
            $preparedConfig = ResolverConnectionDriverFactory::parseDsn($options['url']);
69
        }
70 1
        if (!empty($options['options'])) {
71 1
            $options = array_merge($options, $options['options']);
72
        }
73
74 1
        unset($options['url'], $options['options'], $options['connection_factory']);
75 1
        $preparedConfig = array_merge($preparedConfig, array_filter($options));
76 1
        $factory = new ResolverConnectionDriverFactory([$name => $preparedConfig]);
77
78 1
        return new self($factory->getConfig($name));
79
    }
80
}