@@ -200,7 +200,7 @@ |
||
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
203 | - * @param $id |
|
203 | + * @param string|null $id |
|
204 | 204 | * @throws MongoException |
205 | 205 | */ |
206 | 206 | private function createObjectID($id) |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | class MongoClient |
24 | 24 | { |
25 | 25 | const VERSION = '1.6.12'; |
26 | - const DEFAULT_HOST = "localhost" ; |
|
27 | - const DEFAULT_PORT = 27017 ; |
|
28 | - const RP_PRIMARY = "primary" ; |
|
29 | - const RP_PRIMARY_PREFERRED = "primaryPreferred" ; |
|
30 | - const RP_SECONDARY = "secondary" ; |
|
31 | - const RP_SECONDARY_PREFERRED = "secondaryPreferred" ; |
|
32 | - const RP_NEAREST = "nearest" ; |
|
26 | + const DEFAULT_HOST = "localhost"; |
|
27 | + const DEFAULT_PORT = 27017; |
|
28 | + const RP_PRIMARY = "primary"; |
|
29 | + const RP_PRIMARY_PREFERRED = "primaryPreferred"; |
|
30 | + const RP_SECONDARY = "secondary"; |
|
31 | + const RP_SECONDARY_PREFERRED = "secondaryPreferred"; |
|
32 | + const RP_NEAREST = "nearest"; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * @var bool |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * {@link http://www.php.net/manual/en/class.mongoint64.php MongoInt64} class. The latter is necessary on 32 |
199 | 199 | * bit platforms (and Windows). |
200 | 200 | */ |
201 | - public function killCursor($server_hash , $id) |
|
201 | + public function killCursor($server_hash, $id) |
|
202 | 202 | { |
203 | 203 | |
204 | 204 | } |
@@ -216,7 +216,7 @@ |
||
216 | 216 | * @link http://www.php.net/manual/en/mongoclient.killcursor.php |
217 | 217 | * @param string $server_hash The server hash that has the cursor. |
218 | 218 | * @param int|MongoInt64 $id The ID of the cursor to kill. |
219 | - * @return bool |
|
219 | + * @return boolean|null |
|
220 | 220 | */ |
221 | 221 | public function killCursor($server_hash , $id) |
222 | 222 | { |
@@ -25,7 +25,7 @@ |
||
25 | 25 | * http://php.net/manual/en/mongoresultexception.getdocument.php |
26 | 26 | * @return array <p>The full result document as an array, including partial data if available and additional keys.</p> |
27 | 27 | */ |
28 | - public function getDocument () {} |
|
28 | + public function getDocument() {} |
|
29 | 29 | |
30 | 30 | public $document; |
31 | 31 |
@@ -18,13 +18,16 @@ |
||
18 | 18 | * @link http://php.net/manual/en/class.mongoresultexception.php#mongoresultexception.props.document |
19 | 19 | * |
20 | 20 | */ |
21 | -class MongoResultException extends MongoException { |
|
21 | +class MongoResultException extends MongoException |
|
22 | +{ |
|
22 | 23 | /** |
23 | 24 | * Retrieve the full result document |
24 | 25 | * http://php.net/manual/en/mongoresultexception.getdocument.php |
25 | 26 | * @return array <p>The full result document as an array, including partial data if available and additional keys.</p> |
26 | 27 | */ |
27 | - public function getDocument () {} |
|
28 | + public function getDocument () |
|
29 | + { |
|
30 | +} |
|
28 | 31 | |
29 | 32 | public $document; |
30 | 33 |
@@ -15,7 +15,6 @@ |
||
15 | 15 | |
16 | 16 | use Alcaeus\MongoDbAdapter\TypeInterface; |
17 | 17 | use MongoDB\BSON\Binary; |
18 | -use MongoDB\BSON\Type; |
|
19 | 18 | |
20 | 19 | class MongoBinData implements TypeInterface |
21 | 20 | { |
@@ -72,7 +72,7 @@ |
||
72 | 72 | protected $readPreference = []; |
73 | 73 | |
74 | 74 | /** |
75 | - * @return Cursor |
|
75 | + * @return \Traversable |
|
76 | 76 | */ |
77 | 77 | abstract protected function ensureCursor(); |
78 | 78 |
@@ -201,7 +201,7 @@ |
||
201 | 201 | * @link http://www.php.net/manual/en/mongocursor.hasnext.php |
202 | 202 | * @throws MongoConnectionException |
203 | 203 | * @throws MongoCursorTimeoutException |
204 | - * @return bool Returns true if there is another element |
|
204 | + * @return boolean|null Returns true if there is another element |
|
205 | 205 | */ |
206 | 206 | public function hasNext() |
207 | 207 | { |
@@ -15,7 +15,6 @@ |
||
15 | 15 | |
16 | 16 | use Alcaeus\MongoDbAdapter\AbstractCursor; |
17 | 17 | use MongoDB\Driver\Cursor; |
18 | -use MongoDB\Driver\ReadPreference; |
|
19 | 18 | use MongoDB\Operation\Find; |
20 | 19 | |
21 | 20 | /** |
@@ -380,7 +380,7 @@ |
||
380 | 380 | */ |
381 | 381 | protected function convertCursorType() |
382 | 382 | { |
383 | - if (! $this->tailable) { |
|
383 | + if ( ! $this->tailable) { |
|
384 | 384 | return null; |
385 | 385 | } |
386 | 386 |
@@ -126,6 +126,9 @@ |
||
126 | 126 | ); |
127 | 127 | } |
128 | 128 | |
129 | + /** |
|
130 | + * @param resource $handle |
|
131 | + */ |
|
129 | 132 | private function writeFromRessource($handle) |
130 | 133 | { |
131 | 134 |
@@ -75,7 +75,7 @@ |
||
75 | 75 | $filename = 'file'; |
76 | 76 | } |
77 | 77 | |
78 | - if (! $handle = fopen($filename, 'w')) { |
|
78 | + if ( ! $handle = fopen($filename, 'w')) { |
|
79 | 79 | trigger_error(E_ERROR, 'Can not open the destination file'); |
80 | 80 | return 0; |
81 | 81 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * Returns the address being used by this for slaveOkay reads |
49 | 49 | * |
50 | 50 | * @link http://php.net/manual/en/mongo.getslave.php |
51 | - * @return bool The address of the secondary this connection is using for |
|
51 | + * @return boolean|null The address of the secondary this connection is using for |
|
52 | 52 | * reads. This returns NULL if this is not connected to a replica set or not yet |
53 | 53 | * initialized. |
54 | 54 | */ |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * Get slaveOkay setting for this connection |
62 | 62 | * |
63 | 63 | * @link http://php.net/manual/en/mongo.getslaveokay.php |
64 | - * @return bool Returns the value of slaveOkay for this instance. |
|
64 | + * @return boolean|null Returns the value of slaveOkay for this instance. |
|
65 | 65 | */ |
66 | 66 | public function getSlaveOkay() |
67 | 67 | { |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @link http://www.php.net/manual/en/mongo.pairconnect.php |
75 | 75 | * @throws MongoConnectionException |
76 | - * @return boolean |
|
76 | + * @return boolean|null |
|
77 | 77 | * |
78 | 78 | * @deprecated Pass a string of the form "mongodb://server1,server2" to the constructor instead of using this method. |
79 | 79 | */ |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @link http://php.net/manual/en/mongo.setslaveokay.php |
101 | 101 | * @param bool $ok |
102 | - * @return bool returns the former value of slaveOkay for this instance. |
|
102 | + * @return boolean|null returns the former value of slaveOkay for this instance. |
|
103 | 103 | */ |
104 | 104 | public function setSlaveOkay ($ok) |
105 | 105 | { |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @link http://php.net/manual/en/mongo.setpoolsize.php |
113 | 113 | * @param $size <p>The max number of connections future pools will be able to create. Negative numbers mean that the pool will spawn an infinite number of connections.</p> |
114 | - * @return bool Returns the former value of pool size. |
|
114 | + * @return boolean|null Returns the former value of pool size. |
|
115 | 115 | * @deprecated Relying on this feature is highly discouraged. Please use MongoPool::setSize() instead. |
116 | 116 | */ |
117 | 117 | public function setPoolSize($size) |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param string $username A username used to identify the connection. |
127 | 127 | * @param string $password A password used to identify the connection. |
128 | 128 | * @throws MongoConnectionException |
129 | - * @return boolean If the connection was successful. |
|
129 | + * @return boolean|null If the connection was successful. |
|
130 | 130 | * @deprecated Pass array("persist" => $id) to the constructor instead of using this method. |
131 | 131 | */ |
132 | 132 | public function persistConnect($username = "", $password = "") |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @param string $username A username used to identify the connection. |
142 | 142 | * @param string $password A password used to identify the connection. |
143 | 143 | * @throws MongoConnectionException |
144 | - * @return boolean If the connection was successful. |
|
144 | + * @return boolean|null If the connection was successful. |
|
145 | 145 | * @deprecated Pass "mongodb://server1,server2" and array("persist" => $id) to the constructor instead of using this method. |
146 | 146 | */ |
147 | 147 | public function pairPersistConnect($username = "", $password = "") |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @link http://www.php.net/manual/en/mongo.connectutil.php |
156 | 156 | * @throws MongoConnectionException |
157 | - * @return boolean If the connection was successful. |
|
157 | + * @return boolean|null If the connection was successful. |
|
158 | 158 | */ |
159 | 159 | protected function connectUtil() |
160 | 160 | { |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * Creates a database error on the database. |
202 | 202 | * |
203 | 203 | * @link http://www.php.net/manual/en/mongo.forceerror.php |
204 | - * @return boolean The database response. |
|
204 | + * @return boolean|null The database response. |
|
205 | 205 | * @deprecated Use MongoDB::forceError() instead. |
206 | 206 | */ |
207 | 207 | public function forceError() |
@@ -101,7 +101,7 @@ |
||
101 | 101 | * @param bool $ok |
102 | 102 | * @return bool returns the former value of slaveOkay for this instance. |
103 | 103 | */ |
104 | - public function setSlaveOkay ($ok) |
|
104 | + public function setSlaveOkay($ok) |
|
105 | 105 | { |
106 | 106 | $this->notImplemented(); |
107 | 107 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @var MongoDB |
34 | 34 | */ |
35 | - public $db = NULL; |
|
35 | + public $db = null; |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @var string |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | foreach (func_get_args() as $operator) { |
134 | 134 | $i++; |
135 | 135 | if (! is_array($operator)) { |
136 | - trigger_error("Argument $i is not an array", E_WARNING); |
|
136 | + trigger_error("argument $i is not an array", E_WARNING); |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @param bool $scan_data Only validate indices, not the base collection. |
235 | 235 | * @return array Returns the database's evaluation of this object. |
236 | 236 | */ |
237 | - public function validate($scan_data = FALSE) |
|
237 | + public function validate($scan_data = false) |
|
238 | 238 | { |
239 | 239 | $command = [ |
240 | 240 | 'validate' => $this->name, |
@@ -816,6 +816,9 @@ |
||
816 | 816 | return $options; |
817 | 817 | } |
818 | 818 | |
819 | + /** |
|
820 | + * @param string $name |
|
821 | + */ |
|
819 | 822 | private function checkCollectionName($name) |
820 | 823 | { |
821 | 824 | if (empty($name)) { |
@@ -127,14 +127,14 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function aggregate(array $pipeline, array $op = []) |
129 | 129 | { |
130 | - if (! TypeConverter::isNumericArray($pipeline)) { |
|
130 | + if ( ! TypeConverter::isNumericArray($pipeline)) { |
|
131 | 131 | $pipeline = []; |
132 | 132 | $options = []; |
133 | 133 | |
134 | 134 | $i = 0; |
135 | 135 | foreach (func_get_args() as $operator) { |
136 | 136 | $i++; |
137 | - if (! is_array($operator)) { |
|
137 | + if ( ! is_array($operator)) { |
|
138 | 138 | trigger_error("Argument $i is not an array", E_WARNING); |
139 | 139 | return; |
140 | 140 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | ]; |
178 | 178 | |
179 | 179 | // Convert cursor option |
180 | - if (! isset($options['cursor'])) { |
|
180 | + if ( ! isset($options['cursor'])) { |
|
181 | 181 | $options['cursor'] = true; |
182 | 182 | } |
183 | 183 | |
@@ -263,12 +263,12 @@ discard block |
||
263 | 263 | */ |
264 | 264 | public function insert(&$a, array $options = []) |
265 | 265 | { |
266 | - if (! $this->ensureDocumentHasMongoId($a)) { |
|
266 | + if ( ! $this->ensureDocumentHasMongoId($a)) { |
|
267 | 267 | trigger_error(sprintf('%s expects parameter %d to be an array or object, %s given', __METHOD__, 1, gettype($a)), E_USER_WARNING); |
268 | 268 | return; |
269 | 269 | } |
270 | 270 | |
271 | - if (! count((array)$a)) { |
|
271 | + if ( ! count((array) $a)) { |
|
272 | 272 | throw new \MongoException('document must be an array or object'); |
273 | 273 | } |
274 | 274 | |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | ExceptionConverter::toLegacy($e); |
291 | 291 | } |
292 | 292 | |
293 | - if (! $result->isAcknowledged()) { |
|
293 | + if ( ! $result->isAcknowledged()) { |
|
294 | 294 | return true; |
295 | 295 | } |
296 | 296 | |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | |
322 | 322 | foreach ($a as $key => $item) { |
323 | 323 | try { |
324 | - if (! $this->ensureDocumentHasMongoId($a[$key])) { |
|
324 | + if ( ! $this->ensureDocumentHasMongoId($a[$key])) { |
|
325 | 325 | if ($continueOnError) { |
326 | 326 | unset($a[$key]); |
327 | 327 | } else { |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | ExceptionConverter::toLegacy($e); |
346 | 346 | } |
347 | 347 | |
348 | - if (! $result->isAcknowledged()) { |
|
348 | + if ( ! $result->isAcknowledged()) { |
|
349 | 349 | return true; |
350 | 350 | } |
351 | 351 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @throws MongoCursorException |
370 | 370 | * @return boolean |
371 | 371 | */ |
372 | - public function update(array $criteria , array $newobj, array $options = []) |
|
372 | + public function update(array $criteria, array $newobj, array $options = []) |
|
373 | 373 | { |
374 | 374 | $multiple = isset($options['multiple']) ? $options['multiple'] : false; |
375 | 375 | $method = $multiple ? 'updateMany' : 'updateOne'; |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | ExceptionConverter::toLegacy($e); |
398 | 398 | } |
399 | 399 | |
400 | - if (! $result->isAcknowledged()) { |
|
400 | + if ( ! $result->isAcknowledged()) { |
|
401 | 401 | return true; |
402 | 402 | } |
403 | 403 | |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | */ |
425 | 425 | public function remove(array $criteria = [], array $options = []) |
426 | 426 | { |
427 | - $multiple = isset($options['justOne']) ? !$options['justOne'] : true; |
|
427 | + $multiple = isset($options['justOne']) ? ! $options['justOne'] : true; |
|
428 | 428 | $method = $multiple ? 'deleteMany' : 'deleteOne'; |
429 | 429 | |
430 | 430 | try { |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | ExceptionConverter::toLegacy($e); |
438 | 438 | } |
439 | 439 | |
440 | - if (! $result->isAcknowledged()) { |
|
440 | + if ( ! $result->isAcknowledged()) { |
|
441 | 441 | return true; |
442 | 442 | } |
443 | 443 | |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | */ |
562 | 562 | public function createIndex(array $keys, array $options = []) |
563 | 563 | { |
564 | - if (! is_array($keys) || ! count($keys)) { |
|
564 | + if ( ! is_array($keys) || ! count($keys)) { |
|
565 | 565 | throw new MongoException('keys cannot be empty'); |
566 | 566 | } |
567 | 567 | |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | $indexes = $this->collection->listIndexes(); |
572 | 572 | foreach ($indexes as $index) { |
573 | 573 | |
574 | - if (! empty($options['name']) && $index->getName() === $options['name']) { |
|
574 | + if ( ! empty($options['name']) && $index->getName() === $options['name']) { |
|
575 | 575 | throw new \MongoDuplicateKeyException(); |
576 | 576 | } |
577 | 577 | |
@@ -732,13 +732,13 @@ discard block |
||
732 | 732 | if ($document_or_id instanceof \MongoId) { |
733 | 733 | $id = $document_or_id; |
734 | 734 | } elseif (is_object($document_or_id)) { |
735 | - if (! isset($document_or_id->_id)) { |
|
735 | + if ( ! isset($document_or_id->_id)) { |
|
736 | 736 | return null; |
737 | 737 | } |
738 | 738 | |
739 | 739 | $id = $document_or_id->_id; |
740 | 740 | } elseif (is_array($document_or_id)) { |
741 | - if (! isset($document_or_id['_id'])) { |
|
741 | + if ( ! isset($document_or_id['_id'])) { |
|
742 | 742 | return null; |
743 | 743 | } |
744 | 744 | |
@@ -781,14 +781,14 @@ discard block |
||
781 | 781 | $command = [ |
782 | 782 | 'group' => [ |
783 | 783 | 'ns' => $this->name, |
784 | - '$reduce' => (string)$reduce, |
|
784 | + '$reduce' => (string) $reduce, |
|
785 | 785 | 'initial' => $initial, |
786 | 786 | 'cond' => $condition, |
787 | 787 | ], |
788 | 788 | ]; |
789 | 789 | |
790 | 790 | if ($keys instanceof MongoCode) { |
791 | - $command['group']['$keyf'] = (string)$keys; |
|
791 | + $command['group']['$keyf'] = (string) $keys; |
|
792 | 792 | } else { |
793 | 793 | $command['group']['key'] = $keys; |
794 | 794 | } |
@@ -797,7 +797,7 @@ discard block |
||
797 | 797 | } |
798 | 798 | if (array_key_exists('finalize', $condition)) { |
799 | 799 | if ($condition['finalize'] instanceof MongoCode) { |
800 | - $condition['finalize'] = (string)$condition['finalize']; |
|
800 | + $condition['finalize'] = (string) $condition['finalize']; |
|
801 | 801 | } |
802 | 802 | $command['group']['finalize'] = $condition['finalize']; |
803 | 803 | } |
@@ -851,11 +851,11 @@ discard block |
||
851 | 851 | $options['w'] = ($options['safe']) ? 1 : 0; |
852 | 852 | } |
853 | 853 | |
854 | - if (isset($options['wtimeout']) && !isset($options['wTimeoutMS'])) { |
|
854 | + if (isset($options['wtimeout']) && ! isset($options['wTimeoutMS'])) { |
|
855 | 855 | $options['wTimeoutMS'] = $options['wtimeout']; |
856 | 856 | } |
857 | 857 | |
858 | - if (isset($options['w']) || !isset($options['wTimeoutMS'])) { |
|
858 | + if (isset($options['w']) || ! isset($options['wTimeoutMS'])) { |
|
859 | 859 | $collectionWriteConcern = $this->getWriteConcern(); |
860 | 860 | $writeConcern = $this->createWriteConcernFromParameters( |
861 | 861 | isset($options['w']) ? $options['w'] : $collectionWriteConcern['w'], |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | if (empty($document)) { |
892 | 892 | throw new \MongoException('document cannot be empty'); |
893 | 893 | } |
894 | - if (! isset($document['_id'])) { |
|
894 | + if ( ! isset($document['_id'])) { |
|
895 | 895 | $document['_id'] = new \MongoId(); |
896 | 896 | } |
897 | 897 | |
@@ -902,7 +902,7 @@ discard block |
||
902 | 902 | if (empty((array) $document)) { |
903 | 903 | throw new \MongoException('document cannot be empty'); |
904 | 904 | } |
905 | - if (! isset($document->_id)) { |
|
905 | + if ( ! isset($document->_id)) { |
|
906 | 906 | $document->_id = new \MongoId(); |
907 | 907 | } |
908 | 908 |