Issues (1507)

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.

PHPDaemon/Clients/Mongo/Collection.php (32 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 PHPDaemon\Clients\Mongo;
3
4
/**
5
 * @package    Applications
6
 * @subpackage MongoClientAsync
7
 * @author     Vasily Zorin <[email protected]>
8
 */
9
class Collection
10
{
11
    use \PHPDaemon\Traits\ClassWatchdog;
12
    use \PHPDaemon\Traits\StaticObjectWatchdog;
13
14
    /**
15
     * @var Pool Related Pool object
16
     */
17
    public $pool;
18
19
    /**
20
     * @var string Name of collection
21
     */
22
    public $name;
23
24
    /**
25
     * Contructor of MongoClientAsyncCollection
26
     * @param  string $name Name of collection
27
     * @param  Pool $pool Pool
28
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
29
     */
30
    public function __construct($name, $pool)
31
    {
32
        $this->name = $name;
33
        $this->pool = $pool;
34
    }
35
36
    /**
37
     * Finds objects in collection
38
     * @param  callable $cb Callback called when response received
39
     * @param  array $p Hash of properties (offset, limit, opts, tailable, where, col, fields, sort, hint, explain, snapshot, orderby, parse_oplog)
40
     * @callback $cb ( )
41
     * @return void
42
     */
43
    public function find($cb, $p = [])
44
    {
45
        $p['col'] = $this->name;
46
        $this->pool->find($p, $cb);
47
    }
48
49
    /**
50
     * Finds objects in collection and fires callback when got all objects
51
     * @param  callable $cb Callback called when response received
52
     * @param  array $p Hash of properties (offset, limit, opts, tailable, where, col, fields, sort, hint, explain, snapshot, orderby, parse_oplog)
53
     * @callback $cb ( )
54
     * @return void
55
     */
56
    public function findAll($cb, $p = [])
57
    {
58
        $p['col'] = $this->name;
59
        $this->pool->findAll($p, $cb);
60
    }
61
62
    /**
63
     * Finds one object in collection
64
     * @param  callable $cb Callback called when response received
65
     * @param  array $p Hash of properties (offset,  opts, where, col, fields, sort, hint, explain, snapshot, orderby, parse_oplog)
66
     * @callback $cb ( )
67
     * @return void
68
     */
69
    public function findOne($cb, $p = [])
70
    {
71
        $p['col'] = $this->name;
72
        $this->pool->findOne($p, $cb);
73
    }
74
75
    /**
76
     * Counts objects in collection
77
     * @param  callable $cb Callback called when response received
78
     * @param  array $p Hash of properties (offset, limit, opts, where, col)
79
     * @callback $cb ( )
80
     * @return void
81
     */
82
    public function count($cb, $p = [])
83
    {
84
        $p['col'] = $this->name;
85
        $this->pool->findCount($p, $cb);
86
    }
87
88
    /**
89
     * Ensure index
90
     * @param  array $keys Keys
91
     * @param  array $options Optional. Options
92
     * @param  callable $cb Optional. Callback called when response received
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
93
     * @callback $cb ( )
94
     * @return void
95
     */
96
    public function ensureIndex($keys, $options = [], $cb = null)
97
    {
98
        $this->pool->ensureIndex($this->name, $keys, $options, $cb);
99
    }
100
101
    /**
102
     * Groupping function
103
     * @param  callable $cb Callback called when response received
104
     * @param  array $p Hash of properties (offset, limit, opts, key, col, reduce, initial)
105
     * @callback $cb ( )
106
     * @return void
107
     */
108
    public function group($cb, $p = [])
109
    {
110
        $p['col'] = $this->name;
111
        $this->pool->group($p, $cb);
112
    }
113
114
    /**
115
     * Inserts an object
116
     * @param  array $doc Data
117
     * @param  callable $cb Optional. Callback called when response received
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
118
     * @param  array $params Optional. Params
0 ignored issues
show
Should the type for parameter $params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
119
     * @callback $cb ( )
120
     * @return MongoId
121
     */
122
    public function insert($doc, $cb = null, $params = null)
123
    {
124
        return $this->pool->insert($this->name, $doc, $cb, $params);
0 ignored issues
show
It seems like $params defined by parameter $params on line 122 can also be of type null; however, PHPDaemon\Clients\Mongo\Pool::insert() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
125
    }
126
127
    /**
128
     * Inserts an object
129
     * @param  array $doc Data
130
     * @param  callable $cb Optional. Callback called when response received
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
131
     * @param  array $params Optional. Params
0 ignored issues
show
Should the type for parameter $params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
132
     * @callback $cb ( )
133
     * @return MongoId
134
     */
135
    public function insertOne($doc, $cb = null, $params = null)
136
    {
137
        return $this->pool->insert($this->name, $doc, $cb, $params);
0 ignored issues
show
It seems like $params defined by parameter $params on line 135 can also be of type null; however, PHPDaemon\Clients\Mongo\Pool::insert() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
138
    }
139
140
    /**
141
     * Inserts several documents
142
     * @param  array $docs Array of docs
143
     * @param  callable $cb Optional. Callback called when response received.
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
144
     * @param  array $params Optional. Params
0 ignored issues
show
Should the type for parameter $params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
145
     * @callback $cb ( )
146
     * @return array    IDs
147
     */
148
    public function insertMulti($docs, $cb = null, $params = null)
149
    {
150
        return $this->pool->insertMulti($this->name, $docs, $cb, $params);
0 ignored issues
show
It seems like $params defined by parameter $params on line 148 can also be of type null; however, PHPDaemon\Clients\Mongo\Pool::insertMulti() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
151
    }
152
153
    /**
154
     * Updates one object in collection
155
     * @param  array $cond Conditions
156
     * @param  array $data Data
157
     * @param  integer $flags Optional. Flags
158
     * @param  callable $cb Optional. Callback called when response received
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
159
     * @param  array $params Optional. Params
0 ignored issues
show
Should the type for parameter $params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
160
     * @callback $cb ( )
161
     * @return void
162
     */
163
    public function update($cond, $data, $flags = 0, $cb = null, $params = null)
164
    {
165
        $this->pool->update($this->name, $cond, $data, $flags, $cb, $params);
0 ignored issues
show
It seems like $params defined by parameter $params on line 163 can also be of type null; however, PHPDaemon\Clients\Mongo\Pool::update() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
166
    }
167
168
169
    /**
170
     * Updates one object in collection
171
     * @param  array $cond Conditions
172
     * @param  array $data Data
173
     * @param  callable $cb Optional. Callback called when response received
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
174
     * @param  array $params Optional. Params
0 ignored issues
show
Should the type for parameter $params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
175
     * @callback $cb ( )
176
     * @return void
177
     */
178
    public function updateOne($cond, $data, $cb = null, $params = null)
179
    {
180
        $this->pool->updateOne($this->name, $cond, $data, $cb, $params);
0 ignored issues
show
It seems like $params defined by parameter $params on line 178 can also be of type null; however, PHPDaemon\Clients\Mongo\Pool::updateOne() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
181
    }
182
183
    /**
184
     * Updates one object in collection
185
     * @param  array $cond Conditions
186
     * @param  array $data Data
187
     * @param  callable $cb Optional. Callback called when response received
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
188
     * @param  array $params Optional. Params
0 ignored issues
show
Should the type for parameter $params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
189
     * @callback $cb ( )
190
     * @return void
191
     */
192
    public function updateMulti($cond, $data, $cb = null, $params = null)
193
    {
194
        $this->pool->updateMulti($this->name, $cond, $data, $cb, $params);
0 ignored issues
show
It seems like $params defined by parameter $params on line 192 can also be of type null; however, PHPDaemon\Clients\Mongo\Pool::updateMulti() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
195
    }
196
197
    /**
198
     * Upserts an object (updates if exists, insert if not exists)
199
     * @param  array $cond Conditions
200
     * @param  array $data Data
201
     * @param  boolean $multi Optional. Multi-flag
202
     * @param  callable $cb Optional. Callback called when response received
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
203
     * @param  array $params Optional. Params
0 ignored issues
show
Should the type for parameter $params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
204
     * @callback $cb ( )
205
     * @return void
206
     */
207
    public function upsert($cond, $data, $multi = false, $cb = null, $params = null)
208
    {
209
        $this->pool->upsert($this->name, $cond, $data, $multi, $cb, $params);
0 ignored issues
show
It seems like $params defined by parameter $params on line 207 can also be of type null; however, PHPDaemon\Clients\Mongo\Pool::upsert() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
210
    }
211
212
    /**
213
     * Upserts an object (updates if exists, insert if not exists)
214
     * @param  array $cond Conditions
215
     * @param  array $data Data
216
     * @param  callable $cb Optional. Callback called when response received
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
217
     * @param  array $params Optional. Params
0 ignored issues
show
Should the type for parameter $params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
218
     * @callback $cb ( )
219
     * @return void
220
     */
221
    public function upsertOne($cond, $data, $cb = null, $params = null)
222
    {
223
        $this->pool->upsertOne($this->name, $cond, $data, $cb, $params);
0 ignored issues
show
It seems like $params defined by parameter $params on line 221 can also be of type null; however, PHPDaemon\Clients\Mongo\Pool::upsertOne() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
224
    }
225
226
    /**
227
     * Upserts an object (updates if exists, insert if not exists)
228
     * @param  array $cond Conditions
229
     * @param  array $data Data
230
     * @param  callable $cb Optional. Callback called when response received
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
231
     * @param  array $params Optional. Params
0 ignored issues
show
Should the type for parameter $params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
232
     * @callback $cb ( )
233
     * @return void
234
     */
235
    public function upsertMulti($cond, $data, $cb = null, $params = null)
236
    {
237
        $this->pool->upsertMulti($this->name, $cond, $data, $cb, $params);
0 ignored issues
show
It seems like $params defined by parameter $params on line 235 can also be of type null; however, PHPDaemon\Clients\Mongo\Pool::upsertMulti() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
238
    }
239
240
    /**
241
     * Removes objects from collection
242
     * @param  array $cond Conditions
243
     * @param  callable $cb Optional. Callback called when response received
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
244
     * @param  array $params Optional. Params
0 ignored issues
show
Should the type for parameter $params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
245
     * @callback $cb ( )
246
     * @return void
247
     */
248
    public function remove($cond = [], $cb = null, $params = null)
0 ignored issues
show
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
249
    {
250
        $this->pool->remove($this->name, $cond, $cb);
251
    }
252
253
    /**
254
     * Evaluates a code on the server side
255
     * @param  string $code Code
256
     * @param  callable $cb Callback called when response received
257
     * @callback $cb ( )
258
     * @return void
259
     */
260
    public function evaluate($code, $cb)
261
    {
262
        $this->pool->evaluate($code, $cb);
263
    }
264
265
266
    /**
267
     * Aggregate
268
     * @param  array $p Params
269
     * @param  callable $cb Callback called when response received
270
     * @callback $cb ( )
271
     * @return void
272
     */
273
    public function aggregate($p, $cb)
274
    {
275
        $p['col'] = $this->name;
276
        $this->pool->aggregate($p, $cb);
277
    }
278
279
    /**
280
     * Generation autoincrement
281
     * @param  callable $cb Called when response received
282
     * @param  boolean $plain Plain?
283
     * @callback $cb ( )
284
     * @return void
285
     */
286
    public function autoincrement($cb, $plain = false)
287
    {
288
        $e = explode('.', $this->name);
289
        $col = (isset($e[1]) ? $e[0] . '.' : '') . 'autoincrement';
290
        $this->pool->{$col}->findAndModify([
291
            'query' => ['_id' => isset($e[1]) ? $e[1] : $e[0]],
292
            'update' => ['$inc' => ['seq' => 1]],
293
            'new' => true,
294
            'upsert' => true,
295
        ], $plain ? function ($lastError) use ($cb) {
296
            $cb(isset($lastError['value']['seq']) ? $lastError['value']['seq'] : false);
297
        } : $cb);
298
    }
299
300
    /**
301
     * Generation autoincrement
302
     * @param  array $p Params
303
     * @param  callable $cb Callback called when response received
304
     * @callback $cb ( )
305
     * @return void
306
     */
307
    public function findAndModify($p, $cb)
308
    {
309
        $p['col'] = $this->name;
310
        $this->pool->findAndModify($p, $cb);
311
    }
312
}
313