Passed
Push — master ( 1e9eda...d3d3f6 )
by Eugene
08:23
created

Timestamp::getSeconds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 13
    }
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