Passed
Push — master ( 62ba25...3d6b5c )
by Christian
02:01
created

BatchTime::toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[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 Core23\Form\Model;
13
14
class BatchTime
15
{
16
    /**
17
     * @var int
18
     */
19
    private $day = 0;
20
21
    /**
22
     * @var \DateTime|null
23
     * */
24
    private $time;
25
26
    public function __toString()
27
    {
28
        return $this->toString();
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function toString(): string
35
    {
36
        return 'Day: '.$this->day.', Time: '.($this->time ? $this->time->format('H:i:s') : '');
37
    }
38
39
    /**
40
     * @return int
41
     */
42
    public function getDay(): int
43
    {
44
        return $this->day ?: 0;
45
    }
46
47
    /**
48
     * @param int $day
49
     */
50
    public function setDay(int $day): void
51
    {
52
        $this->day = $day;
53
    }
54
55
    /**
56
     * @return \DateTime|null
57
     */
58
    public function getTime(): ?\DateTime
59
    {
60
        return $this->time;
61
    }
62
63
    /**
64
     * @param \DateTime $time
65
     */
66
    public function setTime(\DateTime $time): void
67
    {
68
        $this->time = $time;
69
    }
70
71
    /**
72
     * @return int
73
     */
74
    public function getSeconds(): int
75
    {
76
        return $this->getDay() * 86400 + (null !== $this->getTime() ? (int) $this->getTime()->format('U') : 0);
77
    }
78
}
79