Timestamp   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fromDateTime() 0 3 1
A __construct() 0 4 1
A getNanoseconds() 0 3 1
A getSeconds() 0 3 1
A now() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of the rybakit/msgpack.php package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace MessagePack\Type;
13
14
final class Timestamp
15
{
16
    private $seconds;
17
    private $nanoseconds;
18
19 13
    public function __construct(int $seconds, int $nanoseconds = 0)
20
    {
21 13
        $this->seconds = $seconds;
22 13
        $this->nanoseconds = $nanoseconds;
23
    }
24
25 1
    public static function now() : self
26
    {
27 1
        $date = new \DateTime();
28
29 1
        return new self($date->getTimestamp(), (int) $date->format('u') * 1000);
30
    }
31
32 1
    public static function fromDateTime(\DateTimeInterface $date) : self
33
    {
34 1
        return new self($date->getTimestamp(), (int) $date->format('u') * 1000);
35
    }
36
37 12
    public function getSeconds() : int
38
    {
39 12
        return $this->seconds;
40
    }
41
42 12
    public function getNanoseconds() : int
43
    {
44 12
        return $this->nanoseconds;
45
    }
46
}
47