traderinteractive /
mongo-queue-php
| 1 | <?php |
||||||
| 2 | /** |
||||||
| 3 | * Defines the TraderInteractive\Mongo\UnorderedQueue class. |
||||||
| 4 | */ |
||||||
| 5 | |||||||
| 6 | namespace TraderInteractive\Mongo; |
||||||
| 7 | |||||||
| 8 | use MongoDB\Client; |
||||||
| 9 | use MongoDB\Operation\FindOneAndUpdate; |
||||||
| 10 | |||||||
| 11 | /** |
||||||
| 12 | * Abstraction of mongo db collection as unordered queue. |
||||||
| 13 | */ |
||||||
| 14 | final class UnorderedQueue extends AbstractQueue implements QueueInterface |
||||||
| 15 | { |
||||||
| 16 | /** |
||||||
| 17 | * Override from AbstractQueue class to remove sort options. |
||||||
| 18 | * |
||||||
| 19 | * @var array |
||||||
| 20 | */ |
||||||
| 21 | const FIND_ONE_AND_UPDATE_OPTIONS = [ |
||||||
| 22 | 'typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array'], |
||||||
| 23 | 'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER, |
||||||
| 24 | ]; |
||||||
| 25 | |||||||
| 26 | /** |
||||||
| 27 | * Construct queue. |
||||||
| 28 | * |
||||||
| 29 | * @param \MongoDB\Collection|string $collectionOrUrl A MongoCollection instance or the mongo connection url. |
||||||
| 30 | * @param string $db the mongo db name |
||||||
| 31 | * @param string $collection the collection name to use for the queue |
||||||
| 32 | * |
||||||
| 33 | * @throws \InvalidArgumentException $collectionOrUrl, $db or $collection was not a string |
||||||
| 34 | */ |
||||||
| 35 | public function __construct($collectionOrUrl, string $db = null, string $collection = null) |
||||||
| 36 | { |
||||||
| 37 | if ($collectionOrUrl instanceof \MongoDB\Collection) { |
||||||
| 38 | $this->collection = $collectionOrUrl; |
||||||
| 39 | return; |
||||||
| 40 | } |
||||||
| 41 | |||||||
| 42 | if (!is_string($collectionOrUrl)) { |
||||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||||
| 43 | throw new \InvalidArgumentException('$collectionOrUrl was not a string'); |
||||||
| 44 | } |
||||||
| 45 | |||||||
| 46 | $this->collection = (new Client($collectionOrUrl))->selectDatabase($db)->selectCollection($collection); |
||||||
|
0 ignored issues
–
show
It seems like
$db can also be of type null; however, parameter $databaseName of MongoDB\Client::selectDatabase() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
It seems like
$collection can also be of type null; however, parameter $collectionName of MongoDB\Database::selectCollection() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 47 | } |
||||||
| 48 | } |
||||||
| 49 |