Completed
Pull Request — master (#60)
by Chad
01:24
created

Queue   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
1
<?php
2
/**
3
 * Defines the TraderInteractive\Mongo\Queue class.
4
 */
5
6
namespace TraderInteractive\Mongo;
7
8
use MongoDB\BSON\UTCDateTime;
9
use MongoDB\Client;
10
11
/**
12
 * Abstraction of mongo db collection as priority queue.
13
 *
14
 * Tied priorities are ordered by time. So you may use a single priority for normal queuing (default args exist for
15
 * this purpose).  Using a random priority achieves random get()
16
 */
17
final class Queue extends AbstractQueue implements QueueInterface
18
{
19
    /**
20
     * Construct queue.
21
     *
22
     * @param \MongoDB\Collection|string $collectionOrUrl A MongoCollection instance or the mongo connection url.
23
     * @param string $db the mongo db name
24
     * @param string $collection the collection name to use for the queue
25
     *
26
     * @throws \InvalidArgumentException $collectionOrUrl, $db or $collection was not a string
27
     */
28
    public function __construct($collectionOrUrl, string $db = null, string $collection = null)
29
    {
30
        if ($collectionOrUrl instanceof \MongoDB\Collection) {
31
            $this->collection = $collectionOrUrl;
32
            return;
33
        }
34
35
        if (!is_string($collectionOrUrl)) {
36
            throw new \InvalidArgumentException('$collectionOrUrl was not a string');
37
        }
38
39
        $this->collection = (new Client($collectionOrUrl))->selectDatabase($db)->selectCollection($collection);
40
    }
41
}
42