Passed
Push — master ( 158433...e258e4 )
by Zaahid
03:43
created

IdHeader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 7
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 4
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
8
namespace ZBateson\MailMimeParser\Header;
9
10
use ZBateson\MailMimeParser\Header\Consumer\IdBaseConsumerService;
11
use ZBateson\MailMimeParser\Header\Part\CommentPart;
12
use ZBateson\MailMimeParser\Header\Part\MimeLiteralPartFactory;
13
14
/**
15
 * Represents a Content-ID, Message-ID, In-Reply-To or References header.
16
 *
17
 * For a multi-id header like In-Reply-To or References, all IDs can be
18
 * retrieved by calling {@see IdHeader::getIds()}.  Otherwise, to retrieve the
19
 * first (or only) ID call {@see IdHeader::getValue()}.
20
 *
21
 * @author Zaahid Bateson
22
 */
23
class IdHeader extends MimeEncodedHeader
24
{
25 90
    public function __construct(
26
        MimeLiteralPartFactory $mimeLiteralPartFactory,
27
        IdBaseConsumerService $consumerService,
28
        string $name,
29
        string $value
30
    ) {
31 90
        parent::__construct($mimeLiteralPartFactory, $consumerService, $name, $value);
32
    }
33
34
    /**
35
     * Returns the ID. Synonymous to calling getValue().
36
     *
37
     * @return string|null The ID
38
     */
39
    public function getId() : ?string
40
    {
41
        return $this->getValue();
42
    }
43
44
    /**
45
     * Returns all IDs parsed for a multi-id header like References or
46
     * In-Reply-To.
47
     *
48
     * @return string[] An array of IDs
49
     */
50 6
    public function getIds() : array
51
    {
52 6
        return \array_values(\array_map(
53 6
            function($p) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
54 5
                return $p->getValue();
55 6
            },
56 6
            \array_filter($this->parts, function($p) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
57 5
                return !($p instanceof CommentPart);
58 6
            })
59 6
        ));
60
    }
61
}
62