DateTimeFormatter::getLong()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 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