MicroSecond::getMicroTimeAsInteger()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace BestServedCold\PhalueObjects\DateTime\Unit;
4
5
use BestServedCold\PhalueObjects\Contract\DateTime as DateTimeInterface;
6
use BestServedCold\PhalueObjects\DateTime\DateTimeTrait;
7
use BestServedCold\PhalueObjects\Mathematical\FloatVO;
8
9
/**
10
 * Class MicroSecond
11
 *
12
 * @package   BestServedCold\PhalueObjects\DateTime\Unit
13
 * @author    Adam Lewis <[email protected]>
14
 * @copyright Copyright (c) 2015 Best Served Cold Media Limited
15
 * @license   http://http://opensource.org/licenses/GPL-3.0 GPL License
16
 * @link      http://bestservedcold.com
17
 * @since     0.0.1-alpha
18
 * @version   0.0.2-alpha
19
 */
20
final class MicroSecond extends FloatVO implements DateTimeInterface
21
{
22
    use DateTimeTrait;
23
24
    /**
25
     * Now.
26
     *
27
     * @return static
28
     */
29 1
    public static function now()
30
    {
31 1
        return self::getMicroTimeAsInteger(microtime());
32
    }
33
34
    /**
35
     * From String.
36
     *
37
     * @param  $string
38
     * @return static
39
     */
40 1
    public static function fromString($string)
41
    {
42 1
        return new static((float) $string);
43
    }
44
45
    /**
46
     * From Native
47
     *
48
     * @param \DateTime $native
49
     * @return DateTimeInterface
50
     */
51 1
    public static function fromNative(\DateTime $native)
52
    {
53 1
        return new static(floatval('0.'.$native->format('u')));
54
    }
55
56
    /**
57
     * @param string $microTime
58
     * @return static
59
     */
60 2
    public static function getMicroTimeAsInteger($microTime)
61
    {
62 2
        return new static(round((float) explode(' ', $microTime)[ 0 ], 6));
63
    }
64
}
65