PHPLIB-330: Apply automatic fixes via phpcbf

parent c5a45f1c
...@@ -30,8 +30,6 @@ class BulkWriteResult ...@@ -30,8 +30,6 @@ class BulkWriteResult
private $isAcknowledged; private $isAcknowledged;
/** /**
* Constructor.
*
* @param WriteResult $writeResult * @param WriteResult $writeResult
* @param mixed[] $insertedIds * @param mixed[] $insertedIds
*/ */
......
...@@ -17,13 +17,15 @@ ...@@ -17,13 +17,15 @@
namespace MongoDB; namespace MongoDB;
use Iterator;
use MongoDB\Driver\CursorId; use MongoDB\Driver\CursorId;
use MongoDB\Driver\Exception\ConnectionException; use MongoDB\Driver\Exception\ConnectionException;
use MongoDB\Driver\Exception\RuntimeException; use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Driver\Exception\ServerException; use MongoDB\Driver\Exception\ServerException;
use MongoDB\Exception\ResumeTokenException; use MongoDB\Exception\ResumeTokenException;
use MongoDB\Model\ChangeStreamIterator; use MongoDB\Model\ChangeStreamIterator;
use Iterator; use function call_user_func;
use function in_array;
/** /**
* Iterator for a change stream. * Iterator for a change stream.
...@@ -57,8 +59,6 @@ class ChangeStream implements Iterator ...@@ -57,8 +59,6 @@ class ChangeStream implements Iterator
private $hasAdvanced = false; private $hasAdvanced = false;
/** /**
* Constructor.
*
* @internal * @internal
* @param ChangeStreamIterator $iterator * @param ChangeStreamIterator $iterator
* @param callable $resumeCallable * @param callable $resumeCallable
...@@ -109,6 +109,7 @@ class ChangeStream implements Iterator ...@@ -109,6 +109,7 @@ class ChangeStream implements Iterator
if ($this->valid()) { if ($this->valid()) {
return $this->key; return $this->key;
} }
return null; return null;
} }
...@@ -167,7 +168,7 @@ class ChangeStream implements Iterator ...@@ -167,7 +168,7 @@ class ChangeStream implements Iterator
return true; return true;
} }
if ( ! $exception instanceof ServerException) { if (! $exception instanceof ServerException) {
return false; return false;
} }
...@@ -202,7 +203,7 @@ class ChangeStream implements Iterator ...@@ -202,7 +203,7 @@ class ChangeStream implements Iterator
/* Return early if there is not a current result. Avoid any attempt to /* Return early if there is not a current result. Avoid any attempt to
* increment the iterator's key. */ * increment the iterator's key. */
if (!$this->valid()) { if (! $this->valid()) {
return; return;
} }
...@@ -236,6 +237,7 @@ class ChangeStream implements Iterator ...@@ -236,6 +237,7 @@ class ChangeStream implements Iterator
{ {
if ($this->isResumableError($exception)) { if ($this->isResumableError($exception)) {
$this->resume(); $this->resume();
return; return;
} }
......
...@@ -17,27 +17,30 @@ ...@@ -17,27 +17,30 @@
namespace MongoDB; namespace MongoDB;
use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
use MongoDB\Model\DatabaseInfoIterator; use MongoDB\Model\DatabaseInfoIterator;
use MongoDB\Operation\DropDatabase; use MongoDB\Operation\DropDatabase;
use MongoDB\Operation\ListDatabases; use MongoDB\Operation\ListDatabases;
use MongoDB\Operation\Watch; use MongoDB\Operation\Watch;
use function is_array;
class Client class Client
{ {
private static $defaultTypeMap = [ private static $defaultTypeMap = [
'array' => \MongoDB\Model\BSONArray::class, 'array' => BSONArray::class,
'document' => \MongoDB\Model\BSONDocument::class, 'document' => BSONDocument::class,
'root' => \MongoDB\Model\BSONDocument::class, 'root' => BSONDocument::class,
]; ];
private static $wireVersionForReadConcern = 4; private static $wireVersionForReadConcern = 4;
private static $wireVersionForWritableCommandWriteConcern = 5; private static $wireVersionForWritableCommandWriteConcern = 5;
...@@ -147,13 +150,13 @@ class Client ...@@ -147,13 +150,13 @@ class Client
*/ */
public function dropDatabase($databaseName, array $options = []) public function dropDatabase($databaseName, array $options = [])
{ {
if ( ! isset($options['typeMap'])) { if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap; $options['typeMap'] = $this->typeMap;
} }
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) { if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) {
$options['writeConcern'] = $this->writeConcern; $options['writeConcern'] = $this->writeConcern;
} }
...@@ -269,7 +272,7 @@ class Client ...@@ -269,7 +272,7 @@ class Client
* Start a new client session. * Start a new client session.
* *
* @see http://php.net/manual/en/mongodb-driver-manager.startsession.php * @see http://php.net/manual/en/mongodb-driver-manager.startsession.php
* @param array $options Session options * @param array $options Session options
* @return Session * @return Session
*/ */
public function startSession(array $options = []) public function startSession(array $options = [])
...@@ -288,17 +291,17 @@ class Client ...@@ -288,17 +291,17 @@ class Client
*/ */
public function watch(array $pipeline = [], array $options = []) public function watch(array $pipeline = [], array $options = [])
{ {
if ( ! isset($options['readPreference'])) { if (! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference; $options['readPreference'] = $this->readPreference;
} }
$server = $this->manager->selectServer($options['readPreference']); $server = $this->manager->selectServer($options['readPreference']);
if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { if (! isset($options['readConcern']) && server_supports_feature($server, self::$wireVersionForReadConcern)) {
$options['readConcern'] = $this->readConcern; $options['readConcern'] = $this->readConcern;
} }
if ( ! isset($options['typeMap'])) { if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap; $options['typeMap'] = $this->typeMap;
} }
......
This diff is collapsed.
...@@ -17,17 +17,18 @@ ...@@ -17,17 +17,18 @@
namespace MongoDB; namespace MongoDB;
use MongoDB\Collection;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\GridFS\Bucket; use MongoDB\GridFS\Bucket;
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
use MongoDB\Model\CollectionInfoIterator; use MongoDB\Model\CollectionInfoIterator;
use MongoDB\Operation\Aggregate; use MongoDB\Operation\Aggregate;
use MongoDB\Operation\CreateCollection; use MongoDB\Operation\CreateCollection;
...@@ -38,13 +39,15 @@ use MongoDB\Operation\ListCollections; ...@@ -38,13 +39,15 @@ use MongoDB\Operation\ListCollections;
use MongoDB\Operation\ModifyCollection; use MongoDB\Operation\ModifyCollection;
use MongoDB\Operation\Watch; use MongoDB\Operation\Watch;
use Traversable; use Traversable;
use function is_array;
use function strlen;
class Database class Database
{ {
private static $defaultTypeMap = [ private static $defaultTypeMap = [
'array' => \MongoDB\Model\BSONArray::class, 'array' => BSONArray::class,
'document' => \MongoDB\Model\BSONDocument::class, 'document' => BSONDocument::class,
'root' => \MongoDB\Model\BSONDocument::class, 'root' => BSONDocument::class,
]; ];
private static $wireVersionForReadConcern = 4; private static $wireVersionForReadConcern = 4;
private static $wireVersionForWritableCommandWriteConcern = 5; private static $wireVersionForWritableCommandWriteConcern = 5;
...@@ -175,9 +178,9 @@ class Database ...@@ -175,9 +178,9 @@ class Database
*/ */
public function aggregate(array $pipeline, array $options = []) public function aggregate(array $pipeline, array $options = [])
{ {
$hasWriteStage = \MongoDB\is_last_pipeline_operator_write($pipeline); $hasWriteStage = is_last_pipeline_operator_write($pipeline);
if ( ! isset($options['readPreference'])) { if (! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference; $options['readPreference'] = $this->readPreference;
} }
...@@ -192,22 +195,22 @@ class Database ...@@ -192,22 +195,22 @@ class Database
* *
* A read concern is also not compatible with transactions. * A read concern is also not compatible with transactions.
*/ */
if ( ! isset($options['readConcern']) && if (! isset($options['readConcern']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) && server_supports_feature($server, self::$wireVersionForReadConcern) &&
! \MongoDB\is_in_transaction($options) && ! is_in_transaction($options) &&
( ! $hasWriteStage || \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcernWithWriteStage)) ( ! $hasWriteStage || server_supports_feature($server, self::$wireVersionForReadConcernWithWriteStage))
) { ) {
$options['readConcern'] = $this->readConcern; $options['readConcern'] = $this->readConcern;
} }
if ( ! isset($options['typeMap'])) { if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap; $options['typeMap'] = $this->typeMap;
} }
if ($hasWriteStage && if ($hasWriteStage &&
! isset($options['writeConcern']) && ! isset($options['writeConcern']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) &&
! \MongoDB\is_in_transaction($options)) { ! is_in_transaction($options)) {
$options['writeConcern'] = $this->writeConcern; $options['writeConcern'] = $this->writeConcern;
} }
...@@ -228,11 +231,11 @@ class Database ...@@ -228,11 +231,11 @@ class Database
*/ */
public function command($command, array $options = []) public function command($command, array $options = [])
{ {
if ( ! isset($options['readPreference'])) { if (! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference; $options['readPreference'] = $this->readPreference;
} }
if ( ! isset($options['typeMap'])) { if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap; $options['typeMap'] = $this->typeMap;
} }
...@@ -255,13 +258,13 @@ class Database ...@@ -255,13 +258,13 @@ class Database
*/ */
public function createCollection($collectionName, array $options = []) public function createCollection($collectionName, array $options = [])
{ {
if ( ! isset($options['typeMap'])) { if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap; $options['typeMap'] = $this->typeMap;
} }
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) { if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) {
$options['writeConcern'] = $this->writeConcern; $options['writeConcern'] = $this->writeConcern;
} }
...@@ -282,13 +285,13 @@ class Database ...@@ -282,13 +285,13 @@ class Database
*/ */
public function drop(array $options = []) public function drop(array $options = [])
{ {
if ( ! isset($options['typeMap'])) { if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap; $options['typeMap'] = $this->typeMap;
} }
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) { if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) {
$options['writeConcern'] = $this->writeConcern; $options['writeConcern'] = $this->writeConcern;
} }
...@@ -310,13 +313,13 @@ class Database ...@@ -310,13 +313,13 @@ class Database
*/ */
public function dropCollection($collectionName, array $options = []) public function dropCollection($collectionName, array $options = [])
{ {
if ( ! isset($options['typeMap'])) { if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap; $options['typeMap'] = $this->typeMap;
} }
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) { if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) {
$options['writeConcern'] = $this->writeConcern; $options['writeConcern'] = $this->writeConcern;
} }
...@@ -417,13 +420,13 @@ class Database ...@@ -417,13 +420,13 @@ class Database
*/ */
public function modifyCollection($collectionName, array $collectionOptions, array $options = []) public function modifyCollection($collectionName, array $collectionOptions, array $options = [])
{ {
if ( ! isset($options['typeMap'])) { if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap; $options['typeMap'] = $this->typeMap;
} }
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) { if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) {
$options['writeConcern'] = $this->writeConcern; $options['writeConcern'] = $this->writeConcern;
} }
...@@ -484,17 +487,17 @@ class Database ...@@ -484,17 +487,17 @@ class Database
*/ */
public function watch(array $pipeline = [], array $options = []) public function watch(array $pipeline = [], array $options = [])
{ {
if ( ! isset($options['readPreference'])) { if (! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference; $options['readPreference'] = $this->readPreference;
} }
$server = $this->manager->selectServer($options['readPreference']); $server = $this->manager->selectServer($options['readPreference']);
if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { if (! isset($options['readConcern']) && server_supports_feature($server, self::$wireVersionForReadConcern)) {
$options['readConcern'] = $this->readConcern; $options['readConcern'] = $this->readConcern;
} }
if ( ! isset($options['typeMap'])) { if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap; $options['typeMap'] = $this->typeMap;
} }
......
...@@ -29,8 +29,6 @@ class DeleteResult ...@@ -29,8 +29,6 @@ class DeleteResult
private $isAcknowledged; private $isAcknowledged;
/** /**
* Constructor.
*
* @param WriteResult $writeResult * @param WriteResult $writeResult
*/ */
public function __construct(WriteResult $writeResult) public function __construct(WriteResult $writeResult)
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
namespace MongoDB\Exception; namespace MongoDB\Exception;
use BadMethodCallException as BaseBadMethodCallException; use BadMethodCallException as BaseBadMethodCallException;
use function sprintf;
class BadMethodCallException extends BaseBadMethodCallException implements Exception class BadMethodCallException extends BaseBadMethodCallException implements Exception
{ {
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
namespace MongoDB\Exception; namespace MongoDB\Exception;
use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException; use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException;
use function get_class;
use function gettype;
use function is_object;
use function sprintf;
class InvalidArgumentException extends DriverInvalidArgumentException implements Exception class InvalidArgumentException extends DriverInvalidArgumentException implements Exception
{ {
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
namespace MongoDB\Exception; namespace MongoDB\Exception;
use function gettype;
use function sprintf;
class ResumeTokenException extends RuntimeException class ResumeTokenException extends RuntimeException
{ {
/** /**
......
...@@ -19,17 +19,40 @@ namespace MongoDB\GridFS; ...@@ -19,17 +19,40 @@ namespace MongoDB\GridFS;
use MongoDB\Collection; use MongoDB\Collection;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\GridFS\Exception\CorruptFileException; use MongoDB\GridFS\Exception\CorruptFileException;
use MongoDB\GridFS\Exception\FileNotFoundException; use MongoDB\GridFS\Exception\FileNotFoundException;
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
use MongoDB\Operation\Find; use MongoDB\Operation\Find;
use stdClass; use stdClass;
use function array_intersect_key;
use function fopen;
use function get_resource_type;
use function in_array;
use function is_array;
use function is_bool;
use function is_integer;
use function is_object;
use function is_resource;
use function is_string;
use function method_exists;
use function MongoDB\apply_type_map_to_document;
use function MongoDB\BSON\fromPHP;
use function MongoDB\BSON\toJSON;
use function property_exists;
use function sprintf;
use function stream_context_create;
use function stream_copy_to_stream;
use function stream_get_meta_data;
use function stream_get_wrappers;
use function urlencode;
/** /**
* Bucket provides a public API for interacting with the GridFS files and chunks * Bucket provides a public API for interacting with the GridFS files and chunks
...@@ -42,9 +65,9 @@ class Bucket ...@@ -42,9 +65,9 @@ class Bucket
private static $defaultBucketName = 'fs'; private static $defaultBucketName = 'fs';
private static $defaultChunkSizeBytes = 261120; private static $defaultChunkSizeBytes = 261120;
private static $defaultTypeMap = [ private static $defaultTypeMap = [
'array' => \MongoDB\Model\BSONArray::class, 'array' => BSONArray::class,
'document' => \MongoDB\Model\BSONDocument::class, 'document' => BSONDocument::class,
'root' => \MongoDB\Model\BSONDocument::class, 'root' => BSONDocument::class,
]; ];
private static $streamWrapperProtocol = 'gridfs'; private static $streamWrapperProtocol = 'gridfs';
...@@ -193,7 +216,7 @@ class Bucket ...@@ -193,7 +216,7 @@ class Bucket
*/ */
public function downloadToStream($id, $destination) public function downloadToStream($id, $destination)
{ {
if ( ! is_resource($destination) || get_resource_type($destination) != "stream") { if (! is_resource($destination) || get_resource_type($destination) != "stream") {
throw InvalidArgumentException::invalidType('$destination', $destination, 'resource'); throw InvalidArgumentException::invalidType('$destination', $destination, 'resource');
} }
...@@ -228,7 +251,7 @@ class Bucket ...@@ -228,7 +251,7 @@ class Bucket
*/ */
public function downloadToStreamByName($filename, $destination, array $options = []) public function downloadToStreamByName($filename, $destination, array $options = [])
{ {
if ( ! is_resource($destination) || get_resource_type($destination) != "stream") { if (! is_resource($destination) || get_resource_type($destination) != "stream") {
throw InvalidArgumentException::invalidType('$destination', $destination, 'resource'); throw InvalidArgumentException::invalidType('$destination', $destination, 'resource');
} }
...@@ -333,7 +356,7 @@ class Bucket ...@@ -333,7 +356,7 @@ class Bucket
$file = $this->getRawFileDocumentForStream($stream); $file = $this->getRawFileDocumentForStream($stream);
// Filter the raw document through the specified type map // Filter the raw document through the specified type map
return \MongoDB\apply_type_map_to_document($file, $this->typeMap); return apply_type_map_to_document($file, $this->typeMap);
} }
/** /**
...@@ -353,9 +376,9 @@ class Bucket ...@@ -353,9 +376,9 @@ class Bucket
* the root type so we can reliably access the ID. * the root type so we can reliably access the ID.
*/ */
$typeMap = ['root' => 'stdClass'] + $this->typeMap; $typeMap = ['root' => 'stdClass'] + $this->typeMap;
$file = \MongoDB\apply_type_map_to_document($file, $typeMap); $file = apply_type_map_to_document($file, $typeMap);
if ( ! isset($file->_id) && ! property_exists($file, '_id')) { if (! isset($file->_id) && ! property_exists($file, '_id')) {
throw new CorruptFileException('file._id does not exist'); throw new CorruptFileException('file._id does not exist');
} }
...@@ -532,7 +555,7 @@ class Bucket ...@@ -532,7 +555,7 @@ class Bucket
? $updateResult->getMatchedCount() === 1 ? $updateResult->getMatchedCount() === 1
: $this->collectionWrapper->findFileById($id) !== null; : $this->collectionWrapper->findFileById($id) !== null;
if ( ! $found) { if (! $found) {
throw FileNotFoundException::byId($id, $this->getFilesNamespace()); throw FileNotFoundException::byId($id, $this->getFilesNamespace());
} }
} }
...@@ -562,7 +585,7 @@ class Bucket ...@@ -562,7 +585,7 @@ class Bucket
*/ */
public function uploadFromStream($filename, $source, array $options = []) public function uploadFromStream($filename, $source, array $options = [])
{ {
if ( ! is_resource($source) || get_resource_type($source) != "stream") { if (! is_resource($source) || get_resource_type($source) != "stream") {
throw InvalidArgumentException::invalidType('$source', $source, 'resource'); throw InvalidArgumentException::invalidType('$source', $source, 'resource');
} }
...@@ -580,10 +603,10 @@ class Bucket ...@@ -580,10 +603,10 @@ class Bucket
*/ */
private function createPathForFile(stdClass $file) private function createPathForFile(stdClass $file)
{ {
if ( ! is_object($file->_id) || method_exists($file->_id, '__toString')) { if (! is_object($file->_id) || method_exists($file->_id, '__toString')) {
$id = (string) $file->_id; $id = (string) $file->_id;
} else { } else {
$id = \MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP(['_id' => $file->_id])); $id = toJSON(fromPHP(['_id' => $file->_id]));
} }
return sprintf( return sprintf(
...@@ -632,13 +655,13 @@ class Bucket ...@@ -632,13 +655,13 @@ class Bucket
*/ */
private function getRawFileDocumentForStream($stream) private function getRawFileDocumentForStream($stream)
{ {
if ( ! is_resource($stream) || get_resource_type($stream) != "stream") { if (! is_resource($stream) || get_resource_type($stream) != "stream") {
throw InvalidArgumentException::invalidType('$stream', $stream, 'resource'); throw InvalidArgumentException::invalidType('$stream', $stream, 'resource');
} }
$metadata = stream_get_meta_data($stream); $metadata = stream_get_meta_data($stream);
if ( ! isset ($metadata['wrapper_data']) || ! $metadata['wrapper_data'] instanceof StreamWrapper) { if (! isset($metadata['wrapper_data']) || ! $metadata['wrapper_data'] instanceof StreamWrapper) {
throw InvalidArgumentException::invalidType('$stream wrapper data', isset($metadata['wrapper_data']) ? $metadata['wrapper_data'] : null, StreamWrapper::class); throw InvalidArgumentException::invalidType('$stream wrapper data', isset($metadata['wrapper_data']) ? $metadata['wrapper_data'] : null, StreamWrapper::class);
} }
......
...@@ -18,12 +18,14 @@ ...@@ -18,12 +18,14 @@
namespace MongoDB\GridFS; namespace MongoDB\GridFS;
use MongoDB\Collection; use MongoDB\Collection;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\UpdateResult;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\UpdateResult;
use stdClass; use stdClass;
use function abs;
use function sprintf;
/** /**
* CollectionWrapper abstracts the GridFS files and chunks collections. * CollectionWrapper abstracts the GridFS files and chunks collections.
...@@ -122,7 +124,7 @@ class CollectionWrapper ...@@ -122,7 +124,7 @@ class CollectionWrapper
* *
* @see Bucket::downloadToStreamByName() * @see Bucket::downloadToStreamByName()
* @see Bucket::openDownloadStreamByName() * @see Bucket::openDownloadStreamByName()
* @param string $filename * @param string $filename
* @param integer $revision * @param integer $revision
* @return stdClass|null * @return stdClass|null
*/ */
...@@ -235,7 +237,7 @@ class CollectionWrapper ...@@ -235,7 +237,7 @@ class CollectionWrapper
*/ */
public function insertChunk($chunk) public function insertChunk($chunk)
{ {
if ( ! $this->checkedIndexes) { if (! $this->checkedIndexes) {
$this->ensureIndexes(); $this->ensureIndexes();
} }
...@@ -251,7 +253,7 @@ class CollectionWrapper ...@@ -251,7 +253,7 @@ class CollectionWrapper
*/ */
public function insertFile($file) public function insertFile($file)
{ {
if ( ! $this->checkedIndexes) { if (! $this->checkedIndexes) {
$this->ensureIndexes(); $this->ensureIndexes();
} }
...@@ -262,7 +264,7 @@ class CollectionWrapper ...@@ -262,7 +264,7 @@ class CollectionWrapper
* Updates the filename field in the file document for a given ID. * Updates the filename field in the file document for a given ID.
* *
* @param mixed $id * @param mixed $id
* @param string $filename * @param string $filename
* @return UpdateResult * @return UpdateResult
*/ */
public function updateFilenameForId($id, $filename) public function updateFilenameForId($id, $filename)
...@@ -315,7 +317,7 @@ class CollectionWrapper ...@@ -315,7 +317,7 @@ class CollectionWrapper
$this->checkedIndexes = true; $this->checkedIndexes = true;
if ( ! $this->isFilesCollectionEmpty()) { if (! $this->isFilesCollectionEmpty()) {
return; return;
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
namespace MongoDB\GridFS\Exception; namespace MongoDB\GridFS\Exception;
use MongoDB\Exception\RuntimeException; use MongoDB\Exception\RuntimeException;
use function sprintf;
class CorruptFileException extends RuntimeException class CorruptFileException extends RuntimeException
{ {
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
namespace MongoDB\GridFS\Exception; namespace MongoDB\GridFS\Exception;
use MongoDB\Exception\RuntimeException; use MongoDB\Exception\RuntimeException;
use function MongoDB\BSON\fromPHP;
use function MongoDB\BSON\toJSON;
use function sprintf;
class FileNotFoundException extends RuntimeException class FileNotFoundException extends RuntimeException
{ {
...@@ -43,7 +46,7 @@ class FileNotFoundException extends RuntimeException ...@@ -43,7 +46,7 @@ class FileNotFoundException extends RuntimeException
*/ */
public static function byId($id, $namespace) public static function byId($id, $namespace)
{ {
$json = \MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP(['_id' => $id])); $json = toJSON(fromPHP(['_id' => $id]));
return new static(sprintf('File "%s" not found in "%s"', $json, $namespace)); return new static(sprintf('File "%s" not found in "%s"', $json, $namespace));
} }
......
...@@ -17,10 +17,17 @@ ...@@ -17,10 +17,17 @@
namespace MongoDB\GridFS; namespace MongoDB\GridFS;
use IteratorIterator;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\GridFS\Exception\CorruptFileException; use MongoDB\GridFS\Exception\CorruptFileException;
use IteratorIterator;
use stdClass; use stdClass;
use function ceil;
use function floor;
use function is_integer;
use function property_exists;
use function sprintf;
use function strlen;
use function substr;
/** /**
* ReadableStream abstracts the process of reading a GridFS file. * ReadableStream abstracts the process of reading a GridFS file.
...@@ -49,15 +56,15 @@ class ReadableStream ...@@ -49,15 +56,15 @@ class ReadableStream
*/ */
public function __construct(CollectionWrapper $collectionWrapper, stdClass $file) public function __construct(CollectionWrapper $collectionWrapper, stdClass $file)
{ {
if ( ! isset($file->chunkSize) || ! is_integer($file->chunkSize) || $file->chunkSize < 1) { if (! isset($file->chunkSize) || ! is_integer($file->chunkSize) || $file->chunkSize < 1) {
throw new CorruptFileException('file.chunkSize is not an integer >= 1'); throw new CorruptFileException('file.chunkSize is not an integer >= 1');
} }
if ( ! isset($file->length) || ! is_integer($file->length) || $file->length < 0) { if (! isset($file->length) || ! is_integer($file->length) || $file->length < 0) {
throw new CorruptFileException('file.length is not an integer > 0'); throw new CorruptFileException('file.length is not an integer > 0');
} }
if ( ! isset($file->_id) && ! property_exists($file, '_id')) { if (! isset($file->_id) && ! property_exists($file, '_id')) {
throw new CorruptFileException('file._id does not exist'); throw new CorruptFileException('file._id does not exist');
} }
...@@ -202,6 +209,7 @@ class ReadableStream ...@@ -202,6 +209,7 @@ class ReadableStream
*/ */
if ($lastChunkOffset > $this->chunkOffset) { if ($lastChunkOffset > $this->chunkOffset) {
$this->chunksIterator = null; $this->chunksIterator = null;
return; return;
} }
...@@ -239,7 +247,7 @@ class ReadableStream ...@@ -239,7 +247,7 @@ class ReadableStream
return false; return false;
} }
if ( ! $this->chunksIterator->valid()) { if (! $this->chunksIterator->valid()) {
throw CorruptFileException::missingChunk($this->chunkOffset); throw CorruptFileException::missingChunk($this->chunkOffset);
} }
...@@ -253,7 +261,7 @@ class ReadableStream ...@@ -253,7 +261,7 @@ class ReadableStream
$actualChunkSize = strlen($this->buffer); $actualChunkSize = strlen($this->buffer);
$expectedChunkSize = ($this->chunkOffset === $this->numChunks - 1) $expectedChunkSize = $this->chunkOffset === $this->numChunks - 1
? $this->expectedLastChunkSize ? $this->expectedLastChunkSize
: $this->chunkSize; : $this->chunkSize;
......
...@@ -17,9 +17,24 @@ ...@@ -17,9 +17,24 @@
namespace MongoDB\GridFS; namespace MongoDB\GridFS;
use MongoDB\BSON\UTCDateTime;
use Exception; use Exception;
use MongoDB\BSON\UTCDateTime;
use stdClass; use stdClass;
use function explode;
use function get_class;
use function in_array;
use function is_integer;
use function sprintf;
use function stream_context_get_options;
use function stream_get_wrappers;
use function stream_wrapper_register;
use function stream_wrapper_unregister;
use function trigger_error;
use const E_USER_WARNING;
use const SEEK_CUR;
use const SEEK_END;
use const SEEK_SET;
use const STREAM_IS_URL;
/** /**
* Stream wrapper for reading and writing a GridFS file. * Stream wrapper for reading and writing a GridFS file.
...@@ -60,7 +75,7 @@ class StreamWrapper ...@@ -60,7 +75,7 @@ class StreamWrapper
stream_wrapper_unregister($protocol); stream_wrapper_unregister($protocol);
} }
stream_wrapper_register($protocol, get_called_class(), \STREAM_IS_URL); stream_wrapper_register($protocol, static::class, STREAM_IS_URL);
} }
/** /**
...@@ -81,7 +96,7 @@ class StreamWrapper ...@@ -81,7 +96,7 @@ class StreamWrapper
*/ */
public function stream_eof() public function stream_eof()
{ {
if ( ! $this->stream instanceof ReadableStream) { if (! $this->stream instanceof ReadableStream) {
return false; return false;
} }
...@@ -126,14 +141,15 @@ class StreamWrapper ...@@ -126,14 +141,15 @@ class StreamWrapper
*/ */
public function stream_read($length) public function stream_read($length)
{ {
if ( ! $this->stream instanceof ReadableStream) { if (! $this->stream instanceof ReadableStream) {
return ''; return '';
} }
try { try {
return $this->stream->readBytes($length); return $this->stream->readBytes($length);
} catch (Exception $e) { } catch (Exception $e) {
trigger_error(sprintf('%s: %s', get_class($e), $e->getMessage()), \E_USER_WARNING); trigger_error(sprintf('%s: %s', get_class($e), $e->getMessage()), E_USER_WARNING);
return false; return false;
} }
} }
...@@ -146,15 +162,15 @@ class StreamWrapper ...@@ -146,15 +162,15 @@ class StreamWrapper
* @param integer $whence One of SEEK_SET, SEEK_CUR, or SEEK_END * @param integer $whence One of SEEK_SET, SEEK_CUR, or SEEK_END
* @return boolean True if the position was updated and false otherwise * @return boolean True if the position was updated and false otherwise
*/ */
public function stream_seek($offset, $whence = \SEEK_SET) public function stream_seek($offset, $whence = SEEK_SET)
{ {
$size = $this->stream->getSize(); $size = $this->stream->getSize();
if ($whence === \SEEK_CUR) { if ($whence === SEEK_CUR) {
$offset += $this->stream->tell(); $offset += $this->stream->tell();
} }
if ($whence === \SEEK_END) { if ($whence === SEEK_END) {
$offset += $size; $offset += $size;
} }
...@@ -222,14 +238,15 @@ class StreamWrapper ...@@ -222,14 +238,15 @@ class StreamWrapper
*/ */
public function stream_write($data) public function stream_write($data)
{ {
if ( ! $this->stream instanceof WritableStream) { if (! $this->stream instanceof WritableStream) {
return 0; return 0;
} }
try { try {
return $this->stream->writeBytes($data); return $this->stream->writeBytes($data);
} catch (Exception $e) { } catch (Exception $e) {
trigger_error(sprintf('%s: %s', get_class($e), $e->getMessage()), \E_USER_WARNING); trigger_error(sprintf('%s: %s', get_class($e), $e->getMessage()), E_USER_WARNING);
return false; return false;
} }
} }
......
...@@ -23,6 +23,19 @@ use MongoDB\BSON\UTCDateTime; ...@@ -23,6 +23,19 @@ use MongoDB\BSON\UTCDateTime;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use stdClass; use stdClass;
use function array_intersect_key;
use function hash_final;
use function hash_init;
use function hash_update;
use function is_array;
use function is_bool;
use function is_integer;
use function is_object;
use function is_string;
use function MongoDB\is_string_array;
use function sprintf;
use function strlen;
use function substr;
/** /**
* WritableStream abstracts the process of writing a GridFS file. * WritableStream abstracts the process of writing a GridFS file.
...@@ -74,12 +87,12 @@ class WritableStream ...@@ -74,12 +87,12 @@ class WritableStream
public function __construct(CollectionWrapper $collectionWrapper, $filename, array $options = []) public function __construct(CollectionWrapper $collectionWrapper, $filename, array $options = [])
{ {
$options += [ $options += [
'_id' => new ObjectId, '_id' => new ObjectId(),
'chunkSizeBytes' => self::$defaultChunkSizeBytes, 'chunkSizeBytes' => self::$defaultChunkSizeBytes,
'disableMD5' => false, 'disableMD5' => false,
]; ];
if (isset($options['aliases']) && ! \MongoDB\is_string_array($options['aliases'])) { if (isset($options['aliases']) && ! is_string_array($options['aliases'])) {
throw InvalidArgumentException::invalidType('"aliases" option', $options['aliases'], 'array of strings'); throw InvalidArgumentException::invalidType('"aliases" option', $options['aliases'], 'array of strings');
} }
...@@ -107,7 +120,7 @@ class WritableStream ...@@ -107,7 +120,7 @@ class WritableStream
$this->collectionWrapper = $collectionWrapper; $this->collectionWrapper = $collectionWrapper;
$this->disableMD5 = $options['disableMD5']; $this->disableMD5 = $options['disableMD5'];
if ( ! $this->disableMD5) { if (! $this->disableMD5) {
$this->hashCtx = hash_init('md5'); $this->hashCtx = hash_init('md5');
} }
...@@ -233,9 +246,9 @@ class WritableStream ...@@ -233,9 +246,9 @@ class WritableStream
private function fileCollectionInsert() private function fileCollectionInsert()
{ {
$this->file['length'] = $this->length; $this->file['length'] = $this->length;
$this->file['uploadDate'] = new UTCDateTime; $this->file['uploadDate'] = new UTCDateTime();
if ( ! $this->disableMD5) { if (! $this->disableMD5) {
$this->file['md5'] = hash_final($this->hashCtx); $this->file['md5'] = hash_final($this->hashCtx);
} }
...@@ -265,7 +278,7 @@ class WritableStream ...@@ -265,7 +278,7 @@ class WritableStream
'data' => new Binary($data, Binary::TYPE_GENERIC), 'data' => new Binary($data, Binary::TYPE_GENERIC),
]; ];
if ( ! $this->disableMD5) { if (! $this->disableMD5) {
hash_update($this->hashCtx, $data); hash_update($this->hashCtx, $data);
} }
......
...@@ -30,8 +30,6 @@ class InsertManyResult ...@@ -30,8 +30,6 @@ class InsertManyResult
private $isAcknowledged; private $isAcknowledged;
/** /**
* Constructor.
*
* @param WriteResult $writeResult * @param WriteResult $writeResult
* @param mixed[] $insertedIds * @param mixed[] $insertedIds
*/ */
......
...@@ -30,8 +30,6 @@ class InsertOneResult ...@@ -30,8 +30,6 @@ class InsertOneResult
private $isAcknowledged; private $isAcknowledged;
/** /**
* Constructor.
*
* @param WriteResult $writeResult * @param WriteResult $writeResult
* @param mixed $insertedId * @param mixed $insertedId
*/ */
......
...@@ -20,6 +20,7 @@ namespace MongoDB; ...@@ -20,6 +20,7 @@ namespace MongoDB;
use IteratorAggregate; use IteratorAggregate;
use stdClass; use stdClass;
use Traversable; use Traversable;
use function call_user_func;
/** /**
* Result class for mapReduce command results. * Result class for mapReduce command results.
...@@ -40,8 +41,6 @@ class MapReduceResult implements IteratorAggregate ...@@ -40,8 +41,6 @@ class MapReduceResult implements IteratorAggregate
private $timing; private $timing;
/** /**
* Constructor.
*
* @internal * @internal
* @param callable $getIterator Callback that returns a Traversable for mapReduce results * @param callable $getIterator Callback that returns a Traversable for mapReduce results
* @param stdClass $result Result document from the mapReduce command * @param stdClass $result Result document from the mapReduce command
......
...@@ -17,10 +17,12 @@ ...@@ -17,10 +17,12 @@
namespace MongoDB\Model; namespace MongoDB\Model;
use MongoDB\BSON\Serializable;
use MongoDB\BSON\Unserializable;
use ArrayObject; use ArrayObject;
use JsonSerializable; use JsonSerializable;
use MongoDB\BSON\Serializable;
use MongoDB\BSON\Unserializable;
use function array_values;
use function MongoDB\recursive_copy;
/** /**
* Model class for a BSON array. * Model class for a BSON array.
...@@ -38,7 +40,7 @@ class BSONArray extends ArrayObject implements JsonSerializable, Serializable, U ...@@ -38,7 +40,7 @@ class BSONArray extends ArrayObject implements JsonSerializable, Serializable, U
public function __clone() public function __clone()
{ {
foreach ($this as $key => $value) { foreach ($this as $key => $value) {
$this[$key] = \MongoDB\recursive_copy($value); $this[$key] = recursive_copy($value);
} }
} }
...@@ -52,7 +54,7 @@ class BSONArray extends ArrayObject implements JsonSerializable, Serializable, U ...@@ -52,7 +54,7 @@ class BSONArray extends ArrayObject implements JsonSerializable, Serializable, U
*/ */
public static function __set_state(array $properties) public static function __set_state(array $properties)
{ {
$array = new static; $array = new static();
$array->exchangeArray($properties); $array->exchangeArray($properties);
return $array; return $array;
......
...@@ -17,10 +17,11 @@ ...@@ -17,10 +17,11 @@
namespace MongoDB\Model; namespace MongoDB\Model;
use MongoDB\BSON\Serializable;
use MongoDB\BSON\Unserializable;
use ArrayObject; use ArrayObject;
use JsonSerializable; use JsonSerializable;
use MongoDB\BSON\Serializable;
use MongoDB\BSON\Unserializable;
use function MongoDB\recursive_copy;
/** /**
* Model class for a BSON document. * Model class for a BSON document.
...@@ -38,13 +39,11 @@ class BSONDocument extends ArrayObject implements JsonSerializable, Serializable ...@@ -38,13 +39,11 @@ class BSONDocument extends ArrayObject implements JsonSerializable, Serializable
public function __clone() public function __clone()
{ {
foreach ($this as $key => $value) { foreach ($this as $key => $value) {
$this[$key] = \MongoDB\recursive_copy($value); $this[$key] = recursive_copy($value);
} }
} }
/** /**
* Constructor.
*
* This overrides the parent constructor to allow property access of entries * This overrides the parent constructor to allow property access of entries
* by default. * by default.
* *
...@@ -68,7 +67,7 @@ class BSONDocument extends ArrayObject implements JsonSerializable, Serializable ...@@ -68,7 +67,7 @@ class BSONDocument extends ArrayObject implements JsonSerializable, Serializable
*/ */
public static function __set_state(array $properties) public static function __set_state(array $properties)
{ {
$document = new static; $document = new static();
$document->exchangeArray($properties); $document->exchangeArray($properties);
return $document; return $document;
......
...@@ -17,10 +17,15 @@ ...@@ -17,10 +17,15 @@
namespace MongoDB\Model; namespace MongoDB\Model;
use Iterator;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Model\BSONDocument; use function is_array;
use Iterator; use function MongoDB\BSON\toPHP;
use function sprintf;
use function strlen;
use function substr;
use function unpack;
/** /**
* Iterator for BSON documents. * Iterator for BSON documents.
...@@ -55,7 +60,7 @@ class BSONIterator implements Iterator ...@@ -55,7 +60,7 @@ class BSONIterator implements Iterator
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array'); throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
} }
if ( ! isset($options['typeMap'])) { if (! isset($options['typeMap'])) {
$options['typeMap'] = []; $options['typeMap'] = [];
} }
...@@ -130,7 +135,7 @@ class BSONIterator implements Iterator ...@@ -130,7 +135,7 @@ class BSONIterator implements Iterator
throw new UnexpectedValueException(sprintf('Expected %d bytes; %d remaining', $documentLength, $this->bufferLength - $this->position)); throw new UnexpectedValueException(sprintf('Expected %d bytes; %d remaining', $documentLength, $this->bufferLength - $this->position));
} }
$this->current = \MongoDB\BSON\toPHP(substr($this->buffer, $this->position, $documentLength), $this->options['typeMap']); $this->current = toPHP(substr($this->buffer, $this->position, $documentLength), $this->options['typeMap']);
$this->position += $documentLength; $this->position += $documentLength;
} }
} }
...@@ -21,6 +21,11 @@ use Countable; ...@@ -21,6 +21,11 @@ use Countable;
use Generator; use Generator;
use Iterator; use Iterator;
use Traversable; use Traversable;
use function count;
use function current;
use function key;
use function next;
use function reset;
/** /**
* Iterator for wrapping a Traversable and caching its results. * Iterator for wrapping a Traversable and caching its results.
...@@ -39,8 +44,6 @@ class CachingIterator implements Countable, Iterator ...@@ -39,8 +44,6 @@ class CachingIterator implements Countable, Iterator
private $iteratorExhausted = false; private $iteratorExhausted = false;
/** /**
* Constructor.
*
* Initialize the iterator and stores the first item in the cache. This * Initialize the iterator and stores the first item in the cache. This
* effectively rewinds the Traversable and the wrapping Generator, which * effectively rewinds the Traversable and the wrapping Generator, which
* will execute up to its first yield statement. Additionally, this mimics * will execute up to its first yield statement. Additionally, this mimics
...@@ -90,7 +93,7 @@ class CachingIterator implements Countable, Iterator ...@@ -90,7 +93,7 @@ class CachingIterator implements Countable, Iterator
*/ */
public function next() public function next()
{ {
if ( ! $this->iteratorExhausted) { if (! $this->iteratorExhausted) {
$this->iterator->next(); $this->iterator->next();
$this->storeCurrentItem(); $this->storeCurrentItem();
} }
...@@ -128,7 +131,7 @@ class CachingIterator implements Countable, Iterator ...@@ -128,7 +131,7 @@ class CachingIterator implements Countable, Iterator
*/ */
private function exhaustIterator() private function exhaustIterator()
{ {
while ( ! $this->iteratorExhausted) { while (! $this->iteratorExhausted) {
$this->next(); $this->next();
} }
} }
......
...@@ -17,16 +17,22 @@ ...@@ -17,16 +17,22 @@
namespace MongoDB\Model; namespace MongoDB\Model;
use IteratorIterator;
use MongoDB\BSON\Serializable; use MongoDB\BSON\Serializable;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Monitoring\CommandFailedEvent; use MongoDB\Driver\Monitoring\CommandFailedEvent;
use MongoDB\Driver\Monitoring\CommandSubscriber;
use MongoDB\Driver\Monitoring\CommandStartedEvent; use MongoDB\Driver\Monitoring\CommandStartedEvent;
use MongoDB\Driver\Monitoring\CommandSubscriber;
use MongoDB\Driver\Monitoring\CommandSucceededEvent; use MongoDB\Driver\Monitoring\CommandSucceededEvent;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\ResumeTokenException; use MongoDB\Exception\ResumeTokenException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use IteratorIterator; use function count;
use function is_array;
use function is_integer;
use function is_object;
use function MongoDB\Driver\Monitoring\addSubscriber;
use function MongoDB\Driver\Monitoring\removeSubscriber;
/** /**
* ChangeStreamIterator wraps a change stream's tailable cursor. * ChangeStreamIterator wraps a change stream's tailable cursor.
...@@ -46,8 +52,6 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber ...@@ -46,8 +52,6 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
private $resumeToken; private $resumeToken;
/** /**
* Constructor.
*
* @internal * @internal
* @param Cursor $cursor * @param Cursor $cursor
* @param integer $firstBatchSize * @param integer $firstBatchSize
...@@ -56,7 +60,7 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber ...@@ -56,7 +60,7 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
*/ */
public function __construct(Cursor $cursor, $firstBatchSize, $initialResumeToken, $postBatchResumeToken) public function __construct(Cursor $cursor, $firstBatchSize, $initialResumeToken, $postBatchResumeToken)
{ {
if ( ! is_integer($firstBatchSize)) { if (! is_integer($firstBatchSize)) {
throw InvalidArgumentException::invalidType('$firstBatchSize', $firstBatchSize, 'integer'); throw InvalidArgumentException::invalidType('$firstBatchSize', $firstBatchSize, 'integer');
} }
...@@ -102,7 +106,7 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber ...@@ -102,7 +106,7 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
$reply = $event->getReply(); $reply = $event->getReply();
if ( ! isset($reply->cursor->nextBatch) || ! is_array($reply->cursor->nextBatch)) { if (! isset($reply->cursor->nextBatch) || ! is_array($reply->cursor->nextBatch)) {
throw new UnexpectedValueException('getMore command did not return a "cursor.nextBatch" array'); throw new UnexpectedValueException('getMore command did not return a "cursor.nextBatch" array');
} }
...@@ -141,15 +145,15 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber ...@@ -141,15 +145,15 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
$getMore = $this->isAtEndOfBatch(); $getMore = $this->isAtEndOfBatch();
if ($getMore) { if ($getMore) {
\MongoDB\Driver\Monitoring\addSubscriber($this); addSubscriber($this);
} }
try { try {
parent::next(); parent::next();
$this->onIteration(!$getMore); $this->onIteration(! $getMore);
} finally { } finally {
if ($getMore) { if ($getMore) {
\MongoDB\Driver\Monitoring\removeSubscriber($this); removeSubscriber($this);
} }
} }
} }
...@@ -178,7 +182,7 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber ...@@ -178,7 +182,7 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
*/ */
private function extractResumeToken($document) private function extractResumeToken($document)
{ {
if ( ! is_array($document) && ! is_object($document)) { if (! is_array($document) && ! is_object($document)) {
throw InvalidArgumentException::invalidType('$document', $document, 'array or object'); throw InvalidArgumentException::invalidType('$document', $document, 'array or object');
} }
...@@ -190,11 +194,11 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber ...@@ -190,11 +194,11 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
? (isset($document['_id']) ? $document['_id'] : null) ? (isset($document['_id']) ? $document['_id'] : null)
: (isset($document->_id) ? $document->_id : null); : (isset($document->_id) ? $document->_id : null);
if ( ! isset($resumeToken)) { if (! isset($resumeToken)) {
throw ResumeTokenException::notFound(); throw ResumeTokenException::notFound();
} }
if ( ! is_array($resumeToken) && ! is_object($resumeToken)) { if (! is_array($resumeToken) && ! is_object($resumeToken)) {
throw ResumeTokenException::invalidType($resumeToken); throw ResumeTokenException::invalidType($resumeToken);
} }
...@@ -208,7 +212,7 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber ...@@ -208,7 +212,7 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
*/ */
private function isAtEndOfBatch() private function isAtEndOfBatch()
{ {
return ($this->batchPosition + 1 >= $this->batchSize); return $this->batchPosition + 1 >= $this->batchSize;
} }
/** /**
......
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
namespace MongoDB\Model; namespace MongoDB\Model;
use MongoDB\Exception\BadMethodCallException;
use ArrayAccess; use ArrayAccess;
use MongoDB\Exception\BadMethodCallException;
use function array_key_exists;
/** /**
* Collection information model class. * Collection information model class.
...@@ -36,8 +37,6 @@ class CollectionInfo implements ArrayAccess ...@@ -36,8 +37,6 @@ class CollectionInfo implements ArrayAccess
private $info; private $info;
/** /**
* Constructor.
*
* @param array $info Collection info * @param array $info Collection info
*/ */
public function __construct(array $info) public function __construct(array $info)
...@@ -142,7 +141,7 @@ class CollectionInfo implements ArrayAccess ...@@ -142,7 +141,7 @@ class CollectionInfo implements ArrayAccess
*/ */
public function offsetSet($key, $value) public function offsetSet($key, $value)
{ {
throw BadMethodCallException::classIsImmutable(__CLASS__); throw BadMethodCallException::classIsImmutable(self::class);
} }
/** /**
...@@ -154,6 +153,6 @@ class CollectionInfo implements ArrayAccess ...@@ -154,6 +153,6 @@ class CollectionInfo implements ArrayAccess
*/ */
public function offsetUnset($key) public function offsetUnset($key)
{ {
throw BadMethodCallException::classIsImmutable(__CLASS__); throw BadMethodCallException::classIsImmutable(self::class);
} }
} }
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
namespace MongoDB\Model; namespace MongoDB\Model;
use MongoDB\Exception\BadMethodCallException;
use ArrayAccess; use ArrayAccess;
use MongoDB\Exception\BadMethodCallException;
use function array_key_exists;
/** /**
* Database information model class. * Database information model class.
* *
...@@ -34,8 +36,6 @@ class DatabaseInfo implements ArrayAccess ...@@ -34,8 +36,6 @@ class DatabaseInfo implements ArrayAccess
private $info; private $info;
/** /**
* Constructor.
*
* @param array $info Database info * @param array $info Database info
*/ */
public function __construct(array $info) public function __construct(array $info)
...@@ -119,7 +119,7 @@ class DatabaseInfo implements ArrayAccess ...@@ -119,7 +119,7 @@ class DatabaseInfo implements ArrayAccess
*/ */
public function offsetSet($key, $value) public function offsetSet($key, $value)
{ {
throw BadMethodCallException::classIsImmutable(__CLASS__); throw BadMethodCallException::classIsImmutable(self::class);
} }
/** /**
...@@ -131,6 +131,6 @@ class DatabaseInfo implements ArrayAccess ...@@ -131,6 +131,6 @@ class DatabaseInfo implements ArrayAccess
*/ */
public function offsetUnset($key) public function offsetUnset($key)
{ {
throw BadMethodCallException::classIsImmutable(__CLASS__); throw BadMethodCallException::classIsImmutable(self::class);
} }
} }
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
namespace MongoDB\Model; namespace MongoDB\Model;
use function current;
use function key;
use function next;
use function reset;
/** /**
* DatabaseInfoIterator for inline listDatabases command results. * DatabaseInfoIterator for inline listDatabases command results.
* *
...@@ -32,8 +37,6 @@ class DatabaseInfoLegacyIterator implements DatabaseInfoIterator ...@@ -32,8 +37,6 @@ class DatabaseInfoLegacyIterator implements DatabaseInfoIterator
private $databases; private $databases;
/** /**
* Constructor.
*
* @param array $databases * @param array $databases
*/ */
public function __construct(array $databases) public function __construct(array $databases)
......
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
namespace MongoDB\Model; namespace MongoDB\Model;
use MongoDB\Exception\BadMethodCallException;
use ArrayAccess; use ArrayAccess;
use MongoDB\Exception\BadMethodCallException;
use function array_key_exists;
use function array_search;
/** /**
* Index information model class. * Index information model class.
...@@ -40,8 +42,6 @@ class IndexInfo implements ArrayAccess ...@@ -40,8 +42,6 @@ class IndexInfo implements ArrayAccess
private $info; private $info;
/** /**
* Constructor.
*
* @param array $info Index info * @param array $info Index info
*/ */
public function __construct(array $info) public function __construct(array $info)
...@@ -212,7 +212,7 @@ class IndexInfo implements ArrayAccess ...@@ -212,7 +212,7 @@ class IndexInfo implements ArrayAccess
*/ */
public function offsetSet($key, $value) public function offsetSet($key, $value)
{ {
throw BadMethodCallException::classIsImmutable(__CLASS__); throw BadMethodCallException::classIsImmutable(self::class);
} }
/** /**
...@@ -224,6 +224,6 @@ class IndexInfo implements ArrayAccess ...@@ -224,6 +224,6 @@ class IndexInfo implements ArrayAccess
*/ */
public function offsetUnset($key) public function offsetUnset($key)
{ {
throw BadMethodCallException::classIsImmutable(__CLASS__); throw BadMethodCallException::classIsImmutable(self::class);
} }
} }
...@@ -19,6 +19,13 @@ namespace MongoDB\Model; ...@@ -19,6 +19,13 @@ namespace MongoDB\Model;
use MongoDB\BSON\Serializable; use MongoDB\BSON\Serializable;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use function is_array;
use function is_float;
use function is_int;
use function is_object;
use function is_string;
use function MongoDB\generate_index_name;
use function sprintf;
/** /**
* Index input model class. * Index input model class.
...@@ -35,40 +42,38 @@ class IndexInput implements Serializable ...@@ -35,40 +42,38 @@ class IndexInput implements Serializable
private $index; private $index;
/** /**
* Constructor.
*
* @param array $index Index specification * @param array $index Index specification
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function __construct(array $index) public function __construct(array $index)
{ {
if ( ! isset($index['key'])) { if (! isset($index['key'])) {
throw new InvalidArgumentException('Required "key" document is missing from index specification'); throw new InvalidArgumentException('Required "key" document is missing from index specification');
} }
if ( ! is_array($index['key']) && ! is_object($index['key'])) { if (! is_array($index['key']) && ! is_object($index['key'])) {
throw InvalidArgumentException::invalidType('"key" option', $index['key'], 'array or object'); throw InvalidArgumentException::invalidType('"key" option', $index['key'], 'array or object');
} }
foreach ($index['key'] as $fieldName => $order) { foreach ($index['key'] as $fieldName => $order) {
if ( ! is_int($order) && ! is_float($order) && ! is_string($order)) { if (! is_int($order) && ! is_float($order) && ! is_string($order)) {
throw InvalidArgumentException::invalidType(sprintf('order value for "%s" field within "key" option', $fieldName), $order, 'numeric or string'); throw InvalidArgumentException::invalidType(sprintf('order value for "%s" field within "key" option', $fieldName), $order, 'numeric or string');
} }
} }
if ( ! isset($index['ns'])) { if (! isset($index['ns'])) {
throw new InvalidArgumentException('Required "ns" option is missing from index specification'); throw new InvalidArgumentException('Required "ns" option is missing from index specification');
} }
if ( ! is_string($index['ns'])) { if (! is_string($index['ns'])) {
throw InvalidArgumentException::invalidType('"ns" option', $index['ns'], 'string'); throw InvalidArgumentException::invalidType('"ns" option', $index['ns'], 'string');
} }
if ( ! isset($index['name'])) { if (! isset($index['name'])) {
$index['name'] = \MongoDB\generate_index_name($index['key']); $index['name'] = generate_index_name($index['key']);
} }
if ( ! is_string($index['name'])) { if (! is_string($index['name'])) {
throw InvalidArgumentException::invalidType('"name" option', $index['name'], 'string'); throw InvalidArgumentException::invalidType('"name" option', $index['name'], 'string');
} }
......
...@@ -17,19 +17,29 @@ ...@@ -17,19 +17,29 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use ArrayIterator;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use ArrayIterator;
use stdClass; use stdClass;
use Traversable; use Traversable;
use function current;
use function is_array;
use function is_bool;
use function is_integer;
use function is_object;
use function is_string;
use function MongoDB\create_field_path_type_map;
use function MongoDB\is_last_pipeline_operator_write;
use function MongoDB\server_supports_feature;
use function sprintf;
/** /**
* Operation for the aggregate command. * Operation for the aggregate command.
...@@ -132,7 +142,7 @@ class Aggregate implements Executable ...@@ -132,7 +142,7 @@ class Aggregate implements Executable
throw new InvalidArgumentException(sprintf('$pipeline is not a list (unexpected index: "%s")', $i)); throw new InvalidArgumentException(sprintf('$pipeline is not a list (unexpected index: "%s")', $i));
} }
if ( ! is_array($operation) && ! is_object($operation)) { if (! is_array($operation) && ! is_object($operation)) {
throw InvalidArgumentException::invalidType(sprintf('$pipeline[%d]', $i), $operation, 'array or object'); throw InvalidArgumentException::invalidType(sprintf('$pipeline[%d]', $i), $operation, 'array or object');
} }
...@@ -144,7 +154,7 @@ class Aggregate implements Executable ...@@ -144,7 +154,7 @@ class Aggregate implements Executable
'useCursor' => true, 'useCursor' => true,
]; ];
if ( ! is_bool($options['allowDiskUse'])) { if (! is_bool($options['allowDiskUse'])) {
throw InvalidArgumentException::invalidType('"allowDiskUse" option', $options['allowDiskUse'], 'boolean'); throw InvalidArgumentException::invalidType('"allowDiskUse" option', $options['allowDiskUse'], 'boolean');
} }
...@@ -196,7 +206,7 @@ class Aggregate implements Executable ...@@ -196,7 +206,7 @@ class Aggregate implements Executable
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array'); throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
} }
if ( ! is_bool($options['useCursor'])) { if (! is_bool($options['useCursor'])) {
throw InvalidArgumentException::invalidType('"useCursor" option', $options['useCursor'], 'boolean'); throw InvalidArgumentException::invalidType('"useCursor" option', $options['useCursor'], 'boolean');
} }
...@@ -216,7 +226,7 @@ class Aggregate implements Executable ...@@ -216,7 +226,7 @@ class Aggregate implements Executable
unset($options['writeConcern']); unset($options['writeConcern']);
} }
if ( ! empty($options['explain'])) { if (! empty($options['explain'])) {
$options['useCursor'] = false; $options['useCursor'] = false;
} }
...@@ -238,15 +248,15 @@ class Aggregate implements Executable ...@@ -238,15 +248,15 @@ class Aggregate implements Executable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { if (isset($this->options['collation']) && ! server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { if (isset($this->options['readConcern']) && ! server_supports_feature($server, self::$wireVersionForReadConcern)) {
throw UnsupportedException::readConcernNotSupported(); throw UnsupportedException::readConcernNotSupported();
} }
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) { if (isset($this->options['writeConcern']) && ! server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported(); throw UnsupportedException::writeConcernNotSupported();
} }
...@@ -260,14 +270,13 @@ class Aggregate implements Executable ...@@ -260,14 +270,13 @@ class Aggregate implements Executable
} }
} }
$hasExplain = ! empty($this->options['explain']); $hasExplain = ! empty($this->options['explain']);
$hasWriteStage = \MongoDB\is_last_pipeline_operator_write($this->pipeline); $hasWriteStage = is_last_pipeline_operator_write($this->pipeline);
$command = $this->createCommand($server, $hasWriteStage); $command = $this->createCommand($server, $hasWriteStage);
$options = $this->createOptions($hasWriteStage, $hasExplain); $options = $this->createOptions($hasWriteStage, $hasExplain);
$cursor = ($hasWriteStage && ! $hasExplain) $cursor = $hasWriteStage && ! $hasExplain
? $server->executeReadWriteCommand($this->databaseName, $command, $options) ? $server->executeReadWriteCommand($this->databaseName, $command, $options)
: $server->executeReadCommand($this->databaseName, $command, $options); : $server->executeReadCommand($this->databaseName, $command, $options);
...@@ -280,12 +289,12 @@ class Aggregate implements Executable ...@@ -280,12 +289,12 @@ class Aggregate implements Executable
} }
if (isset($this->options['typeMap'])) { if (isset($this->options['typeMap'])) {
$cursor->setTypeMap(\MongoDB\create_field_path_type_map($this->options['typeMap'], 'result.$')); $cursor->setTypeMap(create_field_path_type_map($this->options['typeMap'], 'result.$'));
} }
$result = current($cursor->toArray()); $result = current($cursor->toArray());
if ( ! isset($result->result) || ! is_array($result->result)) { if (! isset($result->result) || ! is_array($result->result)) {
throw new UnexpectedValueException('aggregate command did not return a "result" array'); throw new UnexpectedValueException('aggregate command did not return a "result" array');
} }
...@@ -309,9 +318,8 @@ class Aggregate implements Executable ...@@ -309,9 +318,8 @@ class Aggregate implements Executable
$cmd['allowDiskUse'] = $this->options['allowDiskUse']; $cmd['allowDiskUse'] = $this->options['allowDiskUse'];
if ( if (! empty($this->options['bypassDocumentValidation']) &&
! empty($this->options['bypassDocumentValidation']) && server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) { ) {
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
...@@ -338,9 +346,9 @@ class Aggregate implements Executable ...@@ -338,9 +346,9 @@ class Aggregate implements Executable
/* Ignore batchSize if pipeline includes an $out or $merge stage, as /* Ignore batchSize if pipeline includes an $out or $merge stage, as
* no documents will be returned and sending a batchSize of zero * no documents will be returned and sending a batchSize of zero
* could prevent the pipeline from executing at all. */ * could prevent the pipeline from executing at all. */
$cmd['cursor'] = isset($this->options["batchSize"]) && !$hasWriteStage $cmd['cursor'] = isset($this->options["batchSize"]) && ! $hasWriteStage
? ['batchSize' => $this->options["batchSize"]] ? ['batchSize' => $this->options["batchSize"]]
: new stdClass; : new stdClass();
} }
return new Command($cmd, $cmdOptions); return new Command($cmd, $cmdOptions);
...@@ -363,7 +371,7 @@ class Aggregate implements Executable ...@@ -363,7 +371,7 @@ class Aggregate implements Executable
$options['readConcern'] = $this->options['readConcern']; $options['readConcern'] = $this->options['readConcern'];
} }
if (!$hasWriteStage && isset($this->options['readPreference'])) { if (! $hasWriteStage && isset($this->options['readPreference'])) {
$options['readPreference'] = $this->options['readPreference']; $options['readPreference'] = $this->options['readPreference'];
} }
......
...@@ -19,12 +19,22 @@ namespace MongoDB\Operation; ...@@ -19,12 +19,22 @@ namespace MongoDB\Operation;
use MongoDB\BulkWriteResult; use MongoDB\BulkWriteResult;
use MongoDB\Driver\BulkWrite as Bulk; use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function array_key_exists;
use function count;
use function current;
use function is_array;
use function is_bool;
use function is_object;
use function key;
use function MongoDB\is_first_key_operator;
use function MongoDB\server_supports_feature;
use function sprintf;
/** /**
* Operation for executing multiple write operations. * Operation for executing multiple write operations.
...@@ -132,7 +142,7 @@ class BulkWrite implements Executable ...@@ -132,7 +142,7 @@ class BulkWrite implements Executable
throw new InvalidArgumentException(sprintf('$operations is not a list (unexpected index: "%s")', $i)); throw new InvalidArgumentException(sprintf('$operations is not a list (unexpected index: "%s")', $i));
} }
if ( ! is_array($operation)) { if (! is_array($operation)) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]', $i), $operation, 'array'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]', $i), $operation, 'array');
} }
...@@ -143,11 +153,11 @@ class BulkWrite implements Executable ...@@ -143,11 +153,11 @@ class BulkWrite implements Executable
$type = key($operation); $type = key($operation);
$args = current($operation); $args = current($operation);
if ( ! isset($args[0]) && ! array_key_exists(0, $args)) { if (! isset($args[0]) && ! array_key_exists(0, $args)) {
throw new InvalidArgumentException(sprintf('Missing first argument for $operations[%d]["%s"]', $i, $type)); throw new InvalidArgumentException(sprintf('Missing first argument for $operations[%d]["%s"]', $i, $type));
} }
if ( ! is_array($args[0]) && ! is_object($args[0])) { if (! is_array($args[0]) && ! is_object($args[0])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][0]', $i, $type), $args[0], 'array or object'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][0]', $i, $type), $args[0], 'array or object');
} }
...@@ -157,11 +167,11 @@ class BulkWrite implements Executable ...@@ -157,11 +167,11 @@ class BulkWrite implements Executable
case self::DELETE_MANY: case self::DELETE_MANY:
case self::DELETE_ONE: case self::DELETE_ONE:
if ( ! isset($args[1])) { if (! isset($args[1])) {
$args[1] = []; $args[1] = [];
} }
if ( ! is_array($args[1])) { if (! is_array($args[1])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][1]', $i, $type), $args[1], 'array'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][1]', $i, $type), $args[1], 'array');
} }
...@@ -170,7 +180,7 @@ class BulkWrite implements Executable ...@@ -170,7 +180,7 @@ class BulkWrite implements Executable
if (isset($args[1]['collation'])) { if (isset($args[1]['collation'])) {
$this->isCollationUsed = true; $this->isCollationUsed = true;
if ( ! is_array($args[1]['collation']) && ! is_object($args[1]['collation'])) { if (! is_array($args[1]['collation']) && ! is_object($args[1]['collation'])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][1]["collation"]', $i, $type), $args[1]['collation'], 'array or object'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][1]["collation"]', $i, $type), $args[1]['collation'], 'array or object');
} }
} }
...@@ -180,23 +190,23 @@ class BulkWrite implements Executable ...@@ -180,23 +190,23 @@ class BulkWrite implements Executable
break; break;
case self::REPLACE_ONE: case self::REPLACE_ONE:
if ( ! isset($args[1]) && ! array_key_exists(1, $args)) { if (! isset($args[1]) && ! array_key_exists(1, $args)) {
throw new InvalidArgumentException(sprintf('Missing second argument for $operations[%d]["%s"]', $i, $type)); throw new InvalidArgumentException(sprintf('Missing second argument for $operations[%d]["%s"]', $i, $type));
} }
if ( ! is_array($args[1]) && ! is_object($args[1])) { if (! is_array($args[1]) && ! is_object($args[1])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][1]', $i, $type), $args[1], 'array or object'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][1]', $i, $type), $args[1], 'array or object');
} }
if (\MongoDB\is_first_key_operator($args[1])) { if (is_first_key_operator($args[1])) {
throw new InvalidArgumentException(sprintf('First key in $operations[%d]["%s"][1] is an update operator', $i, $type)); throw new InvalidArgumentException(sprintf('First key in $operations[%d]["%s"][1] is an update operator', $i, $type));
} }
if ( ! isset($args[2])) { if (! isset($args[2])) {
$args[2] = []; $args[2] = [];
} }
if ( ! is_array($args[2])) { if (! is_array($args[2])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]', $i, $type), $args[2], 'array'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]', $i, $type), $args[2], 'array');
} }
...@@ -206,12 +216,12 @@ class BulkWrite implements Executable ...@@ -206,12 +216,12 @@ class BulkWrite implements Executable
if (isset($args[2]['collation'])) { if (isset($args[2]['collation'])) {
$this->isCollationUsed = true; $this->isCollationUsed = true;
if ( ! is_array($args[2]['collation']) && ! is_object($args[2]['collation'])) { if (! is_array($args[2]['collation']) && ! is_object($args[2]['collation'])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["collation"]', $i, $type), $args[2]['collation'], 'array or object'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["collation"]', $i, $type), $args[2]['collation'], 'array or object');
} }
} }
if ( ! is_bool($args[2]['upsert'])) { if (! is_bool($args[2]['upsert'])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean');
} }
...@@ -221,23 +231,23 @@ class BulkWrite implements Executable ...@@ -221,23 +231,23 @@ class BulkWrite implements Executable
case self::UPDATE_MANY: case self::UPDATE_MANY:
case self::UPDATE_ONE: case self::UPDATE_ONE:
if ( ! isset($args[1]) && ! array_key_exists(1, $args)) { if (! isset($args[1]) && ! array_key_exists(1, $args)) {
throw new InvalidArgumentException(sprintf('Missing second argument for $operations[%d]["%s"]', $i, $type)); throw new InvalidArgumentException(sprintf('Missing second argument for $operations[%d]["%s"]', $i, $type));
} }
if ( ! is_array($args[1]) && ! is_object($args[1])) { if (! is_array($args[1]) && ! is_object($args[1])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][1]', $i, $type), $args[1], 'array or object'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][1]', $i, $type), $args[1], 'array or object');
} }
if ( ! \MongoDB\is_first_key_operator($args[1])) { if (! is_first_key_operator($args[1])) {
throw new InvalidArgumentException(sprintf('First key in $operations[%d]["%s"][1] is not an update operator', $i, $type)); throw new InvalidArgumentException(sprintf('First key in $operations[%d]["%s"][1] is not an update operator', $i, $type));
} }
if ( ! isset($args[2])) { if (! isset($args[2])) {
$args[2] = []; $args[2] = [];
} }
if ( ! is_array($args[2])) { if (! is_array($args[2])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]', $i, $type), $args[2], 'array'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]', $i, $type), $args[2], 'array');
} }
...@@ -247,7 +257,7 @@ class BulkWrite implements Executable ...@@ -247,7 +257,7 @@ class BulkWrite implements Executable
if (isset($args[2]['arrayFilters'])) { if (isset($args[2]['arrayFilters'])) {
$this->isArrayFiltersUsed = true; $this->isArrayFiltersUsed = true;
if ( ! is_array($args[2]['arrayFilters'])) { if (! is_array($args[2]['arrayFilters'])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["arrayFilters"]', $i, $type), $args[2]['arrayFilters'], 'array'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["arrayFilters"]', $i, $type), $args[2]['arrayFilters'], 'array');
} }
} }
...@@ -255,12 +265,12 @@ class BulkWrite implements Executable ...@@ -255,12 +265,12 @@ class BulkWrite implements Executable
if (isset($args[2]['collation'])) { if (isset($args[2]['collation'])) {
$this->isCollationUsed = true; $this->isCollationUsed = true;
if ( ! is_array($args[2]['collation']) && ! is_object($args[2]['collation'])) { if (! is_array($args[2]['collation']) && ! is_object($args[2]['collation'])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["collation"]', $i, $type), $args[2]['collation'], 'array or object'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["collation"]', $i, $type), $args[2]['collation'], 'array or object');
} }
} }
if ( ! is_bool($args[2]['upsert'])) { if (! is_bool($args[2]['upsert'])) {
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean'); throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean');
} }
...@@ -281,7 +291,7 @@ class BulkWrite implements Executable ...@@ -281,7 +291,7 @@ class BulkWrite implements Executable
throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean'); throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
} }
if ( ! is_bool($options['ordered'])) { if (! is_bool($options['ordered'])) {
throw InvalidArgumentException::invalidType('"ordered" option', $options['ordered'], 'boolean'); throw InvalidArgumentException::invalidType('"ordered" option', $options['ordered'], 'boolean');
} }
...@@ -314,11 +324,11 @@ class BulkWrite implements Executable ...@@ -314,11 +324,11 @@ class BulkWrite implements Executable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if ($this->isArrayFiltersUsed && ! \MongoDB\server_supports_feature($server, self::$wireVersionForArrayFilters)) { if ($this->isArrayFiltersUsed && ! server_supports_feature($server, self::$wireVersionForArrayFilters)) {
throw UnsupportedException::arrayFiltersNotSupported(); throw UnsupportedException::arrayFiltersNotSupported();
} }
if ($this->isCollationUsed && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { if ($this->isCollationUsed && ! server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
...@@ -329,9 +339,8 @@ class BulkWrite implements Executable ...@@ -329,9 +339,8 @@ class BulkWrite implements Executable
$options = ['ordered' => $this->options['ordered']]; $options = ['ordered' => $this->options['ordered']];
if ( if (! empty($this->options['bypassDocumentValidation']) &&
! empty($this->options['bypassDocumentValidation']) && server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) { ) {
$options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; $options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -18,14 +18,21 @@ ...@@ -18,14 +18,21 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function current;
use function is_array;
use function is_float;
use function is_integer;
use function is_object;
use function is_string;
use function MongoDB\server_supports_feature;
/** /**
* Operation for the count command. * Operation for the count command.
...@@ -85,7 +92,7 @@ class Count implements Executable, Explainable ...@@ -85,7 +92,7 @@ class Count implements Executable, Explainable
*/ */
public function __construct($databaseName, $collectionName, $filter = [], array $options = []) public function __construct($databaseName, $collectionName, $filter = [], array $options = [])
{ {
if ( ! is_array($filter) && ! is_object($filter)) { if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object'); throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
} }
...@@ -143,11 +150,11 @@ class Count implements Executable, Explainable ...@@ -143,11 +150,11 @@ class Count implements Executable, Explainable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { if (isset($this->options['collation']) && ! server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { if (isset($this->options['readConcern']) && ! server_supports_feature($server, self::$wireVersionForReadConcern)) {
throw UnsupportedException::readConcernNotSupported(); throw UnsupportedException::readConcernNotSupported();
} }
...@@ -160,7 +167,7 @@ class Count implements Executable, Explainable ...@@ -160,7 +167,7 @@ class Count implements Executable, Explainable
$result = current($cursor->toArray()); $result = current($cursor->toArray());
// Older server versions may return a float // Older server versions may return a float
if ( ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) { if (! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
throw new UnexpectedValueException('count command did not return a numeric "n" value'); throw new UnexpectedValueException('count command did not return a numeric "n" value');
} }
...@@ -181,7 +188,7 @@ class Count implements Executable, Explainable ...@@ -181,7 +188,7 @@ class Count implements Executable, Explainable
{ {
$cmd = ['count' => $this->collectionName]; $cmd = ['count' => $this->collectionName];
if ( ! empty($this->filter)) { if (! empty($this->filter)) {
$cmd['query'] = (object) $this->filter; $cmd['query'] = (object) $this->filter;
} }
......
...@@ -17,11 +17,18 @@ ...@@ -17,11 +17,18 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function array_intersect_key;
use function count;
use function current;
use function is_array;
use function is_float;
use function is_integer;
use function is_object;
/** /**
* Operation for obtaining an exact count of documents in a collection * Operation for obtaining an exact count of documents in a collection
...@@ -80,7 +87,7 @@ class CountDocuments implements Executable ...@@ -80,7 +87,7 @@ class CountDocuments implements Executable
*/ */
public function __construct($databaseName, $collectionName, $filter, array $options = []) public function __construct($databaseName, $collectionName, $filter, array $options = [])
{ {
if ( ! is_array($filter) && ! is_object($filter)) { if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object'); throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
} }
...@@ -124,7 +131,7 @@ class CountDocuments implements Executable ...@@ -124,7 +131,7 @@ class CountDocuments implements Executable
} }
$result = current($allResults); $result = current($allResults);
if ( ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) { if (! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
throw new UnexpectedValueException('count command did not return a numeric "n" value'); throw new UnexpectedValueException('count command did not return a numeric "n" value');
} }
...@@ -137,7 +144,7 @@ class CountDocuments implements Executable ...@@ -137,7 +144,7 @@ class CountDocuments implements Executable
private function createAggregate() private function createAggregate()
{ {
$pipeline = [ $pipeline = [
['$match' => (object) $this->filter] ['$match' => (object) $this->filter],
]; ];
if (isset($this->countOptions['skip'])) { if (isset($this->countOptions['skip'])) {
......
...@@ -18,12 +18,21 @@ ...@@ -18,12 +18,21 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function current;
use function is_array;
use function is_bool;
use function is_integer;
use function is_object;
use function is_string;
use function MongoDB\server_supports_feature;
use function trigger_error;
use const E_USER_DEPRECATED;
/** /**
* Operation for the create command. * Operation for the create command.
...@@ -194,11 +203,11 @@ class CreateCollection implements Executable ...@@ -194,11 +203,11 @@ class CreateCollection implements Executable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { if (isset($this->options['collation']) && ! server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) { if (isset($this->options['writeConcern']) && ! server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported(); throw UnsupportedException::writeConcernNotSupported();
} }
......
...@@ -17,15 +17,19 @@ ...@@ -17,15 +17,19 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\Model\IndexInput; use MongoDB\Model\IndexInput;
use function array_map;
use function is_array;
use function is_integer;
use function MongoDB\server_supports_feature;
use function sprintf;
/** /**
* Operation for the createIndexes command. * Operation for the createIndexes command.
...@@ -82,11 +86,11 @@ class CreateIndexes implements Executable ...@@ -82,11 +86,11 @@ class CreateIndexes implements Executable
throw new InvalidArgumentException(sprintf('$indexes is not a list (unexpected index: "%s")', $i)); throw new InvalidArgumentException(sprintf('$indexes is not a list (unexpected index: "%s")', $i));
} }
if ( ! is_array($index)) { if (! is_array($index)) {
throw InvalidArgumentException::invalidType(sprintf('$index[%d]', $i), $index, 'array'); throw InvalidArgumentException::invalidType(sprintf('$index[%d]', $i), $index, 'array');
} }
if ( ! isset($index['ns'])) { if (! isset($index['ns'])) {
$index['ns'] = $databaseName . '.' . $collectionName; $index['ns'] = $databaseName . '.' . $collectionName;
} }
...@@ -99,7 +103,7 @@ class CreateIndexes implements Executable ...@@ -99,7 +103,7 @@ class CreateIndexes implements Executable
$expectedIndex += 1; $expectedIndex += 1;
} }
if (isset($options['maxTimeMS']) && !is_integer($options['maxTimeMS'])) { if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer'); throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
} }
...@@ -131,11 +135,11 @@ class CreateIndexes implements Executable ...@@ -131,11 +135,11 @@ class CreateIndexes implements Executable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if ($this->isCollationUsed && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { if ($this->isCollationUsed && ! server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) { if (isset($this->options['writeConcern']) && ! server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported(); throw UnsupportedException::writeConcernNotSupported();
} }
...@@ -146,7 +150,9 @@ class CreateIndexes implements Executable ...@@ -146,7 +150,9 @@ class CreateIndexes implements Executable
$this->executeCommand($server); $this->executeCommand($server);
return array_map(function(IndexInput $index) { return (string) $index; }, $this->indexes); return array_map(function (IndexInput $index) {
return (string) $index;
}, $this->indexes);
} }
/** /**
......
...@@ -23,6 +23,8 @@ use MongoDB\Driver\ReadPreference; ...@@ -23,6 +23,8 @@ use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use function is_array;
use function is_object;
/** /**
* Operation for executing a database command. * Operation for executing a database command.
...@@ -54,14 +56,14 @@ class DatabaseCommand implements Executable ...@@ -54,14 +56,14 @@ class DatabaseCommand implements Executable
* * typeMap (array): Type map for BSON deserialization. This will be * * typeMap (array): Type map for BSON deserialization. This will be
* applied to the returned Cursor (it is not sent to the server). * applied to the returned Cursor (it is not sent to the server).
* *
* @param string $databaseName Database name * @param string $databaseName Database name
* @param array|object $command Command document * @param array|object $command Command document
* @param array $options Options for command execution * @param array $options Options for command execution
* @throws InvalidArgumentException for parameter/option parsing errors * @throws InvalidArgumentException for parameter/option parsing errors
*/ */
public function __construct($databaseName, $command, array $options = []) public function __construct($databaseName, $command, array $options = [])
{ {
if ( ! is_array($command) && ! is_object($command)) { if (! is_array($command) && ! is_object($command)) {
throw InvalidArgumentException::invalidType('$command', $command, 'array or object'); throw InvalidArgumentException::invalidType('$command', $command, 'array or object');
} }
...@@ -78,7 +80,7 @@ class DatabaseCommand implements Executable ...@@ -78,7 +80,7 @@ class DatabaseCommand implements Executable
} }
$this->databaseName = (string) $databaseName; $this->databaseName = (string) $databaseName;
$this->command = ($command instanceof Command) ? $command : new Command($command); $this->command = $command instanceof Command ? $command : new Command($command);
$this->options = $options; $this->options = $options;
} }
......
...@@ -19,12 +19,15 @@ namespace MongoDB\Operation; ...@@ -19,12 +19,15 @@ namespace MongoDB\Operation;
use MongoDB\DeleteResult; use MongoDB\DeleteResult;
use MongoDB\Driver\BulkWrite as Bulk; use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function is_array;
use function is_object;
use function MongoDB\server_supports_feature;
/** /**
* Operation for the delete command. * Operation for the delete command.
...@@ -72,7 +75,7 @@ class Delete implements Executable, Explainable ...@@ -72,7 +75,7 @@ class Delete implements Executable, Explainable
*/ */
public function __construct($databaseName, $collectionName, $filter, $limit, array $options = []) public function __construct($databaseName, $collectionName, $filter, $limit, array $options = [])
{ {
if ( ! is_array($filter) && ! is_object($filter)) { if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object'); throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
} }
...@@ -113,7 +116,7 @@ class Delete implements Executable, Explainable ...@@ -113,7 +116,7 @@ class Delete implements Executable, Explainable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { if (isset($this->options['collation']) && ! server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\DeleteResult; use MongoDB\DeleteResult;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\DeleteResult; use MongoDB\DeleteResult;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
......
...@@ -18,14 +18,20 @@ ...@@ -18,14 +18,20 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function current;
use function is_array;
use function is_integer;
use function is_object;
use function MongoDB\create_field_path_type_map;
use function MongoDB\server_supports_feature;
/** /**
* Operation for the distinct command. * Operation for the distinct command.
...@@ -80,7 +86,7 @@ class Distinct implements Executable, Explainable ...@@ -80,7 +86,7 @@ class Distinct implements Executable, Explainable
*/ */
public function __construct($databaseName, $collectionName, $fieldName, $filter = [], array $options = []) public function __construct($databaseName, $collectionName, $fieldName, $filter = [], array $options = [])
{ {
if ( ! is_array($filter) && ! is_object($filter)) { if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object'); throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
} }
...@@ -131,11 +137,11 @@ class Distinct implements Executable, Explainable ...@@ -131,11 +137,11 @@ class Distinct implements Executable, Explainable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { if (isset($this->options['collation']) && ! server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { if (isset($this->options['readConcern']) && ! server_supports_feature($server, self::$wireVersionForReadConcern)) {
throw UnsupportedException::readConcernNotSupported(); throw UnsupportedException::readConcernNotSupported();
} }
...@@ -147,12 +153,12 @@ class Distinct implements Executable, Explainable ...@@ -147,12 +153,12 @@ class Distinct implements Executable, Explainable
$cursor = $server->executeReadCommand($this->databaseName, new Command($this->createCommandDocument()), $this->createOptions()); $cursor = $server->executeReadCommand($this->databaseName, new Command($this->createCommandDocument()), $this->createOptions());
if (isset($this->options['typeMap'])) { if (isset($this->options['typeMap'])) {
$cursor->setTypeMap(\MongoDB\create_field_path_type_map($this->options['typeMap'], 'values.$')); $cursor->setTypeMap(create_field_path_type_map($this->options['typeMap'], 'values.$'));
} }
$result = current($cursor->toArray()); $result = current($cursor->toArray());
if ( ! isset($result->values) || ! is_array($result->values)) { if (! isset($result->values) || ! is_array($result->values)) {
throw new UnexpectedValueException('distinct command did not return a "values" array'); throw new UnexpectedValueException('distinct command did not return a "values" array');
} }
...@@ -176,7 +182,7 @@ class Distinct implements Executable, Explainable ...@@ -176,7 +182,7 @@ class Distinct implements Executable, Explainable
'key' => $this->fieldName, 'key' => $this->fieldName,
]; ];
if ( ! empty($this->filter)) { if (! empty($this->filter)) {
$cmd['query'] = (object) $this->filter; $cmd['query'] = (object) $this->filter;
} }
......
...@@ -18,12 +18,15 @@ ...@@ -18,12 +18,15 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function current;
use function is_array;
use function MongoDB\server_supports_feature;
/** /**
* Operation for the drop command. * Operation for the drop command.
...@@ -98,7 +101,7 @@ class DropCollection implements Executable ...@@ -98,7 +101,7 @@ class DropCollection implements Executable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) { if (isset($this->options['writeConcern']) && ! server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported(); throw UnsupportedException::writeConcernNotSupported();
} }
......
...@@ -18,12 +18,15 @@ ...@@ -18,12 +18,15 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function current;
use function is_array;
use function MongoDB\server_supports_feature;
/** /**
* Operation for the dropDatabase command. * Operation for the dropDatabase command.
...@@ -94,7 +97,7 @@ class DropDatabase implements Executable ...@@ -94,7 +97,7 @@ class DropDatabase implements Executable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) { if (isset($this->options['writeConcern']) && ! server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported(); throw UnsupportedException::writeConcernNotSupported();
} }
......
...@@ -18,12 +18,16 @@ ...@@ -18,12 +18,16 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function current;
use function is_array;
use function is_integer;
use function MongoDB\server_supports_feature;
/** /**
* Operation for the dropIndexes command. * Operation for the dropIndexes command.
...@@ -112,7 +116,7 @@ class DropIndexes implements Executable ...@@ -112,7 +116,7 @@ class DropIndexes implements Executable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) { if (isset($this->options['writeConcern']) && ! server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported(); throw UnsupportedException::writeConcernNotSupported();
} }
......
...@@ -17,11 +17,12 @@ ...@@ -17,11 +17,12 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function array_intersect_key;
/** /**
* Operation for obtaining an estimated count of documents in a collection * Operation for obtaining an estimated count of documents in a collection
...@@ -56,9 +57,9 @@ class EstimatedDocumentCount implements Executable, Explainable ...@@ -56,9 +57,9 @@ class EstimatedDocumentCount implements Executable, Explainable
* *
* Sessions are not supported for server versions < 3.6. * Sessions are not supported for server versions < 3.6.
* *
* @param string $databaseName Database name * @param string $databaseName Database name
* @param string $collectionName Collection name * @param string $collectionName Collection name
* @param array $options Command options * @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors * @throws InvalidArgumentException for parameter/option parsing errors
*/ */
public function __construct($databaseName, $collectionName, array $options = []) public function __construct($databaseName, $collectionName, array $options = [])
......
...@@ -21,9 +21,12 @@ use MongoDB\Driver\Command; ...@@ -21,9 +21,12 @@ use MongoDB\Driver\Command;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Exception\UnsupportedException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\BSONDocument; use MongoDB\Exception\UnsupportedException;
use function current;
use function is_array;
use function is_string;
use function MongoDB\server_supports_feature;
/** /**
* Operation for the explain command. * Operation for the explain command.
...@@ -59,9 +62,9 @@ class Explain implements Executable ...@@ -59,9 +62,9 @@ class Explain implements Executable
* *
* * verbosity (string): The mode in which the explain command will be run. * * verbosity (string): The mode in which the explain command will be run.
* *
* @param string $databaseName Database name * @param string $databaseName Database name
* @param Explainable $explainable Operation to explain * @param Explainable $explainable Operation to explain
* @param array $options Command options * @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors * @throws InvalidArgumentException for parameter/option parsing errors
*/ */
public function __construct($databaseName, Explainable $explainable, array $options = []) public function __construct($databaseName, Explainable $explainable, array $options = [])
...@@ -89,11 +92,11 @@ class Explain implements Executable ...@@ -89,11 +92,11 @@ class Explain implements Executable
public function execute(Server $server) public function execute(Server $server)
{ {
if ($this->explainable instanceof Distinct && ! \MongoDB\server_supports_feature($server, self::$wireVersionForDistinct)) { if ($this->explainable instanceof Distinct && ! server_supports_feature($server, self::$wireVersionForDistinct)) {
throw UnsupportedException::explainNotSupported(); throw UnsupportedException::explainNotSupported();
} }
if ($this->isFindAndModify($this->explainable) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForFindAndModify)) { if ($this->isFindAndModify($this->explainable) && ! server_supports_feature($server, self::$wireVersionForFindAndModify)) {
throw UnsupportedException::explainNotSupported(); throw UnsupportedException::explainNotSupported();
} }
...@@ -138,6 +141,7 @@ class Explain implements Executable ...@@ -138,6 +141,7 @@ class Explain implements Executable
if ($explainable instanceof FindAndModify || $explainable instanceof FindOneAndDelete || $explainable instanceof FindOneAndReplace || $explainable instanceof FindOneAndUpdate) { if ($explainable instanceof FindAndModify || $explainable instanceof FindOneAndDelete || $explainable instanceof FindOneAndReplace || $explainable instanceof FindOneAndUpdate) {
return true; return true;
} }
return false; return false;
} }
} }
...@@ -18,15 +18,23 @@ ...@@ -18,15 +18,23 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Query; use MongoDB\Driver\Query;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\Model\BSONDocument; use function is_array;
use function is_bool;
use function is_integer;
use function is_object;
use function is_string;
use function MongoDB\server_supports_feature;
use function trigger_error;
use const E_USER_DEPRECATED;
/** /**
* Operation for the find command. * Operation for the find command.
* *
...@@ -147,7 +155,7 @@ class Find implements Executable, Explainable ...@@ -147,7 +155,7 @@ class Find implements Executable, Explainable
*/ */
public function __construct($databaseName, $collectionName, $filter, array $options = []) public function __construct($databaseName, $collectionName, $filter, array $options = [])
{ {
if ( ! is_array($filter) && ! is_object($filter)) { if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object'); throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
} }
...@@ -168,7 +176,7 @@ class Find implements Executable, Explainable ...@@ -168,7 +176,7 @@ class Find implements Executable, Explainable
} }
if (isset($options['cursorType'])) { if (isset($options['cursorType'])) {
if ( ! is_integer($options['cursorType'])) { if (! is_integer($options['cursorType'])) {
throw InvalidArgumentException::invalidType('"cursorType" option', $options['cursorType'], 'integer'); throw InvalidArgumentException::invalidType('"cursorType" option', $options['cursorType'], 'integer');
} }
...@@ -288,11 +296,11 @@ class Find implements Executable, Explainable ...@@ -288,11 +296,11 @@ class Find implements Executable, Explainable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { if (isset($this->options['collation']) && ! server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { if (isset($this->options['readConcern']) && ! server_supports_feature($server, self::$wireVersionForReadConcern)) {
throw UnsupportedException::readConcernNotSupported(); throw UnsupportedException::readConcernNotSupported();
} }
...@@ -346,7 +354,7 @@ class Find implements Executable, Explainable ...@@ -346,7 +354,7 @@ class Find implements Executable, Explainable
]; ];
foreach ($modifierFallback as $modifier) { foreach ($modifierFallback as $modifier) {
if ( ! isset($options[$modifier[0]]) && isset($options['modifiers'][$modifier[1]])) { if (! isset($options[$modifier[0]]) && isset($options['modifiers'][$modifier[1]])) {
$options[$modifier[0]] = $options['modifiers'][$modifier[1]]; $options[$modifier[0]] = $options['modifiers'][$modifier[1]];
} }
} }
...@@ -412,7 +420,7 @@ class Find implements Executable, Explainable ...@@ -412,7 +420,7 @@ class Find implements Executable, Explainable
$modifiers = empty($this->options['modifiers']) ? [] : (array) $this->options['modifiers']; $modifiers = empty($this->options['modifiers']) ? [] : (array) $this->options['modifiers'];
if ( ! empty($modifiers)) { if (! empty($modifiers)) {
$options['modifiers'] = $modifiers; $options['modifiers'] = $modifiers;
} }
......
...@@ -18,13 +18,20 @@ ...@@ -18,13 +18,20 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function current;
use function is_array;
use function is_bool;
use function is_integer;
use function is_object;
use function MongoDB\create_field_path_type_map;
use function MongoDB\server_supports_feature;
/** /**
* Operation for the findAndModify command. * Operation for the findAndModify command.
...@@ -137,7 +144,7 @@ class FindAndModify implements Executable, Explainable ...@@ -137,7 +144,7 @@ class FindAndModify implements Executable, Explainable
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer'); throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
} }
if ( ! is_bool($options['new'])) { if (! is_bool($options['new'])) {
throw InvalidArgumentException::invalidType('"new" option', $options['new'], 'boolean'); throw InvalidArgumentException::invalidType('"new" option', $options['new'], 'boolean');
} }
...@@ -145,7 +152,7 @@ class FindAndModify implements Executable, Explainable ...@@ -145,7 +152,7 @@ class FindAndModify implements Executable, Explainable
throw InvalidArgumentException::invalidType('"query" option', $options['query'], 'array or object'); throw InvalidArgumentException::invalidType('"query" option', $options['query'], 'array or object');
} }
if ( ! is_bool($options['remove'])) { if (! is_bool($options['remove'])) {
throw InvalidArgumentException::invalidType('"remove" option', $options['remove'], 'boolean'); throw InvalidArgumentException::invalidType('"remove" option', $options['remove'], 'boolean');
} }
...@@ -169,11 +176,11 @@ class FindAndModify implements Executable, Explainable ...@@ -169,11 +176,11 @@ class FindAndModify implements Executable, Explainable
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], WriteConcern::class); throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], WriteConcern::class);
} }
if ( ! is_bool($options['upsert'])) { if (! is_bool($options['upsert'])) {
throw InvalidArgumentException::invalidType('"upsert" option', $options['upsert'], 'boolean'); throw InvalidArgumentException::invalidType('"upsert" option', $options['upsert'], 'boolean');
} }
if ( ! (isset($options['update']) xor $options['remove'])) { if (! (isset($options['update']) xor $options['remove'])) {
throw new InvalidArgumentException('The "remove" option must be true or an "update" document must be specified, but not both'); throw new InvalidArgumentException('The "remove" option must be true or an "update" document must be specified, but not both');
} }
...@@ -198,15 +205,15 @@ class FindAndModify implements Executable, Explainable ...@@ -198,15 +205,15 @@ class FindAndModify implements Executable, Explainable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['arrayFilters']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForArrayFilters)) { if (isset($this->options['arrayFilters']) && ! server_supports_feature($server, self::$wireVersionForArrayFilters)) {
throw UnsupportedException::arrayFiltersNotSupported(); throw UnsupportedException::arrayFiltersNotSupported();
} }
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { if (isset($this->options['collation']) && ! server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) { if (isset($this->options['writeConcern']) && ! server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported(); throw UnsupportedException::writeConcernNotSupported();
} }
...@@ -218,7 +225,7 @@ class FindAndModify implements Executable, Explainable ...@@ -218,7 +225,7 @@ class FindAndModify implements Executable, Explainable
$cursor = $server->executeWriteCommand($this->databaseName, new Command($this->createCommandDocument($server)), $this->createOptions()); $cursor = $server->executeWriteCommand($this->databaseName, new Command($this->createCommandDocument($server)), $this->createOptions());
if (isset($this->options['typeMap'])) { if (isset($this->options['typeMap'])) {
$cursor->setTypeMap(\MongoDB\create_field_path_type_map($this->options['typeMap'], 'value')); $cursor->setTypeMap(create_field_path_type_map($this->options['typeMap'], 'value'));
} }
$result = current($cursor->toArray()); $result = current($cursor->toArray());
...@@ -262,9 +269,8 @@ class FindAndModify implements Executable, Explainable ...@@ -262,9 +269,8 @@ class FindAndModify implements Executable, Explainable
$cmd['maxTimeMS'] = $this->options['maxTimeMS']; $cmd['maxTimeMS'] = $this->options['maxTimeMS'];
} }
if ( if (! empty($this->options['bypassDocumentValidation']) &&
! empty($this->options['bypassDocumentValidation']) && server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) { ) {
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -17,10 +17,11 @@ ...@@ -17,10 +17,11 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function current;
/** /**
* Operation for finding a single document with the find command. * Operation for finding a single document with the find command.
...@@ -126,7 +127,7 @@ class FindOne implements Executable, Explainable ...@@ -126,7 +127,7 @@ class FindOne implements Executable, Explainable
$cursor = $this->find->execute($server); $cursor = $this->find->execute($server);
$document = current($cursor->toArray()); $document = current($cursor->toArray());
return ($document === false) ? null : $document; return $document === false ? null : $document;
} }
public function getCommandDocument(Server $server) public function getCommandDocument(Server $server)
......
...@@ -17,10 +17,12 @@ ...@@ -17,10 +17,12 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function is_array;
use function is_object;
/** /**
* Operation for deleting a document with the findAndModify command. * Operation for deleting a document with the findAndModify command.
...@@ -71,7 +73,7 @@ class FindOneAndDelete implements Executable, Explainable ...@@ -71,7 +73,7 @@ class FindOneAndDelete implements Executable, Explainable
*/ */
public function __construct($databaseName, $collectionName, $filter, array $options = []) public function __construct($databaseName, $collectionName, $filter, array $options = [])
{ {
if ( ! is_array($filter) && ! is_object($filter)) { if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object'); throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
} }
......
...@@ -17,10 +17,14 @@ ...@@ -17,10 +17,14 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function is_array;
use function is_integer;
use function is_object;
use function MongoDB\is_first_key_operator;
/** /**
* Operation for replacing a document with the findAndModify command. * Operation for replacing a document with the findAndModify command.
...@@ -90,15 +94,15 @@ class FindOneAndReplace implements Executable, Explainable ...@@ -90,15 +94,15 @@ class FindOneAndReplace implements Executable, Explainable
*/ */
public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = []) public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = [])
{ {
if ( ! is_array($filter) && ! is_object($filter)) { if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object'); throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
} }
if ( ! is_array($replacement) && ! is_object($replacement)) { if (! is_array($replacement) && ! is_object($replacement)) {
throw InvalidArgumentException::invalidType('$replacement', $replacement, 'array or object'); throw InvalidArgumentException::invalidType('$replacement', $replacement, 'array or object');
} }
if (\MongoDB\is_first_key_operator($replacement)) { if (is_first_key_operator($replacement)) {
throw new InvalidArgumentException('First key in $replacement argument is an update operator'); throw new InvalidArgumentException('First key in $replacement argument is an update operator');
} }
...@@ -111,7 +115,7 @@ class FindOneAndReplace implements Executable, Explainable ...@@ -111,7 +115,7 @@ class FindOneAndReplace implements Executable, Explainable
throw InvalidArgumentException::invalidType('"projection" option', $options['projection'], 'array or object'); throw InvalidArgumentException::invalidType('"projection" option', $options['projection'], 'array or object');
} }
if ( ! is_integer($options['returnDocument'])) { if (! is_integer($options['returnDocument'])) {
throw InvalidArgumentException::invalidType('"returnDocument" option', $options['returnDocument'], 'integer'); throw InvalidArgumentException::invalidType('"returnDocument" option', $options['returnDocument'], 'integer');
} }
......
...@@ -17,10 +17,14 @@ ...@@ -17,10 +17,14 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function is_array;
use function is_integer;
use function is_object;
use function MongoDB\is_first_key_operator;
/** /**
* Operation for updating a document with the findAndModify command. * Operation for updating a document with the findAndModify command.
...@@ -93,15 +97,15 @@ class FindOneAndUpdate implements Executable, Explainable ...@@ -93,15 +97,15 @@ class FindOneAndUpdate implements Executable, Explainable
*/ */
public function __construct($databaseName, $collectionName, $filter, $update, array $options = []) public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{ {
if ( ! is_array($filter) && ! is_object($filter)) { if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object'); throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
} }
if ( ! is_array($update) && ! is_object($update)) { if (! is_array($update) && ! is_object($update)) {
throw InvalidArgumentException::invalidType('$update', $update, 'array or object'); throw InvalidArgumentException::invalidType('$update', $update, 'array or object');
} }
if ( ! \MongoDB\is_first_key_operator($update)) { if (! is_first_key_operator($update)) {
throw new InvalidArgumentException('First key in $update argument is not an update operator'); throw new InvalidArgumentException('First key in $update argument is not an update operator');
} }
...@@ -114,7 +118,7 @@ class FindOneAndUpdate implements Executable, Explainable ...@@ -114,7 +118,7 @@ class FindOneAndUpdate implements Executable, Explainable
throw InvalidArgumentException::invalidType('"projection" option', $options['projection'], 'array or object'); throw InvalidArgumentException::invalidType('"projection" option', $options['projection'], 'array or object');
} }
if ( ! is_integer($options['returnDocument'])) { if (! is_integer($options['returnDocument'])) {
throw InvalidArgumentException::invalidType('"returnDocument" option', $options['returnDocument'], 'integer'); throw InvalidArgumentException::invalidType('"returnDocument" option', $options['returnDocument'], 'integer');
} }
......
...@@ -17,14 +17,19 @@ ...@@ -17,14 +17,19 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\InsertManyResult;
use MongoDB\Driver\BulkWrite as Bulk; use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\InsertManyResult;
use function is_array;
use function is_bool;
use function is_object;
use function MongoDB\server_supports_feature;
use function sprintf;
/** /**
* Operation for inserting multiple documents with the insert command. * Operation for inserting multiple documents with the insert command.
...@@ -82,7 +87,7 @@ class InsertMany implements Executable ...@@ -82,7 +87,7 @@ class InsertMany implements Executable
throw new InvalidArgumentException(sprintf('$documents is not a list (unexpected index: "%s")', $i)); throw new InvalidArgumentException(sprintf('$documents is not a list (unexpected index: "%s")', $i));
} }
if ( ! is_array($document) && ! is_object($document)) { if (! is_array($document) && ! is_object($document)) {
throw InvalidArgumentException::invalidType(sprintf('$documents[%d]', $i), $document, 'array or object'); throw InvalidArgumentException::invalidType(sprintf('$documents[%d]', $i), $document, 'array or object');
} }
...@@ -95,7 +100,7 @@ class InsertMany implements Executable ...@@ -95,7 +100,7 @@ class InsertMany implements Executable
throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean'); throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
} }
if ( ! is_bool($options['ordered'])) { if (! is_bool($options['ordered'])) {
throw InvalidArgumentException::invalidType('"ordered" option', $options['ordered'], 'boolean'); throw InvalidArgumentException::invalidType('"ordered" option', $options['ordered'], 'boolean');
} }
...@@ -134,9 +139,8 @@ class InsertMany implements Executable ...@@ -134,9 +139,8 @@ class InsertMany implements Executable
$options = ['ordered' => $this->options['ordered']]; $options = ['ordered' => $this->options['ordered']];
if ( if (! empty($this->options['bypassDocumentValidation']) &&
! empty($this->options['bypassDocumentValidation']) && server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) { ) {
$options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; $options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -17,14 +17,18 @@ ...@@ -17,14 +17,18 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\InsertOneResult;
use MongoDB\Driver\BulkWrite as Bulk; use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\InsertOneResult;
use function is_array;
use function is_bool;
use function is_object;
use function MongoDB\server_supports_feature;
/** /**
* Operation for inserting a single document with the insert command. * Operation for inserting a single document with the insert command.
...@@ -67,7 +71,7 @@ class InsertOne implements Executable ...@@ -67,7 +71,7 @@ class InsertOne implements Executable
*/ */
public function __construct($databaseName, $collectionName, $document, array $options = []) public function __construct($databaseName, $collectionName, $document, array $options = [])
{ {
if ( ! is_array($document) && ! is_object($document)) { if (! is_array($document) && ! is_object($document)) {
throw InvalidArgumentException::invalidType('$document', $document, 'array or object'); throw InvalidArgumentException::invalidType('$document', $document, 'array or object');
} }
...@@ -110,9 +114,8 @@ class InsertOne implements Executable ...@@ -110,9 +114,8 @@ class InsertOne implements Executable
throw UnsupportedException::writeConcernNotSupportedInTransaction(); throw UnsupportedException::writeConcernNotSupportedInTransaction();
} }
if ( if (! empty($this->options['bypassDocumentValidation']) &&
! empty($this->options['bypassDocumentValidation']) && server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) { ) {
$options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; $options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -18,13 +18,16 @@ ...@@ -18,13 +18,16 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\CachingIterator; use MongoDB\Model\CachingIterator;
use MongoDB\Model\CollectionInfoCommandIterator; use MongoDB\Model\CollectionInfoCommandIterator;
use MongoDB\Model\CollectionInfoIterator; use MongoDB\Model\CollectionInfoIterator;
use function is_array;
use function is_integer;
use function is_object;
/** /**
* Operation for the listCollections command. * Operation for the listCollections command.
...@@ -119,7 +122,7 @@ class ListCollections implements Executable ...@@ -119,7 +122,7 @@ class ListCollections implements Executable
{ {
$cmd = ['listCollections' => 1]; $cmd = ['listCollections' => 1];
if ( ! empty($this->options['filter'])) { if (! empty($this->options['filter'])) {
$cmd['filter'] = (object) $this->options['filter']; $cmd['filter'] = (object) $this->options['filter'];
} }
......
...@@ -18,13 +18,17 @@ ...@@ -18,13 +18,17 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Model\DatabaseInfoIterator; use MongoDB\Model\DatabaseInfoIterator;
use MongoDB\Model\DatabaseInfoLegacyIterator; use MongoDB\Model\DatabaseInfoLegacyIterator;
use function current;
use function is_array;
use function is_integer;
use function is_object;
/** /**
* Operation for the ListDatabases command. * Operation for the ListDatabases command.
...@@ -86,7 +90,7 @@ class ListDatabases implements Executable ...@@ -86,7 +90,7 @@ class ListDatabases implements Executable
{ {
$cmd = ['listDatabases' => 1]; $cmd = ['listDatabases' => 1];
if ( ! empty($this->options['filter'])) { if (! empty($this->options['filter'])) {
$cmd['filter'] = (object) $this->options['filter']; $cmd['filter'] = (object) $this->options['filter'];
} }
...@@ -98,7 +102,7 @@ class ListDatabases implements Executable ...@@ -98,7 +102,7 @@ class ListDatabases implements Executable
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']); $cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
$result = current($cursor->toArray()); $result = current($cursor->toArray());
if ( ! isset($result['databases']) || ! is_array($result['databases'])) { if (! isset($result['databases']) || ! is_array($result['databases'])) {
throw new UnexpectedValueException('listDatabases command did not return a "databases" array'); throw new UnexpectedValueException('listDatabases command did not return a "databases" array');
} }
......
...@@ -17,16 +17,16 @@ ...@@ -17,16 +17,16 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use EmptyIterator;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Query; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\CachingIterator; use MongoDB\Model\CachingIterator;
use MongoDB\Model\IndexInfoIterator; use MongoDB\Model\IndexInfoIterator;
use MongoDB\Model\IndexInfoIteratorIterator; use MongoDB\Model\IndexInfoIteratorIterator;
use EmptyIterator; use function is_integer;
/** /**
* Operation for the listIndexes command. * Operation for the listIndexes command.
...@@ -133,7 +133,7 @@ class ListIndexes implements Executable ...@@ -133,7 +133,7 @@ class ListIndexes implements Executable
* empty iterator instead of throwing. * empty iterator instead of throwing.
*/ */
if ($e->getCode() === self::$errorCodeNamespaceNotFound || $e->getCode() === self::$errorCodeDatabaseNotFound) { if ($e->getCode() === self::$errorCodeNamespaceNotFound || $e->getCode() === self::$errorCodeDatabaseNotFound) {
return new IndexInfoIteratorIterator(new EmptyIterator); return new IndexInfoIteratorIterator(new EmptyIterator());
} }
throw $e; throw $e;
......
...@@ -17,20 +17,29 @@ ...@@ -17,20 +17,29 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use ArrayIterator;
use MongoDB\BSON\JavascriptInterface; use MongoDB\BSON\JavascriptInterface;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\MapReduceResult; use MongoDB\MapReduceResult;
use ArrayIterator;
use stdClass; use stdClass;
use function current;
use function is_array;
use function is_bool;
use function is_integer;
use function is_object;
use function is_string;
use function MongoDB\create_field_path_type_map;
use function MongoDB\is_mapreduce_output_inline;
use function MongoDB\server_supports_feature;
/** /**
* Operation for the mapReduce command. * Operation for the mapReduce command.
...@@ -143,7 +152,7 @@ class MapReduce implements Executable ...@@ -143,7 +152,7 @@ class MapReduce implements Executable
*/ */
public function __construct($databaseName, $collectionName, JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options = []) public function __construct($databaseName, $collectionName, JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options = [])
{ {
if ( ! is_string($out) && ! is_array($out) && ! is_object($out)) { if (! is_string($out) && ! is_array($out) && ! is_object($out)) {
throw InvalidArgumentException::invalidType('$out', $out, 'string or array or object'); throw InvalidArgumentException::invalidType('$out', $out, 'string or array or object');
} }
...@@ -235,15 +244,15 @@ class MapReduce implements Executable ...@@ -235,15 +244,15 @@ class MapReduce implements Executable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { if (isset($this->options['collation']) && ! server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { if (isset($this->options['readConcern']) && ! server_supports_feature($server, self::$wireVersionForReadConcern)) {
throw UnsupportedException::readConcernNotSupported(); throw UnsupportedException::readConcernNotSupported();
} }
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) { if (isset($this->options['writeConcern']) && ! server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported(); throw UnsupportedException::writeConcernNotSupported();
} }
...@@ -257,7 +266,7 @@ class MapReduce implements Executable ...@@ -257,7 +266,7 @@ class MapReduce implements Executable
} }
} }
$hasOutputCollection = ! \MongoDB\is_mapreduce_output_inline($this->out); $hasOutputCollection = ! is_mapreduce_output_inline($this->out);
$command = $this->createCommand($server); $command = $this->createCommand($server);
$options = $this->createOptions($hasOutputCollection); $options = $this->createOptions($hasOutputCollection);
...@@ -267,7 +276,7 @@ class MapReduce implements Executable ...@@ -267,7 +276,7 @@ class MapReduce implements Executable
: $server->executeReadCommand($this->databaseName, $command, $options); : $server->executeReadCommand($this->databaseName, $command, $options);
if (isset($this->options['typeMap']) && ! $hasOutputCollection) { if (isset($this->options['typeMap']) && ! $hasOutputCollection) {
$cursor->setTypeMap(\MongoDB\create_field_path_type_map($this->options['typeMap'], 'results.$')); $cursor->setTypeMap(create_field_path_type_map($this->options['typeMap'], 'results.$'));
} }
$result = current($cursor->toArray()); $result = current($cursor->toArray());
...@@ -304,9 +313,8 @@ class MapReduce implements Executable ...@@ -304,9 +313,8 @@ class MapReduce implements Executable
} }
} }
if ( if (! empty($this->options['bypassDocumentValidation']) &&
! empty($this->options['bypassDocumentValidation']) && server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) { ) {
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
...@@ -328,7 +336,7 @@ class MapReduce implements Executable ...@@ -328,7 +336,7 @@ class MapReduce implements Executable
if (isset($result->results) && is_array($result->results)) { if (isset($result->results) && is_array($result->results)) {
$results = $result->results; $results = $result->results;
return function() use ($results) { return function () use ($results) {
return new ArrayIterator($results); return new ArrayIterator($results);
}; };
} }
...@@ -340,7 +348,7 @@ class MapReduce implements Executable ...@@ -340,7 +348,7 @@ class MapReduce implements Executable
? new Find($this->databaseName, $result->result, [], $options) ? new Find($this->databaseName, $result->result, [], $options)
: new Find($result->result->db, $result->result->collection, [], $options); : new Find($result->result->db, $result->result->collection, [], $options);
return function() use ($find, $server) { return function () use ($find, $server) {
return $find->execute($server); return $find->execute($server);
}; };
} }
...@@ -364,7 +372,7 @@ class MapReduce implements Executable ...@@ -364,7 +372,7 @@ class MapReduce implements Executable
$options['readConcern'] = $this->options['readConcern']; $options['readConcern'] = $this->options['readConcern'];
} }
if ( ! $hasOutputCollection && isset($this->options['readPreference'])) { if (! $hasOutputCollection && isset($this->options['readPreference'])) {
$options['readPreference'] = $this->options['readPreference']; $options['readPreference'] = $this->options['readPreference'];
} }
......
...@@ -18,12 +18,15 @@ ...@@ -18,12 +18,15 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use function current;
use function is_array;
use function MongoDB\server_supports_feature;
/** /**
* Operation for the collMod command. * Operation for the collMod command.
...@@ -56,10 +59,10 @@ class ModifyCollection implements Executable ...@@ -56,10 +59,10 @@ class ModifyCollection implements Executable
* This is not supported for server versions < 3.2 and will result in an * This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used. * exception at execution time if used.
* *
* @param string $databaseName Database name * @param string $databaseName Database name
* @param string $collectionName Collection or view to modify * @param string $collectionName Collection or view to modify
* @param array $collectionOptions Collection or view options to assign * @param array $collectionOptions Collection or view options to assign
* @param array $options Command options * @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors * @throws InvalidArgumentException for parameter/option parsing errors
*/ */
public function __construct($databaseName, $collectionName, array $collectionOptions, array $options = []) public function __construct($databaseName, $collectionName, array $collectionOptions, array $options = [])
...@@ -100,7 +103,7 @@ class ModifyCollection implements Executable ...@@ -100,7 +103,7 @@ class ModifyCollection implements Executable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) { if (isset($this->options['writeConcern']) && ! server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported(); throw UnsupportedException::writeConcernNotSupported();
} }
......
...@@ -17,11 +17,14 @@ ...@@ -17,11 +17,14 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\UpdateResult;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\UpdateResult;
use function is_array;
use function is_object;
use function MongoDB\is_first_key_operator;
/** /**
* Operation for replacing a single document with the update command. * Operation for replacing a single document with the update command.
...@@ -68,11 +71,11 @@ class ReplaceOne implements Executable ...@@ -68,11 +71,11 @@ class ReplaceOne implements Executable
*/ */
public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = []) public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = [])
{ {
if ( ! is_array($replacement) && ! is_object($replacement)) { if (! is_array($replacement) && ! is_object($replacement)) {
throw InvalidArgumentException::invalidType('$replacement', $replacement, 'array or object'); throw InvalidArgumentException::invalidType('$replacement', $replacement, 'array or object');
} }
if (\MongoDB\is_first_key_operator($replacement)) { if (is_first_key_operator($replacement)) {
throw new InvalidArgumentException('First key in $replacement argument is an update operator'); throw new InvalidArgumentException('First key in $replacement argument is an update operator');
} }
......
...@@ -17,14 +17,19 @@ ...@@ -17,14 +17,19 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\UpdateResult;
use MongoDB\Driver\BulkWrite as Bulk; use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\UpdateResult;
use function is_array;
use function is_bool;
use function is_object;
use function MongoDB\is_first_key_operator;
use function MongoDB\server_supports_feature;
/** /**
* Operation for the update command. * Operation for the update command.
...@@ -92,11 +97,11 @@ class Update implements Executable, Explainable ...@@ -92,11 +97,11 @@ class Update implements Executable, Explainable
*/ */
public function __construct($databaseName, $collectionName, $filter, $update, array $options = []) public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{ {
if ( ! is_array($filter) && ! is_object($filter)) { if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object'); throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
} }
if ( ! is_array($update) && ! is_object($update)) { if (! is_array($update) && ! is_object($update)) {
throw InvalidArgumentException::invalidType('$update', $filter, 'array or object'); throw InvalidArgumentException::invalidType('$update', $filter, 'array or object');
} }
...@@ -117,11 +122,11 @@ class Update implements Executable, Explainable ...@@ -117,11 +122,11 @@ class Update implements Executable, Explainable
throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object'); throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object');
} }
if ( ! is_bool($options['multi'])) { if (! is_bool($options['multi'])) {
throw InvalidArgumentException::invalidType('"multi" option', $options['multi'], 'boolean'); throw InvalidArgumentException::invalidType('"multi" option', $options['multi'], 'boolean');
} }
if ($options['multi'] && ! \MongoDB\is_first_key_operator($update)) { if ($options['multi'] && ! is_first_key_operator($update)) {
throw new InvalidArgumentException('"multi" option cannot be true if $update is a replacement document'); throw new InvalidArgumentException('"multi" option cannot be true if $update is a replacement document');
} }
...@@ -129,7 +134,7 @@ class Update implements Executable, Explainable ...@@ -129,7 +134,7 @@ class Update implements Executable, Explainable
throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class); throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class);
} }
if ( ! is_bool($options['upsert'])) { if (! is_bool($options['upsert'])) {
throw InvalidArgumentException::invalidType('"upsert" option', $options['upsert'], 'boolean'); throw InvalidArgumentException::invalidType('"upsert" option', $options['upsert'], 'boolean');
} }
...@@ -159,11 +164,11 @@ class Update implements Executable, Explainable ...@@ -159,11 +164,11 @@ class Update implements Executable, Explainable
*/ */
public function execute(Server $server) public function execute(Server $server)
{ {
if (isset($this->options['arrayFilters']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForArrayFilters)) { if (isset($this->options['arrayFilters']) && ! server_supports_feature($server, self::$wireVersionForArrayFilters)) {
throw UnsupportedException::arrayFiltersNotSupported(); throw UnsupportedException::arrayFiltersNotSupported();
} }
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { if (isset($this->options['collation']) && ! server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
...@@ -174,9 +179,8 @@ class Update implements Executable, Explainable ...@@ -174,9 +179,8 @@ class Update implements Executable, Explainable
$bulkOptions = []; $bulkOptions = [];
if ( if (! empty($this->options['bypassDocumentValidation']) &&
! empty($this->options['bypassDocumentValidation']) && server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) { ) {
$bulkOptions['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; $bulkOptions['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
...@@ -197,9 +201,8 @@ class Update implements Executable, Explainable ...@@ -197,9 +201,8 @@ class Update implements Executable, Explainable
$cmd['writeConcern'] = $this->options['writeConcern']; $cmd['writeConcern'] = $this->options['writeConcern'];
} }
if ( if (! empty($this->options['bypassDocumentValidation']) &&
! empty($this->options['bypassDocumentValidation']) && server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) { ) {
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -17,11 +17,14 @@ ...@@ -17,11 +17,14 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\UpdateResult;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\UpdateResult;
use function is_array;
use function is_object;
use function MongoDB\is_first_key_operator;
/** /**
* Operation for updating multiple documents with the update command. * Operation for updating multiple documents with the update command.
...@@ -74,11 +77,11 @@ class UpdateMany implements Executable, Explainable ...@@ -74,11 +77,11 @@ class UpdateMany implements Executable, Explainable
*/ */
public function __construct($databaseName, $collectionName, $filter, $update, array $options = []) public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{ {
if ( ! is_array($update) && ! is_object($update)) { if (! is_array($update) && ! is_object($update)) {
throw InvalidArgumentException::invalidType('$update', $update, 'array or object'); throw InvalidArgumentException::invalidType('$update', $update, 'array or object');
} }
if ( ! \MongoDB\is_first_key_operator($update)) { if (! is_first_key_operator($update)) {
throw new InvalidArgumentException('First key in $update argument is not an update operator'); throw new InvalidArgumentException('First key in $update argument is not an update operator');
} }
......
...@@ -17,11 +17,14 @@ ...@@ -17,11 +17,14 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\UpdateResult;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\UpdateResult;
use function is_array;
use function is_object;
use function MongoDB\is_first_key_operator;
/** /**
* Operation for updating a single document with the update command. * Operation for updating a single document with the update command.
...@@ -74,11 +77,11 @@ class UpdateOne implements Executable, Explainable ...@@ -74,11 +77,11 @@ class UpdateOne implements Executable, Explainable
*/ */
public function __construct($databaseName, $collectionName, $filter, $update, array $options = []) public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{ {
if ( ! is_array($update) && ! is_object($update)) { if (! is_array($update) && ! is_object($update)) {
throw InvalidArgumentException::invalidType('$update', $update, 'array or object'); throw InvalidArgumentException::invalidType('$update', $update, 'array or object');
} }
if ( ! \MongoDB\is_first_key_operator($update)) { if (! is_first_key_operator($update)) {
throw new InvalidArgumentException('First key in $update argument is not an update operator'); throw new InvalidArgumentException('First key in $update argument is not an update operator');
} }
......
...@@ -17,24 +17,30 @@ ...@@ -17,24 +17,30 @@
namespace MongoDB\Operation; namespace MongoDB\Operation;
use MongoDB\ChangeStream;
use MongoDB\BSON\TimestampInterface; use MongoDB\BSON\TimestampInterface;
use MongoDB\Model\ChangeStreamIterator; use MongoDB\ChangeStream;
use MongoDB\Driver\Command;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Driver\Session;
use MongoDB\Driver\Exception\RuntimeException; use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Driver\Manager;
use MongoDB\Driver\Monitoring\CommandFailedEvent; use MongoDB\Driver\Monitoring\CommandFailedEvent;
use MongoDB\Driver\Monitoring\CommandSubscriber;
use MongoDB\Driver\Monitoring\CommandStartedEvent; use MongoDB\Driver\Monitoring\CommandStartedEvent;
use MongoDB\Driver\Monitoring\CommandSubscriber;
use MongoDB\Driver\Monitoring\CommandSucceededEvent; use MongoDB\Driver\Monitoring\CommandSucceededEvent;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\Model\ChangeStreamIterator;
use function array_intersect_key;
use function array_unshift;
use function count;
use function is_array;
use function is_object;
use function is_string;
use function MongoDB\Driver\Monitoring\addSubscriber;
use function MongoDB\Driver\Monitoring\removeSubscriber;
use function MongoDB\server_supports_feature;
/** /**
* Operation for creating a change stream with the aggregate command. * Operation for creating a change stream with the aggregate command.
...@@ -131,11 +137,11 @@ class Watch implements Executable, /* @internal */ CommandSubscriber ...@@ -131,11 +137,11 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
* for the collection name. A cluster-level change stream may be created by * for the collection name. A cluster-level change stream may be created by
* specifying null for both the database and collection name. * specifying null for both the database and collection name.
* *
* @param Manager $manager Manager instance from the driver * @param Manager $manager Manager instance from the driver
* @param string|null $databaseName Database name * @param string|null $databaseName Database name
* @param string|null $collectionName Collection name * @param string|null $collectionName Collection name
* @param array $pipeline List of pipeline operations * @param array $pipeline List of pipeline operations
* @param array $options Command options * @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors * @throws InvalidArgumentException for parameter/option parsing errors
*/ */
public function __construct(Manager $manager, $databaseName, $collectionName, array $pipeline, array $options = []) public function __construct(Manager $manager, $databaseName, $collectionName, array $pipeline, array $options = [])
...@@ -170,7 +176,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber ...@@ -170,7 +176,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
* ("implicit from the user's perspective" per PHPLIB-342). Since this * ("implicit from the user's perspective" per PHPLIB-342). Since this
* is filling in for an implicit session, we default "causalConsistency" * is filling in for an implicit session, we default "causalConsistency"
* to false. */ * to false. */
if ( ! isset($options['session'])) { if (! isset($options['session'])) {
try { try {
$options['session'] = $manager->startSession(['causalConsistency' => false]); $options['session'] = $manager->startSession(['causalConsistency' => false]);
} catch (RuntimeException $e) { } catch (RuntimeException $e) {
...@@ -221,7 +227,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber ...@@ -221,7 +227,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
$reply = $event->getReply(); $reply = $event->getReply();
if ( ! isset($reply->cursor->firstBatch) || ! is_array($reply->cursor->firstBatch)) { if (! isset($reply->cursor->firstBatch) || ! is_array($reply->cursor->firstBatch)) {
throw new UnexpectedValueException('aggregate command did not return a "cursor.firstBatch" array'); throw new UnexpectedValueException('aggregate command did not return a "cursor.firstBatch" array');
} }
...@@ -250,7 +256,9 @@ class Watch implements Executable, /* @internal */ CommandSubscriber ...@@ -250,7 +256,9 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
{ {
return new ChangeStream( return new ChangeStream(
$this->createChangeStreamIterator($server), $this->createChangeStreamIterator($server),
function($resumeToken, $hasAdvanced) { return $this->resume($resumeToken, $hasAdvanced); } function ($resumeToken, $hasAdvanced) {
return $this->resume($resumeToken, $hasAdvanced);
}
); );
} }
...@@ -296,12 +304,12 @@ class Watch implements Executable, /* @internal */ CommandSubscriber ...@@ -296,12 +304,12 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
*/ */
private function executeAggregate(Server $server) private function executeAggregate(Server $server)
{ {
\MongoDB\Driver\Monitoring\addSubscriber($this); addSubscriber($this);
try { try {
return $this->aggregate->execute($server); return $this->aggregate->execute($server);
} finally { } finally {
\MongoDB\Driver\Monitoring\removeSubscriber($this); removeSubscriber($this);
} }
} }
...@@ -348,7 +356,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber ...@@ -348,7 +356,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
// Select a new server using the original read preference // Select a new server using the original read preference
$server = $this->manager->selectServer($this->aggregateOptions['readPreference']); $server = $this->manager->selectServer($this->aggregateOptions['readPreference']);
$resumeOption = isset($this->changeStreamOptions['startAfter']) && !$hasAdvanced ? 'startAfter' : 'resumeAfter'; $resumeOption = isset($this->changeStreamOptions['startAfter']) && ! $hasAdvanced ? 'startAfter' : 'resumeAfter';
unset($this->changeStreamOptions['resumeAfter']); unset($this->changeStreamOptions['resumeAfter']);
unset($this->changeStreamOptions['startAfter']); unset($this->changeStreamOptions['startAfter']);
...@@ -395,7 +403,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber ...@@ -395,7 +403,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
return false; return false;
} }
if ( ! \MongoDB\server_supports_feature($server, self::$wireVersionForStartAtOperationTime)) { if (! server_supports_feature($server, self::$wireVersionForStartAtOperationTime)) {
return false; return false;
} }
......
...@@ -29,8 +29,6 @@ class UpdateResult ...@@ -29,8 +29,6 @@ class UpdateResult
private $isAcknowledged; private $isAcknowledged;
/** /**
* Constructor.
*
* @param WriteResult $writeResult * @param WriteResult $writeResult
*/ */
public function __construct(WriteResult $writeResult) public function __construct(WriteResult $writeResult)
......
...@@ -18,13 +18,22 @@ ...@@ -18,13 +18,22 @@
namespace MongoDB; namespace MongoDB;
use MongoDB\BSON\Serializable; use MongoDB\BSON\Serializable;
use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\Session;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use ReflectionException;
use stdClass;
use ReflectionClass; use ReflectionClass;
use ReflectionException;
use function end;
use function get_object_vars;
use function in_array;
use function is_array;
use function is_object;
use function is_string;
use function key;
use function MongoDB\BSON\fromPHP;
use function MongoDB\BSON\toPHP;
use function reset;
use function substr;
/** /**
* Applies a type map to a document. * Applies a type map to a document.
...@@ -41,11 +50,11 @@ use ReflectionClass; ...@@ -41,11 +50,11 @@ use ReflectionClass;
*/ */
function apply_type_map_to_document($document, array $typeMap) function apply_type_map_to_document($document, array $typeMap)
{ {
if ( ! is_array($document) && ! is_object($document)) { if (! is_array($document) && ! is_object($document)) {
throw InvalidArgumentException::invalidType('$document', $document, 'array or object'); throw InvalidArgumentException::invalidType('$document', $document, 'array or object');
} }
return \MongoDB\BSON\toPHP(\MongoDB\BSON\fromPHP($document), $typeMap); return toPHP(fromPHP($document), $typeMap);
} }
/** /**
...@@ -67,7 +76,7 @@ function generate_index_name($document) ...@@ -67,7 +76,7 @@ function generate_index_name($document)
$document = get_object_vars($document); $document = get_object_vars($document);
} }
if ( ! is_array($document)) { if (! is_array($document)) {
throw InvalidArgumentException::invalidType('$document', $document, 'array or object'); throw InvalidArgumentException::invalidType('$document', $document, 'array or object');
} }
...@@ -100,14 +109,14 @@ function is_first_key_operator($document) ...@@ -100,14 +109,14 @@ function is_first_key_operator($document)
$document = get_object_vars($document); $document = get_object_vars($document);
} }
if ( ! is_array($document)) { if (! is_array($document)) {
throw InvalidArgumentException::invalidType('$document', $document, 'array or object'); throw InvalidArgumentException::invalidType('$document', $document, 'array or object');
} }
reset($document); reset($document);
$firstKey = (string) key($document); $firstKey = (string) key($document);
return (isset($firstKey[0]) && $firstKey[0] === '$'); return isset($firstKey[0]) && $firstKey[0] === '$';
} }
/** /**
...@@ -119,7 +128,7 @@ function is_first_key_operator($document) ...@@ -119,7 +128,7 @@ function is_first_key_operator($document)
*/ */
function is_in_transaction(array $options) function is_in_transaction(array $options)
{ {
if (isset($options['session']) && $options['session'] instanceof \MongoDB\Driver\Session && $options['session']->isInTransaction()) { if (isset($options['session']) && $options['session'] instanceof Session && $options['session']->isInTransaction()) {
return true; return true;
} }
...@@ -162,7 +171,7 @@ function is_last_pipeline_operator_write(array $pipeline) ...@@ -162,7 +171,7 @@ function is_last_pipeline_operator_write(array $pipeline)
*/ */
function is_mapreduce_output_inline($out) function is_mapreduce_output_inline($out)
{ {
if ( ! is_array($out) && ! is_object($out)) { if (! is_array($out) && ! is_object($out)) {
return false; return false;
} }
...@@ -174,7 +183,7 @@ function is_mapreduce_output_inline($out) ...@@ -174,7 +183,7 @@ function is_mapreduce_output_inline($out)
$out = get_object_vars($out); $out = get_object_vars($out);
} }
if ( ! is_array($out)) { if (! is_array($out)) {
throw InvalidArgumentException::invalidType('$out', $out, 'array or object'); throw InvalidArgumentException::invalidType('$out', $out, 'array or object');
} }
...@@ -197,18 +206,20 @@ function server_supports_feature(Server $server, $feature) ...@@ -197,18 +206,20 @@ function server_supports_feature(Server $server, $feature)
$maxWireVersion = isset($info['maxWireVersion']) ? (integer) $info['maxWireVersion'] : 0; $maxWireVersion = isset($info['maxWireVersion']) ? (integer) $info['maxWireVersion'] : 0;
$minWireVersion = isset($info['minWireVersion']) ? (integer) $info['minWireVersion'] : 0; $minWireVersion = isset($info['minWireVersion']) ? (integer) $info['minWireVersion'] : 0;
return ($minWireVersion <= $feature && $maxWireVersion >= $feature); return $minWireVersion <= $feature && $maxWireVersion >= $feature;
} }
function is_string_array($input) { function is_string_array($input)
if (!is_array($input)){ {
if (! is_array($input)) {
return false; return false;
} }
foreach($input as $item) { foreach ($input as $item) {
if (!is_string($item)) { if (! is_string($item)) {
return false; return false;
} }
} }
return true; return true;
} }
...@@ -223,19 +234,21 @@ function is_string_array($input) { ...@@ -223,19 +234,21 @@ function is_string_array($input) {
* @return mixed * @return mixed
* @throws ReflectionException * @throws ReflectionException
*/ */
function recursive_copy($element) { function recursive_copy($element)
{
if (is_array($element)) { if (is_array($element)) {
foreach ($element as $key => $value) { foreach ($element as $key => $value) {
$element[$key] = recursive_copy($value); $element[$key] = recursive_copy($value);
} }
return $element; return $element;
} }
if ( ! is_object($element)) { if (! is_object($element)) {
return $element; return $element;
} }
if ( ! (new ReflectionClass($element))->isCloneable()) { if (! (new ReflectionClass($element))->isCloneable()) {
return $element; return $element;
} }
......
...@@ -4,9 +4,15 @@ namespace MongoDB\Tests; ...@@ -4,9 +4,15 @@ namespace MongoDB\Tests;
use MongoDB\Client; use MongoDB\Client;
use MongoDB\Driver\BulkWrite; use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\Command; use MongoDB\Driver\Manager;
use MongoDB\Driver\Session;
use MongoDB\Model\DatabaseInfo; use MongoDB\Model\DatabaseInfo;
use MongoDB\Model\DatabaseInfoIterator;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use function call_user_func;
use function is_callable;
use function sprintf;
use function version_compare;
/** /**
* Functional tests for the Client class. * Functional tests for the Client class.
...@@ -27,7 +33,7 @@ class ClientFunctionalTest extends FunctionalTestCase ...@@ -27,7 +33,7 @@ class ClientFunctionalTest extends FunctionalTestCase
public function testGetManager() public function testGetManager()
{ {
$this->assertInstanceOf(\MongoDB\Driver\Manager::class, $this->client->getManager()); $this->assertInstanceOf(Manager::class, $this->client->getManager());
} }
public function testDropDatabase() public function testDropDatabase()
...@@ -53,14 +59,14 @@ class ClientFunctionalTest extends FunctionalTestCase ...@@ -53,14 +59,14 @@ class ClientFunctionalTest extends FunctionalTestCase
$databases = $this->client->listDatabases(); $databases = $this->client->listDatabases();
$this->assertInstanceOf(\MongoDB\Model\DatabaseInfoIterator::class, $databases); $this->assertInstanceOf(DatabaseInfoIterator::class, $databases);
foreach ($databases as $database) { foreach ($databases as $database) {
$this->assertInstanceOf(\MongoDB\Model\DatabaseInfo::class, $database); $this->assertInstanceOf(DatabaseInfo::class, $database);
} }
$that = $this; $that = $this;
$this->assertDatabaseExists($this->getDatabaseName(), function(DatabaseInfo $info) use ($that) { $this->assertDatabaseExists($this->getDatabaseName(), function (DatabaseInfo $info) use ($that) {
$that->assertFalse($info->isEmpty()); $that->assertFalse($info->isEmpty());
$that->assertGreaterThan(0, $info->getSizeOnDisk()); $that->assertGreaterThan(0, $info->getSizeOnDisk());
}); });
...@@ -74,7 +80,7 @@ class ClientFunctionalTest extends FunctionalTestCase ...@@ -74,7 +80,7 @@ class ClientFunctionalTest extends FunctionalTestCase
* the given name is found, it will be passed to the callback, which may * the given name is found, it will be passed to the callback, which may
* perform additional assertions. * perform additional assertions.
* *
* @param string $databaseName * @param string $databaseName
* @param callable $callback * @param callable $callback
*/ */
private function assertDatabaseExists($databaseName, $callback = null) private function assertDatabaseExists($databaseName, $callback = null)
...@@ -106,6 +112,6 @@ class ClientFunctionalTest extends FunctionalTestCase ...@@ -106,6 +112,6 @@ class ClientFunctionalTest extends FunctionalTestCase
if (version_compare($this->getFeatureCompatibilityVersion(), '3.6', '<')) { if (version_compare($this->getFeatureCompatibilityVersion(), '3.6', '<')) {
$this->markTestSkipped('startSession() is only supported on FCV 3.6 or higher'); $this->markTestSkipped('startSession() is only supported on FCV 3.6 or higher');
} }
$this->assertInstanceOf(\MongoDB\Driver\Session::class, $this->client->startSession()); $this->assertInstanceOf(Session::class, $this->client->startSession());
} }
} }
...@@ -63,13 +63,13 @@ class ClientTest extends TestCase ...@@ -63,13 +63,13 @@ class ClientTest extends TestCase
$collection = $client->selectCollection($this->getDatabaseName(), $this->getCollectionName()); $collection = $client->selectCollection($this->getDatabaseName(), $this->getCollectionName());
$debug = $collection->__debugInfo(); $debug = $collection->__debugInfo();
$this->assertInstanceOf(\MongoDB\Driver\ReadConcern::class, $debug['readConcern']); $this->assertInstanceOf(ReadConcern::class, $debug['readConcern']);
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertIsArray($debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
...@@ -86,13 +86,13 @@ class ClientTest extends TestCase ...@@ -86,13 +86,13 @@ class ClientTest extends TestCase
$collection = $client->selectCollection($this->getDatabaseName(), $this->getCollectionName(), $collectionOptions); $collection = $client->selectCollection($this->getDatabaseName(), $this->getCollectionName(), $collectionOptions);
$debug = $collection->__debugInfo(); $debug = $collection->__debugInfo();
$this->assertInstanceOf(\MongoDB\Driver\ReadConcern::class, $debug['readConcern']); $this->assertInstanceOf(ReadConcern::class, $debug['readConcern']);
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertIsArray($debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
...@@ -105,7 +105,7 @@ class ClientTest extends TestCase ...@@ -105,7 +105,7 @@ class ClientTest extends TestCase
$debug = $database->__debugInfo(); $debug = $database->__debugInfo();
$this->assertSame($this->getDatabaseName(), $debug['databaseName']); $this->assertSame($this->getDatabaseName(), $debug['databaseName']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
...@@ -125,13 +125,13 @@ class ClientTest extends TestCase ...@@ -125,13 +125,13 @@ class ClientTest extends TestCase
$database = $client->selectDatabase($this->getDatabaseName()); $database = $client->selectDatabase($this->getDatabaseName());
$debug = $database->__debugInfo(); $debug = $database->__debugInfo();
$this->assertInstanceOf(\MongoDB\Driver\ReadConcern::class, $debug['readConcern']); $this->assertInstanceOf(ReadConcern::class, $debug['readConcern']);
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertIsArray($debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
...@@ -148,13 +148,13 @@ class ClientTest extends TestCase ...@@ -148,13 +148,13 @@ class ClientTest extends TestCase
$database = $client->selectDatabase($this->getDatabaseName(), $databaseOptions); $database = $client->selectDatabase($this->getDatabaseName(), $databaseOptions);
$debug = $database->__debugInfo(); $debug = $database->__debugInfo();
$this->assertInstanceOf(\MongoDB\Driver\ReadConcern::class, $debug['readConcern']); $this->assertInstanceOf(ReadConcern::class, $debug['readConcern']);
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertIsArray($debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
} }
This diff is collapsed.
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace MongoDB\Tests\Collection; namespace MongoDB\Tests\Collection;
use MongoDB\Collection; use MongoDB\Collection;
use MongoDB\Driver\WriteConcern;
use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase; use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
......
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
namespace MongoDB\Tests; namespace MongoDB\Tests;
use Exception;
use MongoDB\Driver\Monitoring\CommandFailedEvent; use MongoDB\Driver\Monitoring\CommandFailedEvent;
use MongoDB\Driver\Monitoring\CommandStartedEvent; use MongoDB\Driver\Monitoring\CommandStartedEvent;
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
use MongoDB\Driver\Monitoring\CommandSubscriber; use MongoDB\Driver\Monitoring\CommandSubscriber;
use Exception; use MongoDB\Driver\Monitoring\CommandSucceededEvent;
use function call_user_func;
use function MongoDB\Driver\Monitoring\addSubscriber;
use function MongoDB\Driver\Monitoring\removeSubscriber;
/** /**
* Observes command documents using the driver's monitoring API. * Observes command documents using the driver's monitoring API.
...@@ -19,13 +22,14 @@ class CommandObserver implements CommandSubscriber ...@@ -19,13 +22,14 @@ class CommandObserver implements CommandSubscriber
{ {
$this->commands = []; $this->commands = [];
\MongoDB\Driver\Monitoring\addSubscriber($this); addSubscriber($this);
try { try {
call_user_func($execution); call_user_func($execution);
} catch (Exception $executionException) {} } catch (Exception $executionException) {
}
\MongoDB\Driver\Monitoring\removeSubscriber($this); removeSubscriber($this);
foreach ($this->commands as $command) { foreach ($this->commands as $command) {
call_user_func($commandCallback, $command); call_user_func($commandCallback, $command);
......
...@@ -2,9 +2,13 @@ ...@@ -2,9 +2,13 @@
namespace MongoDB\Tests\Database; namespace MongoDB\Tests\Database;
use InvalidArgumentException;
use MongoDB\Driver\BulkWrite; use MongoDB\Driver\BulkWrite;
use MongoDB\Model\CollectionInfo; use MongoDB\Model\CollectionInfo;
use InvalidArgumentException; use MongoDB\Model\CollectionInfoIterator;
use function call_user_func;
use function is_callable;
use function sprintf;
/** /**
* Functional tests for collection management methods. * Functional tests for collection management methods.
...@@ -18,7 +22,7 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase ...@@ -18,7 +22,7 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase
$commandResult = $this->database->createCollection($basicCollectionName); $commandResult = $this->database->createCollection($basicCollectionName);
$this->assertCommandSucceeded($commandResult); $this->assertCommandSucceeded($commandResult);
$this->assertCollectionExists($basicCollectionName, function(CollectionInfo $info) use ($that) { $this->assertCollectionExists($basicCollectionName, function (CollectionInfo $info) use ($that) {
$that->assertFalse($info->isCapped()); $that->assertFalse($info->isCapped());
}); });
...@@ -31,7 +35,7 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase ...@@ -31,7 +35,7 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase
$commandResult = $this->database->createCollection($cappedCollectionName, $cappedCollectionOptions); $commandResult = $this->database->createCollection($cappedCollectionName, $cappedCollectionOptions);
$this->assertCommandSucceeded($commandResult); $this->assertCommandSucceeded($commandResult);
$this->assertCollectionExists($cappedCollectionName, function(CollectionInfo $info) use ($that) { $this->assertCollectionExists($cappedCollectionName, function (CollectionInfo $info) use ($that) {
$that->assertTrue($info->isCapped()); $that->assertTrue($info->isCapped());
$that->assertEquals(100, $info->getCappedMax()); $that->assertEquals(100, $info->getCappedMax());
$that->assertEquals(1048576, $info->getCappedSize()); $that->assertEquals(1048576, $info->getCappedSize());
...@@ -57,10 +61,10 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase ...@@ -57,10 +61,10 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase
$this->assertCommandSucceeded($commandResult); $this->assertCommandSucceeded($commandResult);
$collections = $this->database->listCollections(); $collections = $this->database->listCollections();
$this->assertInstanceOf(\MongoDB\Model\CollectionInfoIterator::class, $collections); $this->assertInstanceOf(CollectionInfoIterator::class, $collections);
foreach ($collections as $collection) { foreach ($collections as $collection) {
$this->assertInstanceOf(\MongoDB\Model\CollectionInfo::class, $collection); $this->assertInstanceOf(CollectionInfo::class, $collection);
} }
} }
...@@ -73,10 +77,10 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase ...@@ -73,10 +77,10 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase
$options = ['filter' => ['name' => $collectionName]]; $options = ['filter' => ['name' => $collectionName]];
$collections = $this->database->listCollections($options); $collections = $this->database->listCollections($options);
$this->assertInstanceOf(\MongoDB\Model\CollectionInfoIterator::class, $collections); $this->assertInstanceOf(CollectionInfoIterator::class, $collections);
foreach ($collections as $collection) { foreach ($collections as $collection) {
$this->assertInstanceOf(\MongoDB\Model\CollectionInfo::class, $collection); $this->assertInstanceOf(CollectionInfo::class, $collection);
$this->assertEquals($collectionName, $collection->getName()); $this->assertEquals($collectionName, $collection->getName());
} }
} }
......
...@@ -4,11 +4,14 @@ namespace MongoDB\Tests\Database; ...@@ -4,11 +4,14 @@ namespace MongoDB\Tests\Database;
use MongoDB\Database; use MongoDB\Database;
use MongoDB\Driver\BulkWrite; use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\Cursor;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\CreateIndexes; use MongoDB\Operation\CreateIndexes;
use function array_key_exists;
use function current;
/** /**
* Functional tests for the Database class. * Functional tests for the Database class.
...@@ -89,7 +92,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -89,7 +92,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$cursor = $this->database->command($command, $options); $cursor = $this->database->command($command, $options);
$this->assertInstanceOf(\MongoDB\Driver\Cursor::class, $cursor); $this->assertInstanceOf(Cursor::class, $cursor);
$commandResult = current($cursor->toArray()); $commandResult = current($cursor->toArray());
$this->assertCommandSucceeded($commandResult); $this->assertCommandSucceeded($commandResult);
...@@ -107,7 +110,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -107,7 +110,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$cursor = $this->database->command($command, $options); $cursor = $this->database->command($command, $options);
$this->assertInstanceOf(\MongoDB\Driver\Cursor::class, $cursor); $this->assertInstanceOf(Cursor::class, $cursor);
$commandResult = current($cursor->toArray()); $commandResult = current($cursor->toArray());
$this->assertCommandSucceeded($commandResult); $this->assertCommandSucceeded($commandResult);
...@@ -149,7 +152,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -149,7 +152,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this->assertSame($this->manager, $debug['manager']); $this->assertSame($this->manager, $debug['manager']);
$this->assertSame($this->getDatabaseName(), $debug['databaseName']); $this->assertSame($this->getDatabaseName(), $debug['databaseName']);
$this->assertSame($this->getCollectionName(), $debug['collectionName']); $this->assertSame($this->getCollectionName(), $debug['collectionName']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
...@@ -186,7 +189,6 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -186,7 +189,6 @@ class DatabaseFunctionalTest extends FunctionalTestCase
} }
} }
public function testSelectCollectionInheritsOptions() public function testSelectCollectionInheritsOptions()
{ {
$databaseOptions = [ $databaseOptions = [
...@@ -203,13 +205,13 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -203,13 +205,13 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this->assertSame($this->manager, $debug['manager']); $this->assertSame($this->manager, $debug['manager']);
$this->assertSame($this->getDatabaseName(), $debug['databaseName']); $this->assertSame($this->getDatabaseName(), $debug['databaseName']);
$this->assertSame($this->getCollectionName(), $debug['collectionName']); $this->assertSame($this->getCollectionName(), $debug['collectionName']);
$this->assertInstanceOf(\MongoDB\Driver\ReadConcern::class, $debug['readConcern']); $this->assertInstanceOf(ReadConcern::class, $debug['readConcern']);
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertIsArray($debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
...@@ -225,13 +227,13 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -225,13 +227,13 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$collection = $this->database->selectCollection($this->getCollectionName(), $collectionOptions); $collection = $this->database->selectCollection($this->getCollectionName(), $collectionOptions);
$debug = $collection->__debugInfo(); $debug = $collection->__debugInfo();
$this->assertInstanceOf(\MongoDB\Driver\ReadConcern::class, $debug['readConcern']); $this->assertInstanceOf(ReadConcern::class, $debug['readConcern']);
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertIsArray($debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
...@@ -251,11 +253,11 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -251,11 +253,11 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this->assertSame($this->getDatabaseName(), $debug['databaseName']); $this->assertSame($this->getDatabaseName(), $debug['databaseName']);
$this->assertSame('fs', $debug['bucketName']); $this->assertSame('fs', $debug['bucketName']);
$this->assertSame(261120, $debug['chunkSizeBytes']); $this->assertSame(261120, $debug['chunkSizeBytes']);
$this->assertInstanceOf(\MongoDB\Driver\ReadConcern::class, $debug['readConcern']); $this->assertInstanceOf(ReadConcern::class, $debug['readConcern']);
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
...@@ -276,11 +278,11 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -276,11 +278,11 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this->assertSame($this->getDatabaseName(), $debug['databaseName']); $this->assertSame($this->getDatabaseName(), $debug['databaseName']);
$this->assertSame('custom_fs', $debug['bucketName']); $this->assertSame('custom_fs', $debug['bucketName']);
$this->assertSame(8192, $debug['chunkSizeBytes']); $this->assertSame(8192, $debug['chunkSizeBytes']);
$this->assertInstanceOf(\MongoDB\Driver\ReadConcern::class, $debug['readConcern']); $this->assertInstanceOf(ReadConcern::class, $debug['readConcern']);
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
...@@ -299,13 +301,13 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -299,13 +301,13 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this->assertSame($this->manager, $debug['manager']); $this->assertSame($this->manager, $debug['manager']);
$this->assertSame($this->getDatabaseName(), $debug['databaseName']); $this->assertSame($this->getDatabaseName(), $debug['databaseName']);
$this->assertInstanceOf(\MongoDB\Driver\ReadConcern::class, $debug['readConcern']); $this->assertInstanceOf(ReadConcern::class, $debug['readConcern']);
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertIsArray($debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
...@@ -321,13 +323,13 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -321,13 +323,13 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$clone = $this->database->withOptions($databaseOptions); $clone = $this->database->withOptions($databaseOptions);
$debug = $clone->__debugInfo(); $debug = $clone->__debugInfo();
$this->assertInstanceOf(\MongoDB\Driver\ReadConcern::class, $debug['readConcern']); $this->assertInstanceOf(ReadConcern::class, $debug['readConcern']);
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertIsArray($debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
} }
} }
...@@ -2,21 +2,33 @@ ...@@ -2,21 +2,33 @@
namespace MongoDB\Tests; namespace MongoDB\Tests;
use InvalidArgumentException;
use MongoDB\BSON\ObjectId;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Exception\CommandException;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Query; use MongoDB\Driver\Query;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\CommandException;
use MongoDB\Operation\CreateCollection; use MongoDB\Operation\CreateCollection;
use MongoDB\Operation\DatabaseCommand; use MongoDB\Operation\DatabaseCommand;
use MongoDB\Operation\DropCollection; use MongoDB\Operation\DropCollection;
use InvalidArgumentException;
use stdClass; use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use UnexpectedValueException; use UnexpectedValueException;
use function array_merge;
use function count;
use function current;
use function explode;
use function implode;
use function is_array;
use function is_object;
use function is_string;
use function key;
use function parse_url;
use function preg_match;
use function version_compare;
abstract class FunctionalTestCase extends TestCase abstract class FunctionalTestCase extends TestCase
{ {
...@@ -75,9 +87,7 @@ abstract class FunctionalTestCase extends TestCase ...@@ -75,9 +87,7 @@ abstract class FunctionalTestCase extends TestCase
$hosts[$numHosts-1] .= ':' . $urlParts['port']; $hosts[$numHosts-1] .= ':' . $urlParts['port'];
} }
$parts = [ $parts = ['mongodb://'];
'mongodb://'
];
if (isset($urlParts['user'], $urlParts['pass'])) { if (isset($urlParts['user'], $urlParts['pass'])) {
$parts += [ $parts += [
...@@ -96,7 +106,7 @@ abstract class FunctionalTestCase extends TestCase ...@@ -96,7 +106,7 @@ abstract class FunctionalTestCase extends TestCase
if (isset($urlParts['query'])) { if (isset($urlParts['query'])) {
$parts = array_merge($parts, [ $parts = array_merge($parts, [
'?', '?',
$urlParts['query'] $urlParts['query'],
]); ]);
} }
...@@ -125,8 +135,8 @@ abstract class FunctionalTestCase extends TestCase ...@@ -125,8 +135,8 @@ abstract class FunctionalTestCase extends TestCase
protected function assertSameObjectId($expectedObjectId, $actualObjectId) protected function assertSameObjectId($expectedObjectId, $actualObjectId)
{ {
$this->assertInstanceOf(\MongoDB\BSON\ObjectId::class, $expectedObjectId); $this->assertInstanceOf(ObjectId::class, $expectedObjectId);
$this->assertInstanceOf(\MongoDB\BSON\ObjectId::class, $actualObjectId); $this->assertInstanceOf(ObjectId::class, $actualObjectId);
$this->assertEquals((string) $expectedObjectId, (string) $actualObjectId); $this->assertEquals((string) $expectedObjectId, (string) $actualObjectId);
} }
...@@ -153,7 +163,7 @@ abstract class FunctionalTestCase extends TestCase ...@@ -153,7 +163,7 @@ abstract class FunctionalTestCase extends TestCase
$command = (object) $command; $command = (object) $command;
} }
if ( ! $command instanceof stdClass) { if (! $command instanceof stdClass) {
throw new InvalidArgumentException('$command is not an array or stdClass instance'); throw new InvalidArgumentException('$command is not an array or stdClass instance');
} }
...@@ -300,7 +310,7 @@ abstract class FunctionalTestCase extends TestCase ...@@ -300,7 +310,7 @@ abstract class FunctionalTestCase extends TestCase
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']); $cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
$document = current($cursor->toArray()); $document = current($cursor->toArray());
if (! $document ) { if (! $document) {
return false; return false;
} }
...@@ -314,13 +324,12 @@ abstract class FunctionalTestCase extends TestCase ...@@ -314,13 +324,12 @@ abstract class FunctionalTestCase extends TestCase
protected function skipIfChangeStreamIsNotSupported() protected function skipIfChangeStreamIsNotSupported()
{ {
switch ( $this->getPrimaryServer()->getType() ) switch ($this->getPrimaryServer()->getType()) {
{
case Server::TYPE_MONGOS: case Server::TYPE_MONGOS:
if (version_compare($this->getServerVersion(), '3.6.0', '<')) { if (version_compare($this->getServerVersion(), '3.6.0', '<')) {
$this->markTestSkipped('$changeStream is only supported on MongoDB 3.6 or higher'); $this->markTestSkipped('$changeStream is only supported on MongoDB 3.6 or higher');
} }
if (!$this->isShardedClusterUsingReplicasets()) { if (! $this->isShardedClusterUsingReplicasets()) {
$this->markTestSkipped('$changeStream is only supported with replicasets'); $this->markTestSkipped('$changeStream is only supported with replicasets');
} }
...@@ -341,13 +350,12 @@ abstract class FunctionalTestCase extends TestCase ...@@ -341,13 +350,12 @@ abstract class FunctionalTestCase extends TestCase
protected function skipIfCausalConsistencyIsNotSupported() protected function skipIfCausalConsistencyIsNotSupported()
{ {
switch ( $this->getPrimaryServer()->getType() ) switch ($this->getPrimaryServer()->getType()) {
{
case Server::TYPE_MONGOS: case Server::TYPE_MONGOS:
if (version_compare($this->getServerVersion(), '3.6.0', '<')) { if (version_compare($this->getServerVersion(), '3.6.0', '<')) {
$this->markTestSkipped('Causal Consistency is only supported on MongoDB 3.6 or higher'); $this->markTestSkipped('Causal Consistency is only supported on MongoDB 3.6 or higher');
} }
if (!$this->isShardedClusterUsingReplicasets()) { if (! $this->isShardedClusterUsingReplicasets()) {
$this->markTestSkipped('Causal Consistency is only supported with replicasets'); $this->markTestSkipped('Causal Consistency is only supported with replicasets');
} }
break; break;
......
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
namespace MongoDB\Tests; namespace MongoDB\Tests;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\BSONArray; use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
use MongoDB\Driver\ReadConcern; use function MongoDB\apply_type_map_to_document;
use MongoDB\Driver\WriteConcern; use function MongoDB\create_field_path_type_map;
use MongoDB\Exception\InvalidArgumentException; use function MongoDB\generate_index_name;
use function MongoDB\is_first_key_operator;
use function MongoDB\is_mapreduce_output_inline;
/** /**
* Unit tests for utility functions. * Unit tests for utility functions.
...@@ -18,7 +21,7 @@ class FunctionsTest extends TestCase ...@@ -18,7 +21,7 @@ class FunctionsTest extends TestCase
*/ */
public function testApplyTypeMapToDocument($document, array $typeMap, $expectedDocument) public function testApplyTypeMapToDocument($document, array $typeMap, $expectedDocument)
{ {
$this->assertEquals($expectedDocument, \MongoDB\apply_type_map_to_document($document, $typeMap)); $this->assertEquals($expectedDocument, apply_type_map_to_document($document, $typeMap));
} }
public function provideDocumentAndTypeMap() public function provideDocumentAndTypeMap()
...@@ -61,37 +64,27 @@ class FunctionsTest extends TestCase ...@@ -61,37 +64,27 @@ class FunctionsTest extends TestCase
[ [
[ [
'x' => 1, 'x' => 1,
'random' => [ 'random' => ['foo' => 'bar'],
'foo' => 'bar',
],
'value' => [ 'value' => [
'bar' => 'baz', 'bar' => 'baz',
'embedded' => [ 'embedded' => ['foo' => 'bar'],
'foo' => 'bar',
],
], ],
], ],
[ [
'root' => 'array', 'root' => 'array',
'document' => 'stdClass', 'document' => 'stdClass',
'array' => 'array', 'array' => 'array',
'fieldPaths' => [ 'fieldPaths' => ['value' => 'array'],
'value' => 'array',
],
], ],
[ [
'x' => 1, 'x' => 1,
'random' => (object) [ 'random' => (object) ['foo' => 'bar'],
'foo' => 'bar',
],
'value' => [ 'value' => [
'bar' => 'baz', 'bar' => 'baz',
'embedded' => (object) [ 'embedded' => (object) ['foo' => 'bar'],
'foo' => 'bar',
],
], ],
], ],
] ],
]; ];
} }
...@@ -100,7 +93,7 @@ class FunctionsTest extends TestCase ...@@ -100,7 +93,7 @@ class FunctionsTest extends TestCase
*/ */
public function testGenerateIndexName($document, $expectedName) public function testGenerateIndexName($document, $expectedName)
{ {
$this->assertSame($expectedName, \MongoDB\generate_index_name($document)); $this->assertSame($expectedName, generate_index_name($document));
} }
public function provideIndexSpecificationDocumentsAndGeneratedNames() public function provideIndexSpecificationDocumentsAndGeneratedNames()
...@@ -120,7 +113,7 @@ class FunctionsTest extends TestCase ...@@ -120,7 +113,7 @@ class FunctionsTest extends TestCase
public function testGenerateIndexNameArgumentTypeCheck($document) public function testGenerateIndexNameArgumentTypeCheck($document)
{ {
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
\MongoDB\generate_index_name($document); generate_index_name($document);
} }
/** /**
...@@ -128,7 +121,7 @@ class FunctionsTest extends TestCase ...@@ -128,7 +121,7 @@ class FunctionsTest extends TestCase
*/ */
public function testIsFirstKeyOperator($document, $isFirstKeyOperator) public function testIsFirstKeyOperator($document, $isFirstKeyOperator)
{ {
$this->assertSame($isFirstKeyOperator, \MongoDB\is_first_key_operator($document)); $this->assertSame($isFirstKeyOperator, is_first_key_operator($document));
} }
public function provideIsFirstKeyOperatorDocuments() public function provideIsFirstKeyOperatorDocuments()
...@@ -149,7 +142,7 @@ class FunctionsTest extends TestCase ...@@ -149,7 +142,7 @@ class FunctionsTest extends TestCase
public function testIsFirstKeyOperatorArgumentTypeCheck($document) public function testIsFirstKeyOperatorArgumentTypeCheck($document)
{ {
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
\MongoDB\is_first_key_operator($document); is_first_key_operator($document);
} }
/** /**
...@@ -157,7 +150,7 @@ class FunctionsTest extends TestCase ...@@ -157,7 +150,7 @@ class FunctionsTest extends TestCase
*/ */
public function testIsMapReduceOutputInline($out, $isInline) public function testIsMapReduceOutputInline($out, $isInline)
{ {
$this->assertSame($isInline, \MongoDB\is_mapreduce_output_inline($out)); $this->assertSame($isInline, is_mapreduce_output_inline($out));
} }
public function provideMapReduceOutValues() public function provideMapReduceOutValues()
...@@ -175,7 +168,7 @@ class FunctionsTest extends TestCase ...@@ -175,7 +168,7 @@ class FunctionsTest extends TestCase
*/ */
public function testCreateFieldPathTypeMap(array $expected, array $typeMap, $fieldPath = 'field') public function testCreateFieldPathTypeMap(array $expected, array $typeMap, $fieldPath = 'field')
{ {
$this->assertEquals($expected, \MongoDB\create_field_path_type_map($typeMap, $fieldPath)); $this->assertEquals($expected, create_field_path_type_map($typeMap, $fieldPath));
} }
public function provideTypeMapValues() public function provideTypeMapValues()
...@@ -205,14 +198,12 @@ class FunctionsTest extends TestCase ...@@ -205,14 +198,12 @@ class FunctionsTest extends TestCase
'field' => 'array', 'field' => 'array',
'field.$' => 'object', 'field.$' => 'object',
'field.$.nested' => 'array', 'field.$.nested' => 'array',
] ],
], ],
[ [
'root' => 'object', 'root' => 'object',
'array' => 'MongoDB\Model\BSONArray', 'array' => 'MongoDB\Model\BSONArray',
'fieldPaths' => [ 'fieldPaths' => ['nested' => 'array'],
'nested' => 'array',
]
], ],
'field.$', 'field.$',
], ],
...@@ -223,13 +214,11 @@ class FunctionsTest extends TestCase ...@@ -223,13 +214,11 @@ class FunctionsTest extends TestCase
'fieldPaths' => [ 'fieldPaths' => [
'field' => 'array', 'field' => 'array',
'field.$.nested' => 'array', 'field.$.nested' => 'array',
] ],
], ],
[ [
'array' => 'MongoDB\Model\BSONArray', 'array' => 'MongoDB\Model\BSONArray',
'fieldPaths' => [ 'fieldPaths' => ['nested' => 'array'],
'nested' => 'array',
]
], ],
'field.$', 'field.$',
], ],
......
...@@ -3,16 +3,32 @@ ...@@ -3,16 +3,32 @@
namespace MongoDB\Tests\GridFS; namespace MongoDB\Tests\GridFS;
use MongoDB\BSON\Binary; use MongoDB\BSON\Binary;
use MongoDB\Collection;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\GridFS\Bucket; use MongoDB\GridFS\Bucket;
use MongoDB\GridFS\Exception\FileNotFoundException; use MongoDB\GridFS\Exception\FileNotFoundException;
use MongoDB\Model\BSONDocument;
use MongoDB\Model\IndexInfo; use MongoDB\Model\IndexInfo;
use MongoDB\Operation\ListCollections; use MongoDB\Operation\ListCollections;
use MongoDB\Operation\ListIndexes; use MongoDB\Operation\ListIndexes;
use PHPUnit\Framework\Error\Warning; use PHPUnit\Framework\Error\Warning;
use function array_merge;
use function call_user_func;
use function current;
use function fclose;
use function fread;
use function fwrite;
use function hash_init;
use function is_callable;
use function min;
use function sprintf;
use function str_repeat;
use function stream_get_contents;
use function strlen;
use function substr;
/** /**
* Functional tests for the Bucket class. * Functional tests for the Bucket class.
...@@ -137,7 +153,8 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -137,7 +153,8 @@ class BucketFunctionalTest extends FunctionalTestCase
try { try {
$this->bucket->delete($id); $this->bucket->delete($id);
$this->fail('FileNotFoundException was not thrown'); $this->fail('FileNotFoundException was not thrown');
} catch (FileNotFoundException $e) {} } catch (FileNotFoundException $e) {
}
$this->assertCollectionCount($this->chunksCollection, 0); $this->assertCollectionCount($this->chunksCollection, 0);
} }
...@@ -323,7 +340,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -323,7 +340,7 @@ class BucketFunctionalTest extends FunctionalTestCase
$cursor = $this->bucket->find(); $cursor = $this->bucket->find();
$fileDocument = current($cursor->toArray()); $fileDocument = current($cursor->toArray());
$this->assertInstanceOf(\MongoDB\Model\BSONDocument::class, $fileDocument); $this->assertInstanceOf(BSONDocument::class, $fileDocument);
} }
public function testFindOne() public function testFindOne()
...@@ -344,7 +361,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -344,7 +361,7 @@ class BucketFunctionalTest extends FunctionalTestCase
] ]
); );
$this->assertInstanceOf(\MongoDB\Model\BSONDocument::class, $fileDocument); $this->assertInstanceOf(BSONDocument::class, $fileDocument);
$this->assertSameDocument(['filename' => 'b', 'length' => 6], $fileDocument); $this->assertSameDocument(['filename' => 'b', 'length' => 6], $fileDocument);
} }
...@@ -364,7 +381,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -364,7 +381,7 @@ class BucketFunctionalTest extends FunctionalTestCase
{ {
$chunksCollection = $this->bucket->getChunksCollection(); $chunksCollection = $this->bucket->getChunksCollection();
$this->assertInstanceOf(\MongoDB\Collection::class, $chunksCollection); $this->assertInstanceOf(Collection::class, $chunksCollection);
$this->assertEquals('fs.chunks', $chunksCollection->getCollectionName()); $this->assertEquals('fs.chunks', $chunksCollection->getCollectionName());
} }
...@@ -392,8 +409,8 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -392,8 +409,8 @@ class BucketFunctionalTest extends FunctionalTestCase
$fileDocument = $this->bucket->getFileDocumentForStream($stream); $fileDocument = $this->bucket->getFileDocumentForStream($stream);
$this->assertInstanceOf(\MongoDB\Model\BSONDocument::class, $fileDocument); $this->assertInstanceOf(BSONDocument::class, $fileDocument);
$this->assertInstanceOf(\MongoDB\Model\BSONDocument::class, $fileDocument['metadata']); $this->assertInstanceOf(BSONDocument::class, $fileDocument['metadata']);
$this->assertSame(['foo' => 'bar'], $fileDocument['metadata']->getArrayCopy()); $this->assertSame(['foo' => 'bar'], $fileDocument['metadata']->getArrayCopy());
} }
...@@ -443,7 +460,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -443,7 +460,7 @@ class BucketFunctionalTest extends FunctionalTestCase
$id = $this->bucket->getFileIdForStream($stream); $id = $this->bucket->getFileIdForStream($stream);
$this->assertInstanceOf(\MongoDB\Model\BSONDocument::class, $id); $this->assertInstanceOf(BSONDocument::class, $id);
$this->assertSame(['x' => 1], $id->getArrayCopy()); $this->assertSame(['x' => 1], $id->getArrayCopy());
} }
...@@ -475,7 +492,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -475,7 +492,7 @@ class BucketFunctionalTest extends FunctionalTestCase
{ {
$filesCollection = $this->bucket->getFilesCollection(); $filesCollection = $this->bucket->getFilesCollection();
$this->assertInstanceOf(\MongoDB\Collection::class, $filesCollection); $this->assertInstanceOf(Collection::class, $filesCollection);
$this->assertEquals('fs.files', $filesCollection->getCollectionName()); $this->assertEquals('fs.files', $filesCollection->getCollectionName());
} }
...@@ -675,7 +692,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -675,7 +692,7 @@ class BucketFunctionalTest extends FunctionalTestCase
$this->bucket->uploadFromStream('filename', $this->createStream('foo')); $this->bucket->uploadFromStream('filename', $this->createStream('foo'));
$this->assertIndexExists($this->filesCollection->getCollectionName(), 'filename_1_uploadDate_1'); $this->assertIndexExists($this->filesCollection->getCollectionName(), 'filename_1_uploadDate_1');
$this->assertIndexExists($this->chunksCollection->getCollectionName(), 'files_id_1_n_1', function(IndexInfo $info) { $this->assertIndexExists($this->chunksCollection->getCollectionName(), 'files_id_1_n_1', function (IndexInfo $info) {
$this->assertTrue($info->isUnique()); $this->assertTrue($info->isUnique());
}); });
} }
......
...@@ -6,6 +6,11 @@ use MongoDB\Collection; ...@@ -6,6 +6,11 @@ use MongoDB\Collection;
use MongoDB\GridFS\Bucket; use MongoDB\GridFS\Bucket;
use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase; use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use function fopen;
use function fwrite;
use function get_resource_type;
use function rewind;
use function stream_get_contents;
/** /**
* Base class for GridFS functional tests. * Base class for GridFS functional tests.
......
...@@ -5,11 +5,11 @@ namespace MongoDB\Tests\GridFS; ...@@ -5,11 +5,11 @@ namespace MongoDB\Tests\GridFS;
use MongoDB\BSON\Binary; use MongoDB\BSON\Binary;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\GridFS\CollectionWrapper; use MongoDB\GridFS\CollectionWrapper;
use MongoDB\GridFS\ReadableStream;
use MongoDB\GridFS\Exception\CorruptFileException; use MongoDB\GridFS\Exception\CorruptFileException;
use MongoDB\GridFS\ReadableStream;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use function array_filter;
/** /**
* Functional tests for the internal ReadableStream class. * Functional tests for the internal ReadableStream class.
...@@ -119,8 +119,9 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase ...@@ -119,8 +119,9 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
public function provideFilteredFileIdAndExpectedBytes() public function provideFilteredFileIdAndExpectedBytes()
{ {
return array_filter($this->provideFileIdAndExpectedBytes(), return array_filter(
function(array $args) { $this->provideFileIdAndExpectedBytes(),
function (array $args) {
return $args[1] > 0; return $args[1] > 0;
} }
); );
...@@ -219,12 +220,12 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase ...@@ -219,12 +220,12 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
$commands = []; $commands = [];
(new CommandObserver)->observe( (new CommandObserver())->observe(
function() use ($stream, $offset, $length, $expectedBytes) { function () use ($stream, $offset, $length, $expectedBytes) {
$stream->seek($offset); $stream->seek($offset);
$this->assertSame($expectedBytes, $stream->readBytes($length)); $this->assertSame($expectedBytes, $stream->readBytes($length));
}, },
function(array $event) use (&$commands) { function (array $event) use (&$commands) {
$commands[] = $event['started']->getCommandName(); $commands[] = $event['started']->getCommandName();
} }
); );
...@@ -255,12 +256,12 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase ...@@ -255,12 +256,12 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
$commands = []; $commands = [];
(new CommandObserver)->observe( (new CommandObserver())->observe(
function() use ($stream, $offset, $length, $expectedBytes) { function () use ($stream, $offset, $length, $expectedBytes) {
$stream->seek($offset); $stream->seek($offset);
$this->assertSame($expectedBytes, $stream->readBytes($length)); $this->assertSame($expectedBytes, $stream->readBytes($length));
}, },
function(array $event) use (&$commands) { function (array $event) use (&$commands) {
$commands[] = $event['started']->getCommandName(); $commands[] = $event['started']->getCommandName();
} }
); );
...@@ -289,12 +290,12 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase ...@@ -289,12 +290,12 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
$commands = []; $commands = [];
(new CommandObserver)->observe( (new CommandObserver())->observe(
function() use ($stream, $offset, $length, $expectedBytes) { function () use ($stream, $offset, $length, $expectedBytes) {
$stream->seek($offset); $stream->seek($offset);
$this->assertSame($expectedBytes, $stream->readBytes($length)); $this->assertSame($expectedBytes, $stream->readBytes($length));
}, },
function(array $event) use (&$commands) { function (array $event) use (&$commands) {
$commands[] = $event['started']->getCommandName(); $commands[] = $event['started']->getCommandName();
} }
); );
......
This diff is collapsed.
...@@ -5,6 +5,15 @@ namespace MongoDB\Tests\GridFS; ...@@ -5,6 +5,15 @@ namespace MongoDB\Tests\GridFS;
use MongoDB\BSON\Binary; use MongoDB\BSON\Binary;
use MongoDB\BSON\UTCDateTime; use MongoDB\BSON\UTCDateTime;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use function fclose;
use function feof;
use function fread;
use function fseek;
use function fstat;
use function fwrite;
use const SEEK_CUR;
use const SEEK_END;
use const SEEK_SET;
/** /**
* Functional tests for the internal StreamWrapper class. * Functional tests for the internal StreamWrapper class.
...@@ -57,26 +66,26 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase ...@@ -57,26 +66,26 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
{ {
$stream = $this->bucket->openDownloadStream('length-10'); $stream = $this->bucket->openDownloadStream('length-10');
$this->assertSame(0, fseek($stream, 2, \SEEK_SET)); $this->assertSame(0, fseek($stream, 2, SEEK_SET));
$this->assertSame('cde', fread($stream, 3)); $this->assertSame('cde', fread($stream, 3));
$this->assertSame(0, fseek($stream, 10, \SEEK_SET)); $this->assertSame(0, fseek($stream, 10, SEEK_SET));
$this->assertSame('', fread($stream, 3)); $this->assertSame('', fread($stream, 3));
$this->assertSame(-1, fseek($stream, -1, \SEEK_SET)); $this->assertSame(-1, fseek($stream, -1, SEEK_SET));
$this->assertSame(-1, fseek($stream, 11, \SEEK_SET)); $this->assertSame(-1, fseek($stream, 11, SEEK_SET));
$this->assertSame(0, fseek($stream, -5, \SEEK_CUR)); $this->assertSame(0, fseek($stream, -5, SEEK_CUR));
$this->assertSame('fgh', fread($stream, 3)); $this->assertSame('fgh', fread($stream, 3));
$this->assertSame(0, fseek($stream, 1, \SEEK_CUR)); $this->assertSame(0, fseek($stream, 1, SEEK_CUR));
$this->assertSame('j', fread($stream, 3)); $this->assertSame('j', fread($stream, 3));
$this->assertSame(-1, fseek($stream, 1, \SEEK_CUR)); $this->assertSame(-1, fseek($stream, 1, SEEK_CUR));
$this->assertSame(-1, fseek($stream, -11, \SEEK_CUR)); $this->assertSame(-1, fseek($stream, -11, SEEK_CUR));
$this->assertSame(0, fseek($stream, 0, \SEEK_END)); $this->assertSame(0, fseek($stream, 0, SEEK_END));
$this->assertSame('', fread($stream, 3)); $this->assertSame('', fread($stream, 3));
$this->assertSame(0, fseek($stream, -8, \SEEK_END)); $this->assertSame(0, fseek($stream, -8, SEEK_END));
$this->assertSame('cde', fread($stream, 3)); $this->assertSame('cde', fread($stream, 3));
$this->assertSame(-1, fseek($stream, -11, \SEEK_END)); $this->assertSame(-1, fseek($stream, -11, SEEK_END));
$this->assertSame(-1, fseek($stream, 1, \SEEK_END)); $this->assertSame(-1, fseek($stream, 1, SEEK_END));
} }
public function testReadableStreamStat() public function testReadableStreamStat()
...@@ -137,17 +146,17 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase ...@@ -137,17 +146,17 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
$this->assertSame(6, fwrite($stream, 'foobar')); $this->assertSame(6, fwrite($stream, 'foobar'));
$this->assertSame(-1, fseek($stream, 0, \SEEK_SET)); $this->assertSame(-1, fseek($stream, 0, SEEK_SET));
$this->assertSame(-1, fseek($stream, 7, \SEEK_SET)); $this->assertSame(-1, fseek($stream, 7, SEEK_SET));
$this->assertSame(0, fseek($stream, 6, \SEEK_SET)); $this->assertSame(0, fseek($stream, 6, SEEK_SET));
$this->assertSame(0, fseek($stream, 0, \SEEK_CUR)); $this->assertSame(0, fseek($stream, 0, SEEK_CUR));
$this->assertSame(-1, fseek($stream, -1, \SEEK_CUR)); $this->assertSame(-1, fseek($stream, -1, SEEK_CUR));
$this->assertSame(-1, fseek($stream, 1, \SEEK_CUR)); $this->assertSame(-1, fseek($stream, 1, SEEK_CUR));
$this->assertSame(0, fseek($stream, 0, \SEEK_END)); $this->assertSame(0, fseek($stream, 0, SEEK_END));
$this->assertSame(-1, fseek($stream, -1, \SEEK_END)); $this->assertSame(-1, fseek($stream, -1, SEEK_END));
$this->assertSame(-1, fseek($stream, 1, \SEEK_END)); $this->assertSame(-1, fseek($stream, 1, SEEK_END));
} }
public function testWritableStreamStatBeforeSaving() public function testWritableStreamStatBeforeSaving()
...@@ -171,7 +180,7 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase ...@@ -171,7 +180,7 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
$stat = fstat($stream); $stat = fstat($stream);
$this->assertSame(6, $stat[7]); $this->assertSame(6, $stat[7]);
$this->assertSame(6, $stat['size']); $this->assertSame(6, $stat['size']);
} }
public function testWritableStreamStatAfterSaving() public function testWritableStreamStatAfterSaving()
{ {
......
...@@ -6,6 +6,7 @@ use MongoDB\Exception\InvalidArgumentException; ...@@ -6,6 +6,7 @@ use MongoDB\Exception\InvalidArgumentException;
use MongoDB\GridFS\CollectionWrapper; use MongoDB\GridFS\CollectionWrapper;
use MongoDB\GridFS\WritableStream; use MongoDB\GridFS\WritableStream;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use function str_repeat;
/** /**
* Functional tests for the internal WritableStream class. * Functional tests for the internal WritableStream class.
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
namespace MongoDB\Tests\Model; namespace MongoDB\Tests\Model;
use Exception;
use MongoDB\Model\CachingIterator; use MongoDB\Model\CachingIterator;
use MongoDB\Tests\TestCase; use MongoDB\Tests\TestCase;
use Exception; use function iterator_to_array;
class CachingIteratorTest extends TestCase class CachingIteratorTest extends TestCase
{ {
...@@ -52,7 +53,7 @@ class CachingIteratorTest extends TestCase ...@@ -52,7 +53,7 @@ class CachingIteratorTest extends TestCase
public function testPartialIterationDoesNotExhaust() public function testPartialIterationDoesNotExhaust()
{ {
$traversable = $this->getTraversableThatThrows([1, 2, new Exception]); $traversable = $this->getTraversableThatThrows([1, 2, new Exception()]);
$iterator = new CachingIterator($traversable); $iterator = new CachingIterator($traversable);
$expectedKey = 0; $expectedKey = 0;
......
This diff is collapsed.
...@@ -64,7 +64,7 @@ class CollectionInfoTest extends TestCase ...@@ -64,7 +64,7 @@ class CollectionInfoTest extends TestCase
{ {
$info = new CollectionInfo(['name' => 'foo', 'options' => ['capped' => true, 'size' => 1048576]]); $info = new CollectionInfo(['name' => 'foo', 'options' => ['capped' => true, 'size' => 1048576]]);
$this->expectException(BadMethodCallException::class); $this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage(CollectionInfo::class .' is immutable'); $this->expectExceptionMessage(CollectionInfo::class . ' is immutable');
$info['options'] = ['capped' => false]; $info['options'] = ['capped' => false];
} }
...@@ -72,7 +72,7 @@ class CollectionInfoTest extends TestCase ...@@ -72,7 +72,7 @@ class CollectionInfoTest extends TestCase
{ {
$info = new CollectionInfo(['name' => 'foo', 'options' => ['capped' => true, 'size' => 1048576]]); $info = new CollectionInfo(['name' => 'foo', 'options' => ['capped' => true, 'size' => 1048576]]);
$this->expectException(BadMethodCallException::class); $this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage(CollectionInfo::class .' is immutable'); $this->expectExceptionMessage(CollectionInfo::class . ' is immutable');
unset($info['options']); unset($info['options']);
} }
} }
...@@ -53,7 +53,7 @@ class DatabaseInfoTest extends TestCase ...@@ -53,7 +53,7 @@ class DatabaseInfoTest extends TestCase
{ {
$info = new DatabaseInfo(['name' => 'foo', 'sizeOnDisk' => 1048576, 'empty' => false]); $info = new DatabaseInfo(['name' => 'foo', 'sizeOnDisk' => 1048576, 'empty' => false]);
$this->expectException(BadMethodCallException::class); $this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage(DatabaseInfo::class .' is immutable'); $this->expectExceptionMessage(DatabaseInfo::class . ' is immutable');
$info['empty'] = true; $info['empty'] = true;
} }
...@@ -61,7 +61,7 @@ class DatabaseInfoTest extends TestCase ...@@ -61,7 +61,7 @@ class DatabaseInfoTest extends TestCase
{ {
$info = new DatabaseInfo(['name' => 'foo', 'sizeOnDisk' => 1048576, 'empty' => false]); $info = new DatabaseInfo(['name' => 'foo', 'sizeOnDisk' => 1048576, 'empty' => false]);
$this->expectException(BadMethodCallException::class); $this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage(DatabaseInfo::class .' is immutable'); $this->expectExceptionMessage(DatabaseInfo::class . ' is immutable');
unset($info['empty']); unset($info['empty']);
} }
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment