Completed
Push — master ( ca6bb7...fdd070 )
by Alessandro
9s
created

ConnectionFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Services;
6
7
use Facile\MongoDbBundle\Models\ClientConfiguration;
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
            ->getClientForDatabase($clientName,$databaseName)
39 2
            ->selectDatabase($databaseName);
40
    }
41
}
42