Completed
Pull Request — master (#10)
by Andreas
02:41
created

MongoCollection::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 */
15
16
use Alcaeus\MongoDbAdapter\TypeConverter;
17
18
/**
19
 * Represents a database collection.
20
 * @link http://www.php.net/manual/en/class.mongocollection.php
21
 */
22
class MongoCollection
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
23
{
24
    const ASCENDING = 1;
25
    const DESCENDING = -1;
26
27
    /**
28
     * @var MongoDB
29
     */
30
    public $db = NULL;
31
32
    /**
33
     * @var string
34
     */
35
    protected $name;
36
37
    /**
38
     * @var \MongoDB\Collection
39
     */
40
    protected $collection;
41
42
    /**
43
     * @var int<p>
44
     */
45
    public $w;
46
47
    /**
48
     * @var int <p>
49
     */
50
    public $wtimeout;
51
52
    /**
53
     * Creates a new collection
54
     * @link http://www.php.net/manual/en/mongocollection.construct.php
55
     * @param MongoDB $db Parent database.
56
     * @param string $name Name for this collection.
57
     * @throws Exception
58
     * @return MongoCollection
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...
59
     */
60
    public function __construct(MongoDB $db, $name)
61
    {
62
        $this->db = $db;
63
        $this->name = $name;
64
        $this->collection = $this->db->getDb()->selectCollection($name);
65
    }
66
67
    /**
68
     * Gets the underlying collection for this object
69
     *
70
     * @internal This part is not of the ext-mongo API and should not be used
71
     * @return \MongoDB\Collection
72
     */
73
    public function getCollection()
74
    {
75
        return $this->collection;
76
    }
77
78
    /**
79
     * String representation of this collection
80
     * @link http://www.php.net/manual/en/mongocollection.--tostring.php
81
     * @return string Returns the full name of this collection.
82
     */
83
    public function __toString()
84
    {
85
        return (string) $this->db . '.' . $this->name;
86
    }
87
88
    /**
89
     * Gets a collection
90
     * @link http://www.php.net/manual/en/mongocollection.get.php
91
     * @param string $name The next string in the collection name.
92
     * @return MongoCollection
93
     */
94
    public function __get($name)
95
    {
96
        return $this->db->selectCollection($this->name . '.' . $name);
97
    }
98
99
    /**
100
     * @link http://www.php.net/manual/en/mongocollection.aggregate.php
101
     * @param array $pipeline
102
     * @param array $op
103
     * @param array $pipelineOperators
0 ignored issues
show
Documentation introduced by
There is no parameter named $pipelineOperators. Did you maybe mean $pipeline?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
104
     * @return array
105
     */
106
    public function aggregate(array $pipeline, array $op = [] /* , array $pipelineOperators, ... */)
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
107
    {
108
        if (! TypeConverter::isNumericArray($pipeline)) {
109
            $pipeline = [];
110
            $options = [];
111
112
            $i = 0;
113
            foreach (func_get_args() as $operator) {
114
                $i++;
115
                if (! is_array($operator)) {
116
                    trigger_error("Argument $i is not an array", E_WARNING);
117
                    return;
118
                }
119
120
                $pipeline[] = $operator;
121
            }
122
        } else {
123
            $options = $op;
124
        }
125
126
        $command = [
127
            'aggregate' => $this->name,
128
            'pipeline' => $pipeline
129
        ];
130
131
        $command += $options;
132
133
        return $this->db->command($command, [], $hash);
134
    }
135
136
    /**
137
     * @link http://php.net/manual/en/mongocollection.aggregatecursor.php
138
     * @param array $pipeline
139
     * @param array $options
140
     * @return MongoCommandCursor
141
     */
142
    public function aggregateCursor(array $pipeline, array $options = [])
143
    {
144
        // Build command manually, can't use mongo-php-library here
145
        $command = [
146
            'aggregate' => $this->name,
147
            'pipeline' => $pipeline
148
        ];
149
150
        // Convert cursor option
151
        if (! isset($options['cursor']) || $options['cursor'] === true || $options['cursor'] === []) {
152
            // Cursor option needs to be an object convert bools and empty arrays since those won't be handled by TypeConverter
153
            $options['cursor'] = new \stdClass;
154
        }
155
156
        $command += $options;
157
158
        return new MongoCommandCursor($this->db->getConnection(), (string) $this, $command);
159
    }
160
161
    /**
162
     * Returns this collection's name
163
     * @link http://www.php.net/manual/en/mongocollection.getname.php
164
     * @return string
165
     */
166
    public function getName()
167
    {
168
        return $this->name;
169
    }
170
171
    /**
172
     * @link http://www.php.net/manual/en/mongocollection.getslaveokay.php
173
     * @return bool
174
     */
175
    public function getSlaveOkay()
176
    {
177
        $this->notImplemented();
178
    }
179
180
    /**
181
     * @link http://www.php.net/manual/en/mongocollection.setslaveokay.php
182
     * @param bool $ok
183
     * @return bool
184
     */
185
    public function setSlaveOkay($ok = true)
0 ignored issues
show
Unused Code introduced by
The parameter $ok 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...
186
    {
187
        $this->notImplemented();
188
    }
189
190
    /**
191
     * @link http://www.php.net/manual/en/mongocollection.getreadpreference.php
192
     * @return array
193
     */
194
    public function getReadPreference()
195
    {
196
        $this->notImplemented();
197
    }
198
199
    /**
200
     * @param string $read_preference
201
     * @param array $tags
202
     * @return bool
203
     */
204
    public function setReadPreference($read_preference, array $tags)
0 ignored issues
show
Unused Code introduced by
The parameter $read_preference 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...
Unused Code introduced by
The parameter $tags 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...
205
    {
206
        $this->notImplemented();
207
    }
208
209
    /**
210
     * Drops this collection
211
     * @link http://www.php.net/manual/en/mongocollection.drop.php
212
     * @return array Returns the database response.
213
     */
214
    public function drop()
215
    {
216
        return $this->collection->drop();
217
    }
218
219
    /**
220
     * Validates this collection
221
     * @link http://www.php.net/manual/en/mongocollection.validate.php
222
     * @param bool $scan_data Only validate indices, not the base collection.
223
     * @return array Returns the database's evaluation of this object.
224
     */
225
    public function validate($scan_data = FALSE)
0 ignored issues
show
Unused Code introduced by
The parameter $scan_data 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...
226
    {
227
        $this->notImplemented();
228
    }
229
230
    /**
231
     * Inserts an array into the collection
232
     * @link http://www.php.net/manual/en/mongocollection.insert.php
233
     * @param array|object $a
234
     * @param array $options
235
     * @throws MongoException if the inserted document is empty or if it contains zero-length keys. Attempting to insert an object with protected and private properties will cause a zero-length key error.
236
     * @throws MongoCursorException if the "w" option is set and the write fails.
237
     * @throws MongoCursorTimeoutException if the "w" option is set to a value greater than one and the operation takes longer than MongoCursor::$timeout milliseconds to complete. This does not kill the operation on the server, it is a client-side timeout. The operation in MongoCollection::$wtimeout is milliseconds.
238
     * @return bool|array Returns an array containing the status of the insertion if the "w" option is set.
239
     */
240
    public function insert($a, array $options = array())
241
    {
242
        return $this->collection->insertOne(TypeConverter::convertLegacyArrayToObject($a), $options);
243
    }
244
245
    /**
246
     * Inserts multiple documents into this collection
247
     * @link http://www.php.net/manual/en/mongocollection.batchinsert.php
248
     * @param array $a An array of arrays.
249
     * @param array $options Options for the inserts.
250
     * @throws MongoCursorException
251
     * @return mixed f "safe" is set, returns an associative array with the status of the inserts ("ok") and any error that may have occured ("err"). Otherwise, returns TRUE if the batch insert was successfully sent, FALSE otherwise.
252
     */
253
    public function batchInsert(array $a, array $options = array())
254
    {
255
        return $this->collection->insertMany($a, $options);
256
    }
257
258
    /**
259
     * Update records based on a given criteria
260
     * @link http://www.php.net/manual/en/mongocollection.update.php
261
     * @param array $criteria Description of the objects to update.
262
     * @param array $newobj The object with which to update the matching records.
263
     * @param array $options This parameter is an associative array of the form
264
     *        array("optionname" => boolean, ...).
265
     *
266
     *        Currently supported options are:
267
     *          "upsert": If no document matches $$criteria, a new document will be created from $$criteria and $$new_object (see upsert example).
268
     *
269
     *          "multiple": All documents matching $criteria will be updated. MongoCollection::update has exactly the opposite behavior of MongoCollection::remove- it updates one document by
270
     *          default, not all matching documents. It is recommended that you always specify whether you want to update multiple documents or a single document, as the
271
     *          database may change its default behavior at some point in the future.
272
     *
273
     *          "safe" Can be a boolean or integer, defaults to false. If false, the program continues executing without waiting for a database response. If true, the program will wait for
274
     *          the database response and throw a MongoCursorException if the update did not succeed. If you are using replication and the master has changed, using "safe" will make the driver
275
     *          disconnect from the master, throw and exception, and attempt to find a new master on the next operation (your application must decide whether or not to retry the operation on the new master).
276
     *          If you do not use "safe" with a replica set and the master changes, there will be no way for the driver to know about the change so it will continuously and silently fail to write.
277
     *          If safe is an integer, will replicate the update to that many machines before returning success (or throw an exception if the replication times out, see wtimeout).
278
     *          This overrides the w variable set on the collection.
279
     *
280
     *         "fsync": Boolean, defaults to false. Forces the update to be synced to disk before returning success. If true, a safe update is implied and will override setting safe to false.
281
     *
282
     *         "timeout" Integer, defaults to MongoCursor::$timeout. If "safe" is set, this sets how long (in milliseconds) for the client to wait for a database response. If the database does
283
     *         not respond within the timeout period, a MongoCursorTimeoutException will be thrown
284
     * @throws MongoCursorException
285
     * @return boolean
286
     */
287
    public function update(array $criteria , array $newobj, array $options = array())
288
    {
289
        $multiple = ($options['multiple']) ? $options['multiple'] : false;
290
//        $multiple = $options['multiple'] ?? false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
291
        $method = $multiple ? 'updateMany' : 'updateOne';
292
293
        return $this->collection->$method($criteria, $newobj, $options);
294
    }
295
296
    /**
297
     * (PECL mongo &gt;= 0.9.0)<br/>
298
     * Remove records from this collection
299
     * @link http://www.php.net/manual/en/mongocollection.remove.php
300
     * @param array $criteria [optional] <p>Query criteria for the documents to delete.</p>
301
     * @param array $options [optional] <p>An array of options for the remove operation. Currently available options
302
     * include:
303
     * </p><ul>
304
     * <li><p><em>"w"</em></p><p>See {@link http://www.php.net/manual/en/mongo.writeconcerns.php Write Concerns}. The default value for <b>MongoClient</b> is <em>1</em>.</p></li>
305
     * <li>
306
     * <p>
307
     * <em>"justOne"</em>
308
     * </p>
309
     * <p>
310
     * Specify <strong><code>TRUE</code></strong> to limit deletion to just one document. If <strong><code>FALSE</code></strong> or
311
     * omitted, all documents matching the criteria will be deleted.
312
     * </p>
313
     * </li>
314
     * <li><p><em>"fsync"</em></p><p>Boolean, defaults to <b>FALSE</b>. If journaling is enabled, it works exactly like <em>"j"</em>. If journaling is not enabled, the write operation blocks until it is synced to database files on disk. If <strong><code>TRUE</code></strong>, an acknowledged insert is implied and this option will override setting <em>"w"</em> to <em>0</em>.</p><blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">If journaling is enabled, users are strongly encouraged to use the <em>"j"</em> option instead of <em>"fsync"</em>. Do not use <em>"fsync"</em> and <em>"j"</em> simultaneously, as that will result in an error.</p></blockquote></li>
315
     * <li><p><em>"j"</em></p><p>Boolean, defaults to <b>FALSE</b>. Forces the write operation to block until it is synced to the journal on disk. If <strong><code>TRUE</code></strong>, an acknowledged write is implied and this option will override setting <em>"w"</em> to <em>0</em>.</p><blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">If this option is used and journaling is disabled, MongoDB 2.6+ will raise an error and the write will fail; older server versions will simply ignore the option.</p></blockquote></li>
316
     * <li><p><em>"socketTimeoutMS"</em></p><p>This option specifies the time limit, in milliseconds, for socket communication. If the server does not respond within the timeout period, a <b>MongoCursorTimeoutException</b> will be thrown and there will be no way to determine if the server actually handled the write or not. A value of <em>-1</em> may be specified to block indefinitely. The default value for <b>MongoClient</b> is <em>30000</em> (30 seconds).</p></li>
317
     * <li><p><em>"w"</em></p><p>See {@link http://www.php.net/manual/en/mongo.writeconcerns.php Write Concerns }. The default value for <b>MongoClient</b> is <em>1</em>.</p></li>
318
     * <li><p><em>"wTimeoutMS"</em></p><p>This option specifies the time limit, in milliseconds, for {@link http://www.php.net/manual/en/mongo.writeconcerns.php write concern} acknowledgement. It is only applicable when <em>"w"</em> is greater than <em>1</em>, as the timeout pertains to replication. If the write concern is not satisfied within the time limit, a <a href="class.mongocursorexception.php" class="classname">MongoCursorException</a> will be thrown. A value of <em>0</em> may be specified to block indefinitely. The default value for {@link http://www.php.net/manual/en/class.mongoclient.php MongoClient} is <em>10000</em> (ten seconds).</p></li>
319
     * </ul>
320
     *
321
     * <p>
322
     * The following options are deprecated and should no longer be used:
323
     * </p><ul>
324
     * <li><p><em>"safe"</em></p><p>Deprecated. Please use the {@link http://www.php.net/manual/en/mongo.writeconcerns.php write concern} <em>"w"</em> option.</p></li>
325
     * <li><p><em>"timeout"</em></p><p>Deprecated alias for <em>"socketTimeoutMS"</em>.</p></li>
326
     * <li><p><b>"wtimeout"</b></p><p>Deprecated alias for <em>"wTimeoutMS"</em>.</p></p>
327
     * @throws MongoCursorException
328
     * @throws MongoCursorTimeoutException
329
     * @return bool|array <p>Returns an array containing the status of the removal if the
330
     * <em>"w"</em> option is set. Otherwise, returns <b>TRUE</b>.
331
     * </p>
332
     * <p>
333
     * Fields in the status array are described in the documentation for
334
     * <b>MongoCollection::insert()</b>.
335
     * </p>
336
     */
337
    public function remove(array $criteria = array(), array $options = array())
338
    {
339
        $multiple = isset($options['justOne']) ? !$options['justOne'] : false;
340
//        $multiple = !$options['justOne'] ?? false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
341
        $method = $multiple ? 'deleteMany' : 'deleteOne';
342
343
        return $this->collection->$method($criteria, $options);
344
    }
345
346
    /**
347
     * Querys this collection
348
     * @link http://www.php.net/manual/en/mongocollection.find.php
349
     * @param array $query The fields for which to search.
350
     * @param array $fields Fields of the results to return.
351
     * @return MongoCursor
352
     */
353
    public function find(array $query = array(), array $fields = array())
354
    {
355
        return new MongoCursor($this->db->getConnection(), (string) $this, $query, $fields);
356
    }
357
358
    /**
359
     * Retrieve a list of distinct values for the given key across a collection
360
     * @link http://www.php.net/manual/ru/mongocollection.distinct.php
361
     * @param string $key The key to use.
362
     * @param array $query An optional query parameters
363
     * @return array|bool Returns an array of distinct values, or <b>FALSE</b> on failure
364
     */
365
    public function distinct($key, array $query = NULL)
366
    {
367
        return array_map([TypeConverter::class, 'convertToLegacyType'], $this->collection->distinct($key, $query));
0 ignored issues
show
Bug introduced by
It seems like $query defined by parameter $query on line 365 can also be of type null; however, MongoDB\Collection::distinct() does only seem to accept array|object, 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...
368
    }
369
370
    /**
371
     * Update a document and return it
372
     * @link http://www.php.net/manual/ru/mongocollection.findandmodify.php
373
     * @param array $query The query criteria to search for.
374
     * @param array $update The update criteria.
375
     * @param array $fields Optionally only return these fields.
376
     * @param array $options An array of options to apply, such as remove the match document from the DB and return it.
377
     * @return array Returns the original document, or the modified document when new is set.
378
     */
379
    public function findAndModify(array $query, array $update = NULL, array $fields = NULL, array $options = NULL)
0 ignored issues
show
Unused Code introduced by
The parameter $query 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...
Unused Code introduced by
The parameter $update 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...
Unused Code introduced by
The parameter $fields 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...
Unused Code introduced by
The parameter $options 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...
380
    {
381
382
    }
383
384
    /**
385
     * Querys this collection, returning a single element
386
     * @link http://www.php.net/manual/en/mongocollection.findone.php
387
     * @param array $query The fields for which to search.
388
     * @param array $fields Fields of the results to return.
389
     * @return array|null
390
     */
391
    public function findOne(array $query = array(), array $fields = array())
0 ignored issues
show
Unused Code introduced by
The parameter $fields 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...
392
    {
393
        $document = $this->collection->findOne(TypeConverter::convertLegacyArrayToObject($query));
394
        if ($document !== null) {
395
            $document = TypeConverter::convertObjectToLegacyArray($document);
396
        }
397
398
        return $document;
399
    }
400
401
    /**
402
     * Creates an index on the given field(s), or does nothing if the index already exists
403
     * @link http://www.php.net/manual/en/mongocollection.createindex.php
404
     * @param array $keys Field or fields to use as index.
405
     * @param array $options [optional] This parameter is an associative array of the form array("optionname" => <boolean>, ...).
406
     * @return array Returns the database response.
407
     */
408
    public function createIndex(array $keys, array $options = array()) {}
0 ignored issues
show
Unused Code introduced by
The parameter $keys 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...
Unused Code introduced by
The parameter $options 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...
409
410
    /**
411
     * @deprecated Use MongoCollection::createIndex() instead.
412
     * Creates an index on the given field(s), or does nothing if the index already exists
413
     * @link http://www.php.net/manual/en/mongocollection.ensureindex.php
414
     * @param array $keys Field or fields to use as index.
415
     * @param array $options [optional] This parameter is an associative array of the form array("optionname" => <boolean>, ...).
416
     * @return boolean always true
417
     */
418
    public function ensureIndex(array $keys, array $options = array()) {}
0 ignored issues
show
Unused Code introduced by
The parameter $keys 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...
Unused Code introduced by
The parameter $options 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...
419
420
    /**
421
     * Deletes an index from this collection
422
     * @link http://www.php.net/manual/en/mongocollection.deleteindex.php
423
     * @param string|array $keys Field or fields from which to delete the index.
424
     * @return array Returns the database response.
425
     */
426
    public function deleteIndex($keys) {}
0 ignored issues
show
Unused Code introduced by
The parameter $keys 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...
427
428
    /**
429
     * Delete all indexes for this collection
430
     * @link http://www.php.net/manual/en/mongocollection.deleteindexes.php
431
     * @return array Returns the database response.
432
     */
433
    public function deleteIndexes() {}
434
435
    /**
436
     * Returns an array of index names for this collection
437
     * @link http://www.php.net/manual/en/mongocollection.getindexinfo.php
438
     * @return array Returns a list of index names.
439
     */
440
    public function getIndexInfo() {}
441
442
    /**
443
     * Counts the number of documents in this collection
444
     * @link http://www.php.net/manual/en/mongocollection.count.php
445
     * @param array|stdClass $query
446
     * @return int Returns the number of documents matching the query.
447
     */
448
    public function count($query = array())
449
    {
450
        return $this->collection->count($query);
451
    }
452
453
    /**
454
     * Saves an object to this collection
455
     * @link http://www.php.net/manual/en/mongocollection.save.php
456
     * @param array|object $a Array to save. If an object is used, it may not have protected or private properties.
457
     * Note: If the parameter does not have an _id key or property, a new MongoId instance will be created and assigned to it.
458
     * See MongoCollection::insert() for additional information on this behavior.
459
     * @param array $options Options for the save.
460
     * <dl>
461
     * <dt>"w"
462
     * <dd>See WriteConcerns. The default value for MongoClient is 1.
463
     * <dt>"fsync"
464
     * <dd>Boolean, defaults to FALSE. Forces the insert to be synced to disk before returning success. If TRUE, an acknowledged insert is implied and will override setting w to 0.
465
     * <dt>"timeout"
466
     * <dd>Integer, defaults to MongoCursor::$timeout. If "safe" is set, this sets how long (in milliseconds) for the client to wait for a database response. If the database does not respond within the timeout period, a MongoCursorTimeoutException will be thrown.
467
     * <dt>"safe"
468
     * <dd>Deprecated. Please use the WriteConcern w option.
469
     * </dl>
470
     * @throws MongoException if the inserted document is empty or if it contains zero-length keys. Attempting to insert an object with protected and private properties will cause a zero-length key error.
471
     * @throws MongoCursorException if the "w" option is set and the write fails.
472
     * @throws MongoCursorTimeoutException if the "w" option is set to a value greater than one and the operation takes longer than MongoCursor::$timeout milliseconds to complete. This does not kill the operation on the server, it is a client-side timeout. The operation in MongoCollection::$wtimeout is milliseconds.
473
     * @return array|boolean If w was set, returns an array containing the status of the save.
474
     * Otherwise, returns a boolean representing if the array was not empty (an empty array will not be inserted).
475
     */
476
    public function save($a, array $options = array()) {}
0 ignored issues
show
Unused Code introduced by
The parameter $a 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...
Unused Code introduced by
The parameter $options 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...
477
478
    /**
479
     * Creates a database reference
480
     * @link http://www.php.net/manual/en/mongocollection.createdbref.php
481
     * @param array $a Object to which to create a reference.
482
     * @return array Returns a database reference array.
483
     */
484
    public function createDBRef(array $a) {}
0 ignored issues
show
Unused Code introduced by
The parameter $a 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...
485
486
    /**
487
     * Fetches the document pointed to by a database reference
488
     * @link http://www.php.net/manual/en/mongocollection.getdbref.php
489
     * @param array $ref A database reference.
490
     * @return array Returns the database document pointed to by the reference.
491
     */
492
    public function getDBRef(array $ref) {}
0 ignored issues
show
Unused Code introduced by
The parameter $ref 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...
493
494
    /**
495
     * @param  mixed $keys
496
     * @static
497
     * @return string
498
     */
499
    protected static function toIndexString($keys) {}
0 ignored issues
show
Unused Code introduced by
The parameter $keys 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...
500
501
    /**
502
     * Performs an operation similar to SQL's GROUP BY command
503
     * @link http://www.php.net/manual/en/mongocollection.group.php
504
     * @param mixed $keys Fields to group by. If an array or non-code object is passed, it will be the key used to group results.
505
     * @param array $initial Initial value of the aggregation counter object.
506
     * @param MongoCode $reduce A function that aggregates (reduces) the objects iterated.
507
     * @param array $condition An condition that must be true for a row to be considered.
508
     * @return array
509
     */
510
    public function group($keys, array $initial, MongoCode $reduce, array $condition = array()) {}
0 ignored issues
show
Unused Code introduced by
The parameter $keys 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...
Unused Code introduced by
The parameter $initial 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...
Unused Code introduced by
The parameter $reduce 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...
Unused Code introduced by
The parameter $condition 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...
511
512
    protected function notImplemented()
513
    {
514
        throw new \Exception('Not implemented');
515
    }
516
}
517
518