Issues (183)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Db/Driver/Pdo.php (6 issues)

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 FMUP\Db\Driver;
4
5
use FMUP\Db\Exception;
6
use FMUP\Logger;
7
8
class Pdo extends PdoConfiguration
9
{
10
    const CHARSET_UTF8 = 'utf8';
11
12
    /**
13
     * Charset to use
14
     * @return string
15
     */
16 2
    protected function getCharset()
17
    {
18 2
        $charset = (string)$this->getSettings('charset');
19 2
        return $charset ?: self::CHARSET_UTF8;
20
    }
21
22
    /**
23
     * @param \Pdo $instance
24
     * @return $this
25
     */
26 1
    protected function defaultConfiguration(\Pdo $instance)
27
    {
28 1
        $charset = $this->getCharset();
29 1
        $instance->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
30 1
        $instance->setAttribute(\PDO::ATTR_TIMEOUT, 10.0);
31 1
        $instance->exec('SET NAMES ' . $charset);
32 1
        $instance->exec('SET CHARACTER SET ' . $charset);
33 1
        return $this;
34
    }
35
36
    /**
37
     * Fetch all rows for a given statement
38
     * @param object $statement
39
     * @return array
40
     * @throws Exception
41
     */
42 3 View Code Duplication
    public function fetchAll($statement)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44 3
        if (!$statement instanceof \PDOStatement) {
45 1
            $this->log(Logger::ERROR, 'Statement not in right format', array('statement' => $statement));
46 1
            throw new Exception('Statement not in right format');
47
        }
48
49
        try {
50 2
            return $statement->fetchAll($this->getFetchMode());
51 1
        } catch (\PDOException $e) {
52 1
            $this->log(Logger::ERROR, $e->getMessage(), array('error' => $e));
53 1
            throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
54
        }
55
    }
56
57
    /**
58
     * Begin a transaction
59
     * @return bool
60
     * @throws Exception
61
     */
62 3
    public function beginTransaction()
63
    {
64
        try {
65 3
            if ($this->getDriver()->inTransaction()) {
66 1
                $this->log(Logger::CRITICAL, 'Transaction already opened', $this->getSettings());
0 ignored issues
show
It seems like $this->getSettings() targeting FMUP\Db\Driver\PdoConfiguration::getSettings() can also be of type null; however, FMUP\Logger\LoggerTrait::log() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
67 1
                throw new Exception('Transaction already opened');
68
            }
69 1
            $this->log(Logger::DEBUG, 'Transaction start');
70 1
            return $this->getDriver()->beginTransaction();
71 2
        } catch (\PDOException $e) {
72 1
            $this->log(Logger::ERROR, $e->getMessage(), array('settings' => $this->getSettings()));
73 1
            throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
74
        }
75
    }
76
77
    /**
78
     * @return bool
79
     * @throws Exception
80
     */
81 2 View Code Duplication
    public function rollback()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
    {
83
        try {
84 2
            $this->log(Logger::DEBUG, 'Transaction rollback');
85 2
            return $this->getDriver()->rollBack();
86 1
        } catch (\PDOException $e) {
87 1
            $this->log(Logger::ERROR, $e->getMessage(), array('error' => $e));
88 1
            throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
89
        }
90
    }
91
92
    /**
93
     * @return mixed
94
     * @throws Exception
95
     */
96 2
    public function errorCode()
97
    {
98
        try {
99 2
            return $this->getDriver()->errorCode();
100 1
        } catch (\PDOException $e) {
101 1
            $this->log(Logger::ERROR, $e->getMessage(), array('error' => $e));
102 1
            throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
103
        }
104
    }
105
106
    /**
107
     * @return array
108
     * @throws Exception
109
     */
110 2
    public function errorInfo()
111
    {
112
        try {
113 2
            return $this->getDriver()->errorInfo();
114 1
        } catch (\PDOException $e) {
115 1
            $this->log(Logger::ERROR, $e->getMessage(), array('error' => $e));
116 1
            throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
117
        }
118
    }
119
120
    /**
121
     * @return bool
122
     * @throws Exception
123
     */
124 2 View Code Duplication
    public function commit()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
    {
126
        try {
127 2
            $this->log(Logger::DEBUG, 'Transaction commit');
128 2
            return $this->getDriver()->commit();
129 1
        } catch (\PDOException $e) {
130 1
            $this->log(Logger::ERROR, $e->getMessage(), array('error' => $e));
131 1
            throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
132
        }
133
    }
134
135
    /**
136
     * Execute a statement for given values
137
     * @param object $statement
138
     * @param array $values
139
     * @return bool
140
     * @throws Exception
141
     */
142 3
    public function execute($statement, $values = array())
143
    {
144 3
        if (!$statement instanceof \PDOStatement) {
145 1
            $this->log(Logger::ERROR, 'Statement not in right format', array('statement' => $statement));
146 1
            throw new Exception('Statement not in right format');
147
        }
148
149
        try {
150 2
            $this->log(Logger::DEBUG, 'Executing query', array('values' => $values));
151 2
            return $statement->execute($values);
152 1
        } catch (\PDOException $e) {
153 1
            $this->log(Logger::ERROR, $e->getMessage(), array('exception' => $e, 'values' => $values));
154 1
            throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
155
        }
156
    }
157
158
    /**
159
     * Prepare a SQL string to a statement
160
     * @param string $sql
161
     * @param array $options
162
     * @return \PDOStatement
163
     * @throws Exception
164
     */
165 3
    public function prepare($sql, array $options = array())
166
    {
167
        try {
168 3
            $this->log(Logger::DEBUG, 'Preparing query', array('sql' => $sql, 'options' => $options));
169 3
            return $this->getDriver()->prepare($sql, $options);
170 1
        } catch (\PDOException $e) {
171 1
            $this->log(Logger::ERROR, $e->getMessage(), array('exception' => $e, 'sql' => $sql));
172 1
            throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
173
        }
174
    }
175
176
    /**
177
     * Retrieve id inserted
178
     * @param string $name optional
179
     * @return string
180
     * @throws Exception
181
     */
182 2 View Code Duplication
    public function lastInsertId($name = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
183
    {
184
        try {
185 2
            return $this->getDriver()->lastInsertId($name);
186 1
        } catch (\PDOException $e) {
187 1
            $this->log(Logger::ERROR, $e->getMessage(), array('error' => $e));
188 1
            throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
189
        }
190
    }
191
192
    /**
193
     * Retrieve number of affected rows of a statement
194
     * @param mixed $statement
195
     * @return int
196
     * @throws Exception
197
     */
198 3 View Code Duplication
    public function count($statement)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
199
    {
200 3
        if (!$statement instanceof \PDOStatement) {
201 1
            $this->log(Logger::ERROR, 'Statement not in right format', array('statement' => $statement));
202 1
            throw new Exception('Statement not in right format');
203
        }
204
205
        try {
206 2
            return $statement->rowCount();
207 1
        } catch (\PDOException $e) {
208 1
            $this->log(Logger::ERROR, $e->getMessage(), array('error' => $e));
209 1
            throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
210
        }
211
    }
212
}
213