Completed
Push — master ( 363bb4...91ed68 )
by Yohan
02:04
created

Second::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 19
rs 9.2
cc 4
eloc 10
nc 3
nop 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A Second::isValid() 0 4 1
1
<?php
2
3
namespace CalendR\Period;
4
5
/**
6
 * Represents a second.
7
 *
8
 * @author Zander Baldwin <[email protected]>
9
 */
10
class Second extends PeriodAbstract
11
{
12
    /**
13
     * Returns the period as a DatePeriod.
14
     *
15
     * @return \DatePeriod
16
     */
17
    public function getDatePeriod()
18
    {
19
        return new \DatePeriod($this->begin, new \DateInterval('PT1S'), $this->end);
20
    }
21
22
    /**
23
     * @param \DateTime $start
24
     *
25
     * @return bool
26
     */
27
    public static function isValid(\DateTime $start)
28
    {
29
        return $start->format('u') === '000000';
30
    }
31
32
    /**
33
     * Returns the second.
34
     *
35
     * @return string
36
     */
37
    public function __toString()
38
    {
39
        return $this->format('s');
40
    }
41
42
    /**
43
     * Returns a \DateInterval equivalent to the period.
44
     *
45
     * @return \DateInterval
46
     */
47
    public static function getDateInterval()
48
    {
49
        return new \DateInterval('PT1S');
50
    }
51
}
52