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

AbstractDateParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
getDateTime() 0 1 ?
A getDateFormat() 0 4 1
A getText() 0 15 2
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