DateTimeFormatter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
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 4 1
A getLong() 0 9 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Arbor\Moment\Formatter;
6
7
use Arbor\Moment\DateTime;
8
9
/**
10
 * Class DateTimeFormatter
11
 *
12
 * @package Arbor\Moment\Formatter
13
 * @author Igor Vuckovic <[email protected]>
14
 */
15
class DateTimeFormatter implements FormatterInterface
16
{
17
    /** @var DateTime */
18
    private $dateTime;
19
20
    /**
21
     * @param DateTime $dateTime
22
     */
23 45
    public function __construct(DateTime $dateTime)
24
    {
25 45
        $this->dateTime = $dateTime;
26 45
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 24
    public function getShort() : string
32
    {
33 24
        return $this->dateTime->format(DateTime::FORMAT_SHORT);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 35
    public function getLong() : string
40
    {
41 35
        $format = DateTime::FORMAT_SHORT;
42 35
        if ($this->dateTime->getDateType() === DateTime::TYPE_DATETIME) {
43 26
            $format .= ', ' . DateTime::FORMAT_TIME;
44
        }
45
46 35
        return $this->dateTime->format($format);
47
    }
48
}
49