Query   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 86
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createDate() 0 20 4
1
<?php
2
3
namespace Pouzor\MongoDBBundle\Constants;
4
5
/**
6
 * Query options for mongo cursors
7
 *
8
 * Class Query
9
 * @package Pouzor\MongoDBBundle\Constants
10
 */
11
final class Query
12
{
13
    /**
14
     * The number of documents to skip before returning
15
     */
16
    const OFFSET = 'skip';
17
18
    /**
19
     * The number of documents to be returned
20
     */
21
    const LIMIT = 'limit';
22
23
    /**
24
     * The order in which to return matching documents
25
     */
26
    const SORT = 'sort';
27
28
    /**
29
     * The number of documents to return per batch
30
     */
31
    const BATCH_SIZE = 'batchSize';
32
33
    /**
34
     * Stream the data down full blast in multiple "reply" packets.
35
     * Faster when you are pulling down a lot of data and you know
36
     * you want to retrieve it all
37
     */
38
    const EXHAUST = 'exhaust';
39
40
    /**
41
     * Block rather than returning no data. After a period, time out.
42
     * Useful for tailable cursor
43
     */
44
    const AWAIT_DATA = 'awaitData';
45
46
    /**
47
     * Do not timeout a cursor that has been idle for more then 10 minutes
48
     */
49
    const NO_CURSOR_TIMEOUT = 'noCursorTimeout';
50
51
    /**
52
     * Specifies the fields to return using booleans or projection operators
53
     */
54
    const PROJECTION = 'projection';
55
56
    /**
57
     * Cursor will not be closed when the last data is retrieved.
58
     * You can resume this cursor later
59
     */
60
    const TAILABLE = 'tailable';
61
62
    /**
63
     * maxTimeMS (integer): The maximum amount of time to allow the query to
64
     * run. If "$maxTimeMS" also exists in the modifiers document, this
65
     * option will take precedence.
66
     */
67
    const MAX_TIME_MS = 'maxTimeMS';
68
69
70
    /**
71
     * @param string | int $time
72
     * @return MongoDB\BSON\UTCDateTime
73
     * @throws \Exception
74
     */
75 2
    public static function createDate($time = null)
76
    {
77 2
        $dateClass = DriverClasses::DATE_CLASS;
78
79 2
        if (!$time) {
80 1
            return new $dateClass(time() * 1000);
81
        }
82
83 2
        if (is_int($time)) {
84 1
            return new $dateClass($time * 1000);
85
        }
86
87 2
        if (strtotime($time) === false) {
88 1
            throw new \Exception('Invalid time');
89
        }
90
91 1
        $utime = (new \DateTime($time));
92
93 1
        return new $dateClass($utime);
94
    }
95
96
}
97