Issues (8)

Security Analysis    no request data  

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/DbalReader.php (7 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 Port\Dbal;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Statement;
7
use Port\Reader\CountableReader;
8
9
/**
10
 * Reads data through the Doctrine DBAL
11
 */
12
class DbalReader implements CountableReader
13
{
14
    /**
15
     * @var Connection
16
     */
17
    private $connection;
18
19
    /**
20
     * @var array
21
     */
22
    private $data;
23
24
    /**
25
     * @var Statement
26
     */
27
    private $stmt;
28
29
    /**
30
     * @var string
31
     */
32
    private $sql;
33
34
    /**
35
     * @var array
36
     */
37
    private $params;
38
39
    /**
40
     * @var integer
41
     */
42
    private $rowCount;
43
44
    /**
45
     * @var boolean
46
     */
47
    private $rowCountCalculated = true;
48
49
    /**
50
     * @var string
51
     */
52
    private $key;
53
54
    /**
55
     * @param Connection $connection
56
     * @param string     $sql
57
     * @param array      $params
58
     */
59 10
    public function __construct(Connection $connection, $sql, array $params = [])
60
    {
61 10
        $this->connection = $connection;
62
63 10
        $this->setSql($sql, $params);
64 10
    }
65
66
    /**
67
     * Do calculate row count?
68
     *
69
     * @param boolean $calculate
70
     */
71 2
    public function setRowCountCalculated($calculate = true)
72
    {
73 2
        $this->rowCountCalculated = (bool) $calculate;
74 2
    }
75
76
    /**
77
     * Is row count calculated?
78
     *
79
     * @return boolean
80
     */
81 1
    public function isRowCountCalculated()
82
    {
83 1
        return $this->rowCountCalculated;
84
    }
85
86
    /**
87
     * Set Query string with Parameters
88
     *
89
     * @param string $sql
90
     * @param array  $params
91
     */
92 10
    public function setSql($sql, array $params = [])
93
    {
94 10
        $this->sql = (string) $sql;
95
96 10
        $this->setSqlParameters($params);
97 10
    }
98
99
    /**
100
     * Set SQL parameters
101
     *
102
     * @param array $params
103
     */
104 10
    public function setSqlParameters(array $params)
105
    {
106 10
        $this->params = $params;
107
108 10
        $this->stmt = null;
109 10
        $this->rowCount = null;
110 10
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115 5
    public function current()
116
    {
117 5
        if (null === $this->data) {
118 3
            $this->rewind();
119 3
        }
120
121 5
        return $this->data;
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127 2
    public function next()
128
    {
129 2
        $this->key++;
130 2
        $this->data = $this->stmt->fetch(\PDO::FETCH_ASSOC);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->stmt->fetch(\PDO::FETCH_ASSOC) of type * is incompatible with the declared type array of property $data.

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...
Deprecated Code introduced by
The method Doctrine\DBAL\Statement::fetch() has been deprecated with message: Use fetchNumeric(), fetchAssociative() or fetchOne() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
131 2
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136 1
    public function key()
137
    {
138 1
        return $this->key;
139
    }
140
141
    /**
142
     * {@inheritdoc}
143
     */
144 3
    public function valid()
145
    {
146 3
        if (null === $this->data) {
147 1
            $this->rewind();
148 1
        }
149
150 3
        return (false !== $this->data);
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156 7
    public function rewind()
157
    {
158 7
        if (null === $this->stmt) {
159 7
            $this->stmt = $this->prepare($this->sql, $this->params);
160 7
        }
161 7
        if (0 !== $this->key) {
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison !== seems to always evaluate to true as the types of 0 (integer) and $this->key (string) can never be identical. Maybe you want to use a loose comparison != instead?
Loading history...
162 7
            $this->stmt->execute();
163 7
            $this->data = $this->stmt->fetch(\PDO::FETCH_ASSOC);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->stmt->fetch(\PDO::FETCH_ASSOC) of type * is incompatible with the declared type array of property $data.

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...
Deprecated Code introduced by
The method Doctrine\DBAL\Statement::fetch() has been deprecated with message: Use fetchNumeric(), fetchAssociative() or fetchOne() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
164 7
            $this->key = 0;
0 ignored issues
show
Documentation Bug introduced by
The property $key was declared of type string, but 0 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
165 7
        }
166 7
    }
167
168
    /**
169
     * {@inheritdoc}
170
     */
171 3
    public function count()
172
    {
173 3
        if (null === $this->rowCount) {
174 3
            if ($this->rowCountCalculated) {
175 2
                $this->doCalcRowCount();
176 2
            } else {
177 1
                if (null === $this->stmt) {
178 1
                    $this->rewind();
179 1
                }
180 1
                $this->rowCount = $this->stmt->rowCount();
181
            }
182 3
        }
183
184 3
        return $this->rowCount;
185
    }
186
187 2
    private function doCalcRowCount()
188
    {
189 2
        $statement = $this->prepare(sprintf('SELECT COUNT(*) FROM (%s) AS port_cnt', $this->sql), $this->params);
190 2
        $statement->execute();
191
192 2
        $this->rowCount = (int) $statement->fetchColumn(0);
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\DBAL\Statement::fetchColumn() has been deprecated with message: Use fetchOne() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
193 2
    }
194
195
    /**
196
     * Prepare given statement
197
     *
198
     * @param string $sql
199
     * @param array  $params
200
     *
201
     * @return Statement
202
     */
203 8
    private function prepare($sql, array $params)
204
    {
205 8
        $statement = $this->connection->prepare($sql);
206 8
        foreach ($params as $key => $value) {
207 8
            $statement->bindValue($key, $value);
208 8
        }
209
210 8
        return $statement;
211
    }
212
}
213