ConnectionFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 26
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createConnection() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Services;
6
7
use MongoDB\Database;
8
9
/**
10
 * Class ConnectionFactory.
11
 *
12
 * @internal
13
 */
14
final class ConnectionFactory
15
{
16
    /** @var ClientRegistry */
17
    private $clientRegistry;
18
19
    /**
20
     * ConnectionFactory constructor.
21 11
     *
22
     * @param ClientRegistry $clientRegistry
23 11
     */
24 11
    public function __construct(ClientRegistry $clientRegistry)
25
    {
26
        $this->clientRegistry = $clientRegistry;
27
    }
28
29
    /**
30
     * @param string $clientName
31
     * @param string $databaseName
32 11
     *
33
     * @return Database
34 11
     */
35 11
    public function createConnection(string $clientName, string $databaseName): Database
36 11
    {
37
        return $this->clientRegistry
38
            ->getClientForDatabase($clientName, $databaseName)
39
            ->selectDatabase($databaseName);
40
    }
41
}
42