Passed
Push — master ( 1f2094...564202 )
by Zaahid
03:47
created

AddressEmailConsumer::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 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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
/**
10
 * Parses the Address portion of an email address header, for an address part
11
 * that contains both a name and an email address, e.g. "name" <[email protected]>.
12
 * 
13
 * The address portion found within the '<' and '>' chars may contain comments
14
 * and quoted portions.
15
 * 
16
 * @author Zaahid Bateson
17
 */
18
class AddressEmailConsumer extends AbstractConsumer
19
{
20
    /**
21
     * Returns the following as sub-consumers:
22
     *  - {@see AddressGroupConsumer}
23
     *  - {@see CommentConsumer}
24
     *  - {@see QuotedStringConsumer}
25
     * 
26
     * @return AbstractConsumer[] the sub-consumers
27
     */
28 98
    protected function getSubConsumers()
29
    {
30
        return [
31 98
            $this->consumerService->getCommentConsumer(),
32 98
            $this->consumerService->getQuotedStringConsumer(),
33
        ];
34
    }
35
    
36
    /**
37
     * Overridden to return patterns matching the beginning/end part of an
38
     * address in a name/address part ("<" and ">" chars).
39
     * 
40
     * @return string[] the patterns
41
     */
42 98
    public function getTokenSeparators()
43
    {
44 98
        return [ '<', '>' ];
45
    }
46
    
47
    /**
48
     * Returns true for the '>' char.
49
     * 
50
     * @param string $token
51
     * @return boolean false
52
     */
53 97
    protected function isEndToken($token)
54
    {
55 97
        return ($token === '>');
56
    }
57
    
58
    /**
59
     * Returns true for the '<' char.
60
     * 
61
     * @param string $token
62
     * @return boolean false
63
     */
64 94
    protected function isStartToken($token)
65
    {
66 94
        return ($token === '<');
67
    }
68
69
    /**
70
     * Returns a single AddressPart with its 'email' portion set, so an
71
     * AddressConsumer can identify it and create an AddressPart with both a
72
     * name and email set.
73
     * 
74
     * @param \ZBateson\MailMimeParser\Header\IHeaderPart[] $parts
75
     * @return \ZBateson\MailMimeParser\Header\IHeaderPart[]|array
76
     */
77 97
    protected function processParts(array $parts)
78
    {
79 97
        $strEmail = '';
80 97
        foreach ($parts as $p) {
81 97
            $strEmail .= $p->getValue();
82
        }
83 97
        return [ $this->partFactory->newAddressPart('', $strEmail) ];
84
    }
85
}
86