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

AddressBaseConsumer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 2
cbo 3
dl 0
loc 83
ccs 12
cts 12
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubConsumers() 0 6 1
A getTokenSeparators() 0 4 1
A isEndToken() 0 4 1
A advanceToNextToken() 0 7 2
A isStartToken() 0 4 1
A getPartForToken() 0 4 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
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