Issues (19)

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/Reader/DbalReader.php (4 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
namespace Ddeboer\DataImport\Reader;
3
4
use Doctrine\DBAL\Connection;
5
use Doctrine\DBAL\Statement;
6
7
/**
8
 * Reads data through the Doctrine DBAL
9
 */
10
class DbalReader implements CountableReader
11
{
12
    /**
13
     * @var Connection
14
     */
15
    private $connection;
16
17
    /**
18
     * @var array
19
     */
20
    private $data;
21
22
    /**
23
     * @var Statement
24
     */
25
    private $stmt;
26
27
    /**
28
     * @var string
29
     */
30
    private $sql;
31
32
    /**
33
     * @var array
34
     */
35
    private $params;
36
37
    /**
38
     * @var integer
39
     */
40
    private $rowCount;
41
42
    /**
43
     * @var boolean
44
     */
45
    private $rowCountCalculated = true;
46
47
    /**
48
     * @var string
49
     */
50
    private $key;
51
52
    /**
53
     * @param Connection $connection
54
     * @param string     $sql
55
     * @param array      $params
56
     */
57 11
    public function __construct(Connection $connection, $sql, array $params = [])
58
    {
59 11
        $this->connection = $connection;
60
61 11
        $this->setSql($sql, $params);
62 11
    }
63
64
    /**
65
     * Do calculate row count?
66
     *
67
     * @param boolean $calculate
68
     */
69 2
    public function setRowCountCalculated($calculate = true)
70
    {
71 2
        $this->rowCountCalculated = (bool) $calculate;
72 2
    }
73
74
    /**
75
     * Is row count calculated?
76
     *
77
     * @return boolean
78
     */
79 1
    public function isRowCountCalculated()
80
    {
81 1
        return $this->rowCountCalculated;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 3
    public function getFields()
88
    {
89 3
        if (null === $this->data) {
90 3
            $this->rewind();
91 3
        }
92 3
        if (false === $this->data) {
93 1
            return [];
94
        }
95
96 2
        return array_keys((array) $this->data);
97
    }
98
99
    /**
100
     * Set Query string with Parameters
101
     *
102
     * @param string $sql
103
     * @param array  $params
104
     */
105 11
    public function setSql($sql, array $params = [])
106
    {
107 11
        $this->sql = (string) $sql;
108
109 11
        $this->setSqlParameters($params);
110 11
    }
111
112
    /**
113
     * Set SQL parameters
114
     *
115
     * @param array $params
116
     */
117 11
    public function setSqlParameters(array $params)
118
    {
119 11
        $this->params = $params;
120
121 11
        $this->stmt = null;
122 11
        $this->rowCount = null;
123 11
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128 3
    public function current()
129
    {
130 3
        if (null === $this->data) {
131 1
            $this->rewind();
132 1
        }
133
134 3
        return $this->data;
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140 2
    public function next()
141
    {
142 2
        $this->key++;
143 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...
144 2
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149 1
    public function key()
150
    {
151 1
        return $this->key;
152
    }
153
154
    /**
155
     * {@inheritdoc}
156
     */
157 3
    public function valid()
158
    {
159 3
        if (null === $this->data) {
160 1
            $this->rewind();
161 1
        }
162
163 3
        return (false !== $this->data);
164
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169 8
    public function rewind()
170
    {
171 8
        if (null === $this->stmt) {
172 8
            $this->stmt = $this->prepare($this->sql, $this->params);
173 8
        }
174 8
        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...
175 8
            $this->stmt->execute();
176 8
            $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...
177 8
            $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...
178 8
        }
179 8
    }
180
181
    /**
182
     * {@inheritdoc}
183
     */
184 3
    public function count()
185
    {
186 3
        if (null === $this->rowCount) {
187 3
            if ($this->rowCountCalculated) {
188 2
                $this->doCalcRowCount();
189 2
            } else {
190 1
                if (null === $this->stmt) {
191 1
                    $this->rewind();
192 1
                }
193 1
                $this->rowCount = $this->stmt->rowCount();
194
            }
195 3
        }
196
197 3
        return $this->rowCount;
198
    }
199
200 2
    private function doCalcRowCount()
201
    {
202 2
        $statement = $this->prepare(sprintf('SELECT COUNT(*) FROM (%s) AS count', $this->sql), $this->params);
203 2
        $statement->execute();
204
205 2
        $this->rowCount = (int) $statement->fetchColumn(0);
206 2
    }
207
208
    /**
209
     * Prepare given statement
210
     *
211
     * @param string $sql
212
     * @param array  $params
213
     *
214
     * @return Statement
215
     */
216 9
    private function prepare($sql, array $params)
217
    {
218 9
        $statement = $this->connection->prepare($sql);
219 9
        foreach ($params as $key => $value) {
220 9
            $statement->bindValue($key, $value);
221 9
        }
222
223 9
        return $statement;
224
    }
225
}
226