Second::now()   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 0
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\Integer;
8
9
/**
10
 * Class Second
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 Second extends Integer implements DateTimeInterface
21
{
22
    use DateTimeTrait;
23
24
    /**
25
     * @param integer $value
26
     */
27 22
    public function __construct($value)
28
    {
29 22
        parent::__construct($value);
30 22
    }
31
32 10
    public static function now()
33
    {
34 10
        return new static(self::getNowDateTimeFormat('s'));
35
    }
36
37 12
    public function __toString()
38
    {
39 12
        return str_pad($this->getValue(), 2, '0', STR_PAD_LEFT);
40
    }
41
42
    /**
43
     * From String.
44
     *
45
     * @param  $string
46
     * @return static
47
     */
48 1
    public static function fromString($string)
49
    {
50 1
        return new static((int) $string);
51
    }
52
53
    /**
54
     * From Native
55
     *
56
     * @param \DateTime $native
57
     * @return DateTimeInterface
58
     */
59 1
    public static function fromNative(\DateTime $native)
60
    {
61 1
        return new static((int) $native->format('s'));
62
    }
63
64
    /**
65
     * @return int
66
     */
67 1
    public function getMaximum()
68
    {
69 1
        return 59;
70
    }
71
72
    /**
73
     * @return int
74
     */
75 1
    public function getMinimum()
76
    {
77 1
        return 0;
78
    }
79
80
}
81