Completed
Pull Request — master (#6)
by Antonio Oertel
03:40
created

Driver   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 93.75%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 12
c 2
b 0
f 1
lcom 1
cbo 4
dl 0
loc 127
ccs 30
cts 32
cp 0.9375
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A factoryLegacy() 0 15 2
A factory() 0 14 2
A getConnection() 0 4 1
A fetch() 0 4 1
A find() 0 4 1
A generateQuery() 0 4 1
A insert() 0 4 1
A update() 0 4 1
A remove() 0 4 1
1
<?php
2
3
namespace Respect\Structural\Driver\MongoDb;
4
5
use Respect\Structural\Driver\Exception as DriverException;
6
use MongoDB\Client as MongoDBClient;
7
use Respect\Data\Collections\Collection;
8
use Respect\Structural\Driver as BaseDriver;
9
10
class Driver implements BaseDriver
11
{
12
    /**
13
     * @var MongoDBClient
14
     */
15
    private $connection;
16
17 2
    protected function __construct(BaseDriver $connection)
18
    {
19 2
        $this->connection = $connection;
0 ignored issues
show
Documentation Bug introduced by
It seems like $connection of type object<Respect\Structural\Driver> is incompatible with the declared type object<MongoDB\Client> of property $connection.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
20 2
    }
21
22
    /**
23
     * @param string $database
24
     * @param string $server
25
     * @param array  $options
26
     * @param array  $driverOptions
27
     *
28
     * @return Driver
29
     *
30
     * @throws DriverException
31
     */
32 1
    public static function factoryLegacy(
33
        $database,
34
        $server = 'mongodb://localhost:27017',
35
        array $options = ['connect' => false],
36
        array $driverOptions = []
37
    ) {
38 1
        if (!extension_loaded('mongo')) {
39
            throw DriverException::extensionNotLoaded('mongo');
40
        }
41
42 1
        $client = new \MongoClient($server, $options, $driverOptions);
43 1
        $driver = new MongoDriver($client, $database);
44
45 1
        return new self($driver);
46
    }
47
48
    /**
49
     * @param string $database
50
     * @param string $uri
51
     * @param array  $uriOptions
52
     * @param array  $driverOptions
53
     *
54
     * @return Driver
55
     *
56
     * @throws DriverException
57
     */
58 1
    public static function factory(
59
        $database,
60
        $uri = 'mongodb://localhost:27017',
61
        array $uriOptions = [],
62
        array $driverOptions = []
63
    ) {
64 1
        if (!extension_loaded('mongodb')) {
65
            throw DriverException::extensionNotLoaded('mongodb');
66
        }
67 1
        $client = new \MongoDB\Client($uri, $uriOptions, $driverOptions);
68 1
        $driver = new MongoDbDriver($client, $database);
69
70 1
        return new self($driver);
71
    }
72
73
    /**
74
     * @return Driver
75
     */
76 2
    public function getConnection()
77
    {
78 2
        return $this->connection;
79
    }
80
81
    /**
82
     * @param \Iterator $cursor
83
     *
84
     * @return array
85
     */
86 1
    public function fetch(\Iterator $cursor)
87
    {
88 1
        return $this->getConnection()->fetch($cursor);
0 ignored issues
show
Bug introduced by
The method fetch() does not seem to exist on object<MongoDB\Client>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
    }
90
91
    /**
92
     * @param array $collection
93
     * @param array $query
94
     *
95
     * @return \Iterator
96
     */
97 1
    public function find($collection, array $query = [])
98
    {
99 1
        return $this->getConnection()->find($collection, $query);
0 ignored issues
show
Bug introduced by
The method find() does not seem to exist on object<MongoDB\Client>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
    }
101
102
    /**
103
     * @param Collection $collection
104
     *
105
     * @return array
106
     */
107 1
    public function generateQuery(Collection $collection)
108
    {
109 1
        return $this->getConnection()->generateQuery($collection);
0 ignored issues
show
Bug introduced by
The method generateQuery() does not seem to exist on object<MongoDB\Client>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
110
    }
111
112
    /**
113
     * @param Collection $collection
114
     * @param $document
115
     *
116
     * @return void
117
     */
118 1
    public function insert($collection, $document)
119
    {
120 1
        $this->getConnection()->insert($collection, $document);
0 ignored issues
show
Bug introduced by
The method insert() does not seem to exist on object<MongoDB\Client>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
121 1
    }
122
123 1
    public function update($collection, $criteria, $document)
124
    {
125 1
        $this->getConnection()->update($collection, $criteria, $document);
0 ignored issues
show
Bug introduced by
The method update() does not seem to exist on object<MongoDB\Client>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
126 1
    }
127
128
    /**
129
     * @param string $collection
130
     * @param array  $criteria
131
     */
132 1
    public function remove($collection, $criteria)
133
    {
134 1
        $this->getConnection()->remove($collection, $criteria);
0 ignored issues
show
Bug introduced by
The method remove() does not seem to exist on object<MongoDB\Client>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
135 1
    }
136
}
137