Passed
Pull Request — master (#149)
by
unknown
02:58
created

DateHeader::getConsumer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of the ZBateson\MailMimeParser project.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
6
 */
7
namespace ZBateson\MailMimeParser\Header;
8
9
use ZBateson\MailMimeParser\Header\Consumer\ConsumerService;
10
use ZBateson\MailMimeParser\Header\Part\DatePart;
11
12
/**
13
 * Reads a DatePart value header in either RFC 2822 or RFC 822 format.
14
 * 
15
 * @author Zaahid Bateson
16
 */
17
class DateHeader extends AbstractHeader
18
{
19
    /**
20
     * Returns a DateConsumer.
21
     * 
22
     * @param ConsumerService $consumerService
23
     * @return \ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer
24
     */
25 4
    protected function getConsumer(ConsumerService $consumerService)
26
    {
27 4
        return $consumerService->getDateConsumer();
28
    }
29
    
30
    /**
31
     * Convenience method returning the part's DateTime object.
32
     * 
33
     * @return \DateTime
34
     */
35 3
    public function getDateTime()
36
    {
37 3
        if (!empty($this->parts) && $this->parts[0] instanceof DatePart) {
38 2
            return $this->parts[0]->getDateTime();
39
        }
40 1
        return null;
41
    }
42
    
43
    public function getDateTimeImmutable()
44
    {
45
        $dateTime = $this->getDateTime();
46
        if ($dateTime instanceof \DateTime) {
0 ignored issues
show
introduced by
$dateTime is always a sub-type of DateTime.
Loading history...
47
            return \DateTimeImmutable::createFromMutable($dateTime);
48
        }
49
        return null;
50
    }
51
}
52