Database   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 28
dl 0
loc 72
ccs 26
cts 26
cp 1
rs 10
c 2
b 1
f 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A withOptions() 0 11 1
A __construct() 0 11 1
A selectCollection() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Capsule;
6
7
use MongoDB\Database as MongoDatabase;
8
use MongoDB\Driver\Manager;
9
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
10
11
/**
12
 * Class Database.
13
 *
14
 * @internal
15
 */
16
final class Database extends MongoDatabase
17
{
18
    /** @var EventDispatcherInterface */
19
    private $eventDispatcher;
20
21
    /** @var string */
22
    private $clientName;
23
24
    /** @var string */
25
    private $databaseName;
26
27
    /**
28
     * Database constructor.
29
     *
30
     * @param Manager $manager
31
     * @param string $clientName
32
     * @param string $databaseName
33 6
     * @param array $options
34
     * @param EventDispatcherInterface $eventDispatcher
35
     *
36
     * @internal param DataCollectorLoggerInterface $logger
37
     */
38
    public function __construct(
39
        Manager $manager,
40 6
        string $clientName,
41 6
        string $databaseName,
42 6
        array $options = [],
43 6
        EventDispatcherInterface $eventDispatcher
44 6
    ) {
45
        parent::__construct($manager, $databaseName, $options);
46
        $this->eventDispatcher = $eventDispatcher;
47
        $this->clientName = $clientName;
48
        $this->databaseName = $databaseName;
49 1
    }
50
51 1
    /**
52
     * {@inheritdoc}
53 1
     */
54 1
    public function selectCollection($collectionName, array $options = [])
55 1
    {
56 1
        $debug = $this->__debugInfo();
57
        $options += [
58
            'readConcern' => $debug['readConcern'],
59 1
            'readPreference' => $debug['readPreference'],
60 1
            'typeMap' => $debug['typeMap'],
61 1
            'writeConcern' => $debug['writeConcern'],
62 1
        ];
63 1
64 1
        return new Collection(
65 1
            $debug['manager'],
66
            $this->clientName,
67
            $this->databaseName,
68
            $collectionName,
69
            $options,
70
            $this->eventDispatcher
71
        );
72 1
    }
73
74 1
    /**
75
     * {@inheritdoc}
76 1
     */
77 1
    public function withOptions(array $options = [])
78 1
    {
79 1
        $debug = $this->__debugInfo();
80
        $options += [
81
            'readConcern' => $debug['readConcern'],
82 1
            'readPreference' => $debug['readPreference'],
83
            'typeMap' => $debug['typeMap'],
84
            'writeConcern' => $debug['writeConcern'],
85
        ];
86
87
        return new self($debug['manager'], $this->clientName, $debug['databaseName'], $options, $this->eventDispatcher);
88
    }
89
}
90