Completed
Push — master ( ab502e...07a33d )
by Zaahid
06:14
created

AddressBaseConsumer::advanceToNextToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
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
use Iterator;
10
11
/**
12
 * Serves as a base-consumer for recipient/sender email address headers (like
13
 * From and To).
14
 * 
15
 * AddressBaseConsumer passes on token processing to its sub-consumer, an
16
 * AddressConsumer, and collects Part\AddressPart objects processed and returned
17
 * by AddressConsumer.
18
 *
19
 * @author Zaahid Bateson
20
 */
21
class AddressBaseConsumer extends AbstractConsumer
22
{
23
    /**
24
     * Returns \ZBateson\MailMimeParser\Header\Consumer\AddressConsumer as a
25
     * sub-consumer.
26
     * 
27
     * @return AbstractConsumer[] the sub-consumers
28
     */
29 3
    protected function getSubConsumers()
30
    {
31
        return [
32 3
            $this->consumerService->getAddressConsumer()
33 3
        ];
34
    }
35
    
36
    /**
37
     * Returns an empty array.
38
     * 
39
     * @return string[] an array of regex pattern matchers
40
     */
41 3
    protected function getTokenSeparators()
42
    {
43 3
        return [];
44
    }
45
    
46
    /**
47
     * Disables advancing for start tokens.
48
     * 
49
     * The start token for AddressBaseConsumer is part of an AddressPart (or a
50
     * sub-consumer) and so must be passed on.
51
     * 
52
     * @param Iterator $tokens
53
     * @param bool $isStartToken
54
     */
55 3
    protected function advanceToNextToken(Iterator $tokens, $isStartToken)
56
    {
57 3
        if ($isStartToken) {
58 3
            return;
59
        }
60 3
        parent::advanceToNextToken($tokens, $isStartToken);
61 3
    }
62
    
63
    /**
64
     * AddressBaseConsumer doesn't have start/end tokens, and so always returns
65
     * false.
66
     * 
67
     * @param string $token
68
     * @return boolean false
69
     */
70 3
    protected function isEndToken($token)
71
    {
72 3
        return false;
73
    }
74
    
75
    /**
76
     * AddressBaseConsumer doesn't have start/end tokens, and so always returns
77
     * false.
78
     * 
79
     * @codeCoverageIgnore
80
     * @param string $token
81
     * @return boolean false
82
     */
83
    protected function isStartToken($token)
84
    {
85
        return false;
86
    }
87
    
88
    /**
89
     * Never reached by AddressBaseConsumer. Overridden to satisfy
90
     * AbstractConsumer.
91
     * 
92
     * @codeCoverageIgnore
93
     * @param string $token the token
94
     * @param bool $isLiteral set to true if the token represents a literal -
95
     *        e.g. an escaped token
96
     * @return \ZBateson\MailMimeParser\Header\Part\HeaderPart the constructed header
97
     *         part or null if the token should be ignored
98
     */
99
    protected function getPartForToken($token, $isLiteral)
100
    {
101
        return $this->partFactory->newToken($token);
102
    }
103
}
104