Passed
Push — master ( 5379a4...a2888f )
by Joao
04:49
created

src/Repository/NoSqlDataset.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace ByJG\AnyDataset\Repository;
4
5
use ByJG\AnyDataset\ConnectionManagement;
6
use ByJG\AnyDataset\Database\MongoDBDriver;
7
use ByJG\AnyDataset\Database\NoSQLDriverInterface;
8
use InvalidArgumentException;
9
10
class NoSqlDataset implements NoSQLDriverInterface
11
{
12
13
    /**
14
     * Enter description here...
15
     *
16
     * @var ConnectionManagement
17
     */
18
    protected $_connectionManagement;
19
20
    /**
21
     *
22
     * @var NoSQLDriverInterface
23
     */
24
    protected $_dbDriver = null;
25
26
    /**
27
     *
28
     * @param string $dbname
29
     * @param string $collection
30
     * @throws InvalidArgumentException
31
     */
32
    public function __construct($dbname, $collection)
33
    {
34
        $this->_connectionManagement = new ConnectionManagement($dbname);
35
36
        if ($this->_connectionManagement->getDriver() == "mongodb") {
37
            $this->_dbDriver = new MongoDBDriver($this->_connectionManagement, $collection);
38
        } else {
39
            throw new InvalidArgumentException("There is no '{$this->_connectionManagement->getDriver()}' NoSQL database");
40
        }
41
    }
42
43
    public function getDbType()
44
    {
45
        return $this->_connectionManagement->getDbType();
46
    }
47
48
    public function getDbConnectionString()
49
    {
50
        return $this->_connectionManagement->getDbConnectionString();
51
    }
52
53
    public function testConnection()
54
    {
55
        return true;
56
    }
57
58
    /**
59
     *
60
     * @return mixed
61
     */
62
    public function getCollection()
63
    {
64
        return $this->_dbDriver->getCollection();
65
    }
66
67
    /**
68
     *
69
     * @param mixed $filter
70
     * @param null $fields
71
     * @return IteratorInterface $filter
72
     */
73
    public function getIterator($filter = null, $fields = null)
74
    {
75
        return $this->_dbDriver->getIterator($filter, $fields);
76
    }
77
78
    /**
79
     *
80
     * @param void $document
81
     */
82
    public function insert($document)
83
    {
84
        $this->_dbDriver->insert($document);
85
    }
86
87
    /**
88
     *
89
     * @param mixed $collection
90
     * @return bool
91
     */
92
    public function setCollection($collection)
93
    {
94
        return $this->_dbDriver->setCollection($collection);
95
    }
96
97
    /**
98
     *
99
     * @param mixed $document
100
     * @param mixed $filter
101
     * @param mixed $options
102
     * @return bool
103
     */
104
    public function update($document, $filter = null, $options = null)
105
    {
106
        return $this->_dbDriver->update($document, $filter, $options);
107
    }
108
109
    /**
110
     * @access public
111
     * @return string
112
     */
113
    public function getDBConnection()
114
    {
115
        return $this->_dbDriver->getDbConnection();
116
    }
117
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
118
      public function setDriverAttribute($name, $value)
119
      {
120
      return $this->_dbDriver->setAttribute($name, $value);
121
      }
122
123
      public function getDriverAttribute($name)
124
      {
125
      return $this->_dbDriver->getAttribute($name);
126
      }
127
     *
128
     */
129
}
130