TimeFormatter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 34
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getShort() 0 7 1
A getLong() 0 6 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