Completed
Pull Request — master (#5)
by Alessandro
03:10
created

ConnectionFactory::getClientForConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Services;
6
7
use Facile\MongoDbBundle\Models\ConnectionConfiguration;
8
use MongoDB\Client;
9
use MongoDB\Database;
10
11
/**
12
 * Class ConnectionFactory.
13
 */
14
class ConnectionFactory
15
{
16
    /** @var ClientRegistry */
17
    private $clientRegistry;
18
19
    /**
20
     * ConnectionFactory constructor.
21
     *
22
     * @param ClientRegistry $clientRegistry
23
     */
24 2
    public function __construct(ClientRegistry $clientRegistry)
25
    {
26 2
        $this->clientRegistry = $clientRegistry;
27 2
    }
28
29
    /**
30
     * @param string $clientName
31
     * @param string $databaseName
32
     *
33
     * @return Database
34
     */
35 2
    public function createConnection(string $clientName, string $databaseName): Database
36
    {
37 2
        return $this->clientRegistry
38 2
            ->getClient($clientName)
39 2
            ->selectDatabase($databaseName);
40
    }
41
}
42