Passed
Push — master ( dd3faf...038d50 )
by Zaahid
03:37
created

IdConsumer::getPartForToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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