ConnectionFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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