Completed
Push — master ( 4984e7...9ad690 )
by John
03:58
created

AbstractDateParser::getDateFormat()   A

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
namespace Graze\CiffRenderer\Field\Parser\DateParser;
4
5
use Graze\CiffRenderer\Field\Parser\FixedTextParser;
6
use Graze\CiffRenderer\Field\Parser\DateParser\DateFormatter\DateFormatterFactory;
7
use Graze\CiffRenderer\Exception\UnsupportedDateFormatException;
8
9
abstract class AbstractDateParser extends FixedTextParser
10
{
11
    /**
12
     * @return string
13
     *
14
     * @throws UnsupportedDateFormatException
15
     */
16 2
    public function getText()
17
    {
18
        try {
19 2
            $dateFormat = $this->getDateFormat();
20
21 2
            $dateFormatter = DateFormatterFactory::getFormatter($dateFormat);
22
23 2
            return $dateFormatter->format(
24 2
                $this->getDateTime(),
25
                $dateFormat
26
            );
27
        } catch (\Exception $e) {
28
            throw new UnsupportedDateFormatException($this->getDateFormat());
29
        }
30
    }
31
32
    /**
33
     * Fetch a DateTime object set to the correct date/time.
34
     *
35
     * @return DateTimeInterface
36
     */
37
    abstract protected function getDateTime();
38
39
    /**
40
     * @return string
41
     */
42 4
    public function getDateFormat()
43
    {
44 4
        return (string) $this->xmlField->Data->Object->Default;
45
    }
46
}
47