Issues (4)

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.

Source/Query.php (1 issue)

Severity

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
 * @author Rémy M. Böhler <[email protected]>
4
 */
5
namespace Rorm;
6
7
use PDO;
8
9
/**
10
 * Class Query
11
 */
12
class Query
13
{
14
    /** @var PDO */
15
    protected $dbh;
16
17
    /** @var string */
18
    protected $class;
19
20
    /** @var bool */
21
    protected $classIsOrmModel;
22
23
    /** @var string */
24
    protected $query;
25
26
    /** @var array */
27
    protected $params;
28
29
    /** @var \PDOStatement */
30
    protected $statement;
31
32
    /**
33
     * @param string $class
34
     * @param PDO|null $dbh if null the default database connection is used
35
     */
36 31
    public function __construct($class = 'stdClass', PDO $dbh = null)
37
    {
38 31
        $this->class = $class;
39 31
        $this->classIsOrmModel = is_subclass_of($this->class, '\\Rorm\\Model');
40 31
        $this->dbh = $dbh ? $dbh : Rorm::getDatabase();
41 31
    }
42
43
    /**
44
     * @return string
45
     */
46 3
    public function getClass()
47
    {
48 3
        return $this->class;
49
    }
50
51
    /**
52
     * @param string $query
53
     */
54 4
    public function setQuery($query)
55
    {
56 4
        $this->query = $query;
57 4
    }
58
59
    /**
60
     * @return string
61
     */
62 9
    public function getQuery()
63
    {
64 9
        return $this->query;
65
    }
66
67
    /**
68
     * @param array $params
69
     */
70 2
    public function setParams(array $params)
71
    {
72 2
        $this->params = $params;
73 2
    }
74
75
    /**
76
     * @return array
77
     */
78 4
    public function getParams()
79
    {
80 4
        return $this->params;
81
    }
82
83
    /**
84
     * @return bool
85
     *
86
     * @todo probably we can unset query an params to free up memory
0 ignored issues
show
Comment refers to a TODO task

This check looks TODO comments that have been left in the code.

``TODO``s show that something is left unfinished and should be attended to.

Loading history...
87
     */
88 12
    protected function execute()
89
    {
90 12
        $this->statement = $this->dbh->prepare($this->query);
91
        // set fetchMode to assoc, it is easier to copy data from an array than an object
92 12
        $this->statement->setFetchMode(PDO::FETCH_ASSOC);
93 12
        return $this->statement->execute($this->params);
94
    }
95
96
    /**
97
     * @return object|null
98
     */
99 8
    public function fetch()
100
    {
101 8
        $data = $this->statement->fetch();
102 8
        if ($data !== false) {
103 7
            return $this->instanceFromObject($data);
104
        }
105 3
        return null;
106
    }
107
108
    /**
109
     * @param array $data
110
     * @return object
111
     */
112 11
    public function instanceFromObject(array $data)
113
    {
114 11
        $instance = new $this->class;
115 11
        if ($this->classIsOrmModel) {
116
            /** @var \Rorm\Model $instance */
117 10
            $instance->setData($data);
118 10
        } else {
119 1
            foreach ($data as $key => $value) {
120 1
                $instance->$key = $value;
121 1
            }
122
        }
123
124 11
        return $instance;
125
    }
126
127
    /**
128
     * @return string|null
129
     */
130 3
    public function findColumn()
131
    {
132 3
        if ($this->execute()) {
133 3
            return $this->statement->fetchColumn();
134
        }
135
        return null;
136
    }
137
138
    /**
139
     * Return one object
140
     *
141
     * @return object|null
142
     */
143 9
    public function findOne()
144
    {
145
        // DO NOT use rowCount to check if something was found because not all drivers support it
146 9
        if ($this->execute()) {
147 8
            return $this->fetch();
148
        }
149
        return null;
150
    }
151
152
    /**
153
     * Return a iterator to iterate over which returns one object at a time
154
     * the objects are lazy loaded and not kept on memory
155
     *
156
     * because the results are not buffered you can only iterate once over it!
157
     * If you need to iterate multiple times over the result you should use the findAll method
158
     *
159
     * Note for PHP 5.5
160
     * yield could be used
161
     *
162
     * @return QueryIterator
163
     */
164 5
    public function findMany()
165
    {
166 5
        $this->execute();
167 5
        return new QueryIterator($this->statement, $this);
168
        // PHP 5.5 yield version for future use
169
        /*while ($object = $this->statement->fetchObject()) {
170
            yield $this->instanceFromObject($object);
171
        }*/
172
    }
173
174
    /**
175
     * Return an array with all objects, this can lead to heavy memory consumption
176
     *
177
     * @return array
178
     */
179 3
    public function findAll()
180
    {
181 3
        $result = array();
182
183 3
        foreach ($this->findMany() as $object) {
184 3
            $result[] = $object;
185 3
        }
186
187 3
        return $result;
188
    }
189
190
    /**
191
     * This operation is very expensive.
192
     *
193
     * PDOStatement::rowCount does not work on all drivers!
194
     *
195
     * @return int
196
     */
197 1
    public function count()
198
    {
199 1
        return count($this->findAll());
200
    }
201
}
202