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

IdBaseConsumer::getSubConsumers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
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\Consumer;
8
9
use Iterator;
10
11
/**
12
 * Serves as a base-consumer for ID headers (like Message-ID and Content-ID).
13
 * 
14
 * IdBaseConsumer passes on token processing to its sub-consumer, an
15
 * IdConsumer, and collects Part\LiteralPart objects processed and returned
16
 * by IdConsumer.
17
 *
18
 * @author Zaahid Bateson
19
 */
20
class IdBaseConsumer extends AbstractConsumer
21
{
22
    /**
23
     * Returns \ZBateson\MailMimeParser\Header\Consumer\IdConsumer as a
24
     * sub-consumer.
25
     * 
26
     * @return AbstractConsumer[] the sub-consumers
27
     */
28 3
    protected function getSubConsumers()
29
    {
30
        return [
31 3
            $this->consumerService->getCommentConsumer(),
32 3
            $this->consumerService->getIdConsumer()
33
        ];
34
    }
35
    
36
    /**
37
     * Returns '\s+' as a whitespace separator.
38
     * 
39
     * @return string[] an array of regex pattern matchers
40
     */
41 3
    protected function getTokenSeparators()
42
    {
43 3
        return ['\s+'];
44
    }
45
46
    /**
47
     * Disables advancing for start tokens not matching '<'.
48
     *
49
     * @param Iterator $tokens
50
     * @param bool $isStartToken
51
     */
52 3
    protected function advanceToNextToken(Iterator $tokens, $isStartToken)
53
    {
54 3
        if ($isStartToken && $tokens->current() !== '<' && $tokens->current() !== '(') {
55
            return;
56
        }
57 3
        parent::advanceToNextToken($tokens, $isStartToken);
58 3
    }
59
60
    /**
61
     * IdBaseConsumer doesn't have start/end tokens, and so always returns
62
     * false.
63
     * 
64
     * @param string $token
65
     * @return boolean false
66
     */
67 3
    protected function isEndToken($token)
68
    {
69 3
        return false;
70
    }
71
    
72
    /**
73
     * IdBaseConsumer doesn't have start/end tokens, and so always returns
74
     * false.
75
     * 
76
     * @codeCoverageIgnore
77
     * @param string $token
78
     * @return boolean false
79
     */
80
    protected function isStartToken($token)
81
    {
82
        return false;
83
    }
84
    
85
    /**
86
     * Could be reached by whitespace characters.  Returns null to ignore the
87
     * passed token.
88
     * 
89
     * @param string $token the token
90
     * @param bool $isLiteral set to true if the token represents a literal -
91
     *        e.g. an escaped token
92
     * @return \ZBateson\MailMimeParser\Header\Part\HeaderPart|null the
93
     *         constructed header part or null if the token should be ignored
94
     */
95 2
    protected function getPartForToken($token, $isLiteral)
96
    {
97 2
        return null;
98
    }
99
}
100