TimeFormatter::getShort()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Arbor\Moment\Formatter;
6
7
use Arbor\Moment\Time;
8
9
/**
10
 * Class TimeFormatter
11
 *
12
 * @package Arbor\Moment\Formatter
13
 * @author Igor Vuckovic <[email protected]>
14
 */
15
class TimeFormatter implements FormatterInterface
16
{
17
    /** @var Time */
18
    private $time;
19
20
    /**
21
     * @param Time $time
22
     */
23 42
    public function __construct(Time $time)
24
    {
25 42
        $this->time = $time;
26 42
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 16
    public function getShort() : string
32
    {
33 16
        $hours = (string)$this->time->getHours();
34 16
        $minutes = (string)$this->time->getMinutes();
35
36 16
        return str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($minutes, 2, '0', STR_PAD_LEFT);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 6
    public function getLong() : string
43
    {
44 6
        $seconds = (string)$this->time->getSeconds();
45
46 6
        return $this->getShort() . ':' . str_pad($seconds, 2, '0', STR_PAD_LEFT);
47
    }
48
}
49