Client::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 5
dl 0
loc 10
ccs 4
cts 4
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\Capsule;
6
7
use MongoDB\Client as MongoClient;
8
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9
10
/**
11
 * Class Client.
12
 *
13
 * @internal
14
 */
15
final class Client extends MongoClient
16
{
17
    /** @var EventDispatcherInterface */
18
    private $eventDispatcher;
19
20
    /** @var string */
21
    private $clientName;
22
23
    /**
24
     * Client constructor.
25
     *
26
     * @param string $uri
27
     * @param array $uriOptions
28
     * @param array $driverOptions
29
     * @param string $clientName
30 6
     * @param EventDispatcherInterface $eventDispatcher
31
     *
32
     * @internal param DataCollectorLoggerInterface $logger
33
     */
34
    public function __construct(
35
        $uri = 'mongodb://localhost:27017',
36
        array $uriOptions = [],
37 6
        array $driverOptions = [],
38 6
        string $clientName,
39 6
        EventDispatcherInterface $eventDispatcher
40 6
    ) {
41
        parent::__construct($uri, $uriOptions, $driverOptions);
42
        $this->eventDispatcher = $eventDispatcher;
43
        $this->clientName = $clientName;
44
    }
45 4
46
    /**
47 4
     * {@inheritdoc}
48
     */
49 4
    public function selectDatabase($databaseName, array $options = [])
50
    {
51
        $debug = $this->__debugInfo();
52 4
        $options += [
53
            'typeMap' => $debug['typeMap'],
54
        ];
55
56
        return new Database($debug['manager'], $this->clientName, $databaseName, $options, $this->eventDispatcher);
57
    }
58 1
59
    /**
60 1
     * {@inheritdoc}
61
     */
62 1
    public function selectCollection($databaseName, $collectionName, array $options = [])
63
    {
64
        $debug = $this->__debugInfo();
65 1
        $options += [
66
            'typeMap' => $debug['typeMap'],
67
        ];
68
69
        return new Collection($debug['manager'], $this->clientName, $databaseName, $collectionName, $options, $this->eventDispatcher);
70
    }
71
}
72