DateTimeFormatter::getShort()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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\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