Completed
Push — master ( 94d22b...a304f8 )
by Andreu
02:15
created

MongoAdapter::fromMongoDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
4
namespace Litipk\Jiffy;
5
6
7
/**
8
 * Trait MongoAdapter: Only to be used inside UniversalTimestamp.
9
 * @package Litipk\Jiffy
10
 */
11
trait MongoAdapter
12
{
13
    /**
14
     * @param \MongoDate $mongoDate
15
     * @return UniversalTimestamp
16
     */
17
    public static function fromMongoDate(\MongoDate $mongoDate)
18
    {
19
        return UniversalTimestamp::fromMillisecondsTimestamp(
20
            $mongoDate->sec*1000 + (int)($mongoDate->usec/1000)
21
        );
22
    }
23
24
    /**
25
     * @return \MongoDate
26
     */
27
    public function asMongoDate()
28
    {
29
        return new \MongoDate(
30
            (int)floor($this->millis/1000),
0 ignored issues
show
Bug introduced by
The property millis does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
            1000*($this->millis%1000)
32
        );
33
    }
34
}
35