Passed
Push — 2.0 ( df1b1e...20b3e4 )
by Zaahid
08:44 queued 05:27
created

IdConsumer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 7
c 1
b 0
f 0
dl 0
loc 44
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPartForToken() 0 6 2
A isStartToken() 0 3 1
A isEndToken() 0 3 1
A getTokenSeparators() 0 3 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\Consumer;
9
10
/**
11
 * Parses a single ID from an ID header.  Begins consuming on a '<' char, and
12
 * ends on a '>' char.
13
 *
14
 * @author Zaahid Bateson
15
 */
16
class IdConsumer extends GenericConsumer
17
{
18
    /**
19
     * Overridden to return patterns matching the beginning part of an ID ('<'
20
     * and '>' chars).
21
     *
22
     * @return string[] the patterns
23
     */
24 30
    public function getTokenSeparators() : array
25
    {
26 30
        return ['\s+', '<', '>'];
27
    }
28
29
    /**
30
     * Returns true for '>'.
31
     */
32 29
    protected function isEndToken(string $token) : bool
33
    {
34 29
        return ($token === '>');
35
    }
36
37
    /**
38
     * Returns true for '<'.
39
     */
40 27
    protected function isStartToken(string $token) : bool
41
    {
42 27
        return ($token === '<');
43
    }
44
45
    /**
46
     * Returns null for whitespace, and LiteralPart for anything else.
47
     *
48
     * @param string $token the token
49
     * @param bool $isLiteral set to true if the token represents a literal -
50
     *        e.g. an escaped token
51
     * @return \ZBateson\MailMimeParser\Header\IHeaderPart|null the constructed
52
     *         header part or null if the token should be ignored
53
     */
54 29
    protected function getPartForToken(string $token, bool $isLiteral)
55
    {
56 29
        if (\preg_match('/^\s+$/', $token)) {
57 2
            return null;
58
        }
59 29
        return $this->partFactory->newLiteralPart($token);
60
    }
61
}
62