Passed
Push — master ( 7ee1dd...fe1f98 )
by Zaahid
03:17
created

IdHeader::getIds()   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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Consumer\AbstractConsumer;
11
use ZBateson\MailMimeParser\Header\Part\CommentPart;
12
13
/**
14
 * Represents a Content-ID, Message-ID, In-Reply-To or Reference header.
15
 *
16
 * For a multi-id header like In-Reply-To or Reference, all IDs can be retrieved
17
 * by calling 'getIds()'.  Otherwise, to retrieve the first (or only) ID call
18
 * 'getValue()'.
19
 * 
20
 * @author Zaahid Bateson
21
 */
22
class IdHeader extends GenericHeader
23
{
24
    /**
25
     * @var string[] an array of ids found. 
26
     */
27
    protected $ids = [];
28
29
    /**
30
     * Returns an IdBaseConsumer.
31
     *
32
     * @param ConsumerService $consumerService
33
     * @return \ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer
34
     */
35 6
    protected function getConsumer(ConsumerService $consumerService)
36
    {
37 6
        return $consumerService->getIdBaseConsumer();
38
    }
39
40
    /**
41
     * Overridden to extract all IDs into ids array.
42
     *
43
     * @param AbstractConsumer $consumer
44
     */
45 6
    protected function setParseHeaderValue(AbstractConsumer $consumer)
46
    {
47 6
        parent::setParseHeaderValue($consumer);
48 6
        foreach ($this->parts as $part) {
49 5
            if (!($part instanceof CommentPart)) {
50 5
                $this->ids[] = $part->getValue();
51
            }
52
        }
53 6
    }
54
55
    /**
56
     * Returns the first parsed ID or null if none exist.
57
     *
58
     * @return string|null
59
     */
60 6
    public function getValue()
61
    {
62 6
        if (!empty($this->ids)) {
63 5
            return $this->ids[0];
64
        }
65 1
        return null;
66
    }
67
68
    /**
69
     * Returns all IDs parsed for a multi-id header like Reference or
70
     * In-Reply-To.
71
     * 
72
     * @return string[]
73
     */
74 4
    public function getIds()
75
    {
76 4
        return $this->ids;
77
    }
78
}
79