Passed
Push — master ( 46ed75...ca2387 )
by Zaahid
03:33
created

AddressBaseConsumerService::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 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
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
8
namespace ZBateson\MailMimeParser\Header\Consumer;
9
10
use ZBateson\MailMimeParser\Header\Part\HeaderPartFactory;
11
use ZBateson\MailMimeParser\Header\IHeaderPart;
12
use Iterator;
13
14
/**
15
 * Serves as a base-consumer for recipient/sender email address headers (like
16
 * From and To).
17
 *
18
 * AddressBaseConsumerService passes on token processing to its sub-consumer, an
19
 * AddressConsumerService, and collects Part\AddressPart objects processed and
20
 * returned by AddressConsumerService.
21
 *
22
 * @author Zaahid Bateson
23
 */
24
class AddressBaseConsumerService extends AbstractConsumerService
25
{
26 4
    public function __construct(
27
        HeaderPartFactory $partFactory,
28
        AddressConsumerService $addressConsumerService
29
    ) {
30 4
        parent::__construct($partFactory, [ $addressConsumerService ]);
31
    }
32
33
    /**
34
     * Returns an empty array.
35
     *
36
     * @return string[] an array of regex pattern matchers
37
     */
38 5
    protected function getTokenSeparators() : array
39
    {
40 5
        return [];
41
    }
42
43
    /**
44
     * Disables advancing for start tokens.
45
     *
46
     * The start token for AddressBaseConsumerService is part of an
47
     * {@see AddressPart} (or a sub-consumer) and so must be passed on.
48
     *
49
     * @return static
50
     */
51 99
    protected function advanceToNextToken(Iterator $tokens, bool $isStartToken) : AbstractConsumerService
52
    {
53 99
        if ($isStartToken) {
54 99
            return $this;
55
        }
56 99
        parent::advanceToNextToken($tokens, $isStartToken);
57 99
        return $this;
58
    }
59
60
    /**
61
     * AddressBaseConsumerService doesn't have start/end tokens, and so always
62
     * returns false.
63
     *
64
     * @return false
65
     */
66 99
    protected function isEndToken(string $token) : bool
67
    {
68 99
        return false;
69
    }
70
71
    /**
72
     * AddressBaseConsumerService doesn't have start/end tokens, and so always
73
     * returns false.
74
     *
75
     * @codeCoverageIgnore
76
     * @return false
77
     */
78
    protected function isStartToken(string $token) : bool
79
    {
80
        return false;
81
    }
82
83
    /**
84
     * Overridden so tokens aren't handled at this level, and instead are passed
85
     * on to AddressConsumerService.
86
     *
87
     * @return \ZBateson\MailMimeParser\Header\IHeaderPart[]|array
88
     */
89 99
    protected function getTokenParts(Iterator $tokens) : array
90
    {
91 99
        return $this->getConsumerTokenParts($tokens);
92
    }
93
94
    /**
95
     * Never reached by AddressBaseConsumerService. Overridden to satisfy
96
     * AbstractConsumerService.
97
     *
98
     * @codeCoverageIgnore
99
     */
100
    protected function getPartForToken(string $token, bool $isLiteral) : ?IHeaderPart
101
    {
102
        return null;
103
    }
104
}
105