Completed
Push — master ( c7757e...39cb21 )
by Luís
16s
created

lib/Doctrine/DBAL/Portability/Connection.php (1 issue)

1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\DBAL\Portability;
21
22
use Doctrine\DBAL\Cache\QueryCacheProfile;
23
24
/**
25
 * Portability wrapper for a Connection.
26
 *
27
 * @link   www.doctrine-project.org
28
 * @since  2.0
29
 * @author Benjamin Eberlei <[email protected]>
30
 */
31
class Connection extends \Doctrine\DBAL\Connection
32
{
33
    const PORTABILITY_ALL               = 255;
34
    const PORTABILITY_NONE              = 0;
35
    const PORTABILITY_RTRIM             = 1;
36
    const PORTABILITY_EMPTY_TO_NULL     = 4;
37
    const PORTABILITY_FIX_CASE          = 8;
38
39
    const PORTABILITY_DB2               = 13;
40
    const PORTABILITY_ORACLE            = 9;
41
    const PORTABILITY_POSTGRESQL        = 13;
42
    const PORTABILITY_SQLITE            = 13;
43
    const PORTABILITY_OTHERVENDORS      = 12;
44
    const PORTABILITY_DRIZZLE           = 13;
45
    const PORTABILITY_SQLANYWHERE       = 13;
46
    const PORTABILITY_SQLSRV            = 13;
47
48
    /**
49
     * @var integer
50
     */
51
    private $portability = self::PORTABILITY_NONE;
52
53
    /**
54
     * @var integer
55
     */
56
    private $case;
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 6
    public function connect()
62
    {
63 6
        $ret = parent::connect();
64 6
        if ($ret) {
65 6
            $params = $this->getParams();
66 6
            if (isset($params['portability'])) {
67 6
                if ($this->getDatabasePlatform()->getName() === "oracle") {
68
                    $params['portability'] = $params['portability'] & self::PORTABILITY_ORACLE;
69 6
                } elseif ($this->getDatabasePlatform()->getName() === "postgresql") {
70
                    $params['portability'] = $params['portability'] & self::PORTABILITY_POSTGRESQL;
71 6
                } elseif ($this->getDatabasePlatform()->getName() === "sqlite") {
72 5
                    $params['portability'] = $params['portability'] & self::PORTABILITY_SQLITE;
73 1 View Code Duplication
                } elseif ($this->getDatabasePlatform()->getName() === "drizzle") {
74
                    $params['portability'] = $params['portability'] & self::PORTABILITY_DRIZZLE;
75 1
                } elseif ($this->getDatabasePlatform()->getName() === 'sqlanywhere') {
76
                    $params['portability'] = $params['portability'] & self::PORTABILITY_SQLANYWHERE;
77 1 View Code Duplication
                } elseif ($this->getDatabasePlatform()->getName() === 'db2') {
78
                    $params['portability'] = $params['portability'] & self::PORTABILITY_DB2;
79 1
                } elseif ($this->getDatabasePlatform()->getName() === 'mssql') {
80 1
                    $params['portability'] = $params['portability'] & self::PORTABILITY_SQLSRV;
81
                } else {
82
                    $params['portability'] = $params['portability'] & self::PORTABILITY_OTHERVENDORS;
83
                }
84 6
                $this->portability = $params['portability'];
85
            }
86 6
            if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) {
87 5
                if ($this->_conn instanceof \Doctrine\DBAL\Driver\PDOConnection) {
88
                    // make use of c-level support for case handling
89 5
                    $this->_conn->setAttribute(\PDO::ATTR_CASE, $params['fetch_case']);
90
                } else {
91
                    $this->case = ($params['fetch_case'] == \PDO::CASE_LOWER) ? CASE_LOWER : CASE_UPPER;
92
                }
93
            }
94
        }
95
96 6
        return $ret;
97
    }
98
99
    /**
100
     * @return integer
101
     */
102 6
    public function getPortability()
103
    {
104 6
        return $this->portability;
105
    }
106
107
    /**
108
     * @return integer
109
     */
110 5
    public function getFetchCase()
111
    {
112 5
        return $this->case;
113
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118 2
    public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null)
119
    {
120 2
        $stmt = new Statement(parent::executeQuery($query, $params, $types, $qcp), $this);
121 2
        $stmt->setFetchMode($this->defaultFetchMode);
122
123 2
        return $stmt;
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129 2
    public function prepare($statement)
130
    {
131 2
        $stmt = new Statement(parent::prepare($statement), $this);
132 2
        $stmt->setFetchMode($this->defaultFetchMode);
133
134 2
        return $stmt;
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140 5
    public function query()
141
    {
142 5
        $this->connect();
143
144 5
        $stmt = $this->_conn->query(...func_get_args());
0 ignored issues
show
The call to Doctrine\DBAL\Driver\Connection::query() has too many arguments starting with func_get_args(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

144
        /** @scrutinizer ignore-call */ 
145
        $stmt = $this->_conn->query(...func_get_args());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
145 5
        $stmt = new Statement($stmt, $this);
146 5
        $stmt->setFetchMode($this->defaultFetchMode);
147
148 5
        return $stmt;
149
    }
150
}
151