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

Minute::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
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 18
rs 9.2
cc 4
eloc 10
nc 3
nop 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A Minute::isValid() 0 4 1
1
<?php
2
3
namespace CalendR\Period;
4
5
/**
6
 * Represents a minute.
7
 *
8
 * @author Zander Baldwin <[email protected]>
9
 */
10
class Minute extends PeriodAbstract implements \Iterator
11
{
12
    /**
13
     * @var PeriodInterface
14
     */
15
    private $current;
16
17
    /**
18
     * Returns the period as a DatePeriod.
19
     *
20
     * @return \DatePeriod
21
     */
22
    public function getDatePeriod()
23
    {
24
        return new \DatePeriod($this->begin, new \DateInterval('PT1S'), $this->end);
25
    }
26
27
    /**
28
     * @param \DateTime $start
29
     *
30
     * @return bool
31
     */
32
    public static function isValid(\DateTime $start)
33
    {
34
        return $start->format('s') == '00';
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function current()
41
    {
42
        return $this->current;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function next()
49
    {
50
        if (null === $this->current) {
51
            $this->current = $this->getFactory()->createSecond($this->begin);
52
        } else {
53
            $this->current = $this->current->getNext();
54
            if (!$this->contains($this->current->getBegin())) {
55
                $this->current = null;
56
            }
57
        }
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function key()
64
    {
65
        return (int) $this->current->getBegin()->format('i');
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function valid()
72
    {
73
        return null !== $this->current;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function rewind()
80
    {
81
        $this->current = null;
82
        $this->next();
83
    }
84
85
    /**
86
     * Returns the minute.
87
     *
88
     * @return string
89
     */
90
    public function __toString()
91
    {
92
        return $this->format('i');
93
    }
94
95
    /**
96
     * Returns a \DateInterval equivalent to the period.
97
     *
98
     * @return \DateInterval
99
     */
100
    public static function getDateInterval()
101
    {
102
        return new \DateInterval('PT1M');
103
    }
104
}
105