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

MongoAdapter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 24
ccs 0
cts 13
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromMongoDate() 0 6 1
A asMongoDate() 0 7 1
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