IdConsumerService   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 7
c 0
b 0
f 0
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isEndToken() 0 3 1
A isStartToken() 0 3 1
A getPartForToken() 0 6 2
A getTokenSeparators() 0 3 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
8
namespace ZBateson\MailMimeParser\Header\Consumer;
9
10
use ZBateson\MailMimeParser\Header\IHeaderPart;
11
12
/**
13
 * Parses a single ID from an ID header.  Begins consuming on a '<' char, and
14
 * ends on a '>' char.
15
 *
16
 * @author Zaahid Bateson
17
 */
18
class IdConsumerService extends GenericConsumerService
19
{
20
    /**
21
     * Overridden to return patterns matching the beginning part of an ID ('<'
22
     * and '>' chars).
23
     *
24
     * @return string[] the patterns
25
     */
26 4
    public function getTokenSeparators() : array
27
    {
28 4
        return \array_merge(parent::getTokenSeparators(), ['<', '>']);
29
    }
30
31
    /**
32
     * Returns true for '>'.
33
     */
34 85
    protected function isEndToken(string $token) : bool
35
    {
36 85
        return ($token === '>');
37
    }
38
39
    /**
40
     * Returns true for '<'.
41
     */
42 83
    protected function isStartToken(string $token) : bool
43
    {
44 83
        return ($token === '<');
45
    }
46
47
    /**
48
     * Returns null for whitespace, and Token for anything else.
49
     */
50 85
    protected function getPartForToken(string $token, bool $isLiteral) : ?IHeaderPart
51
    {
52 85
        if (\preg_match('/^\s+$/', $token)) {
53 2
            return null;
54
        }
55 85
        return $this->partFactory->newToken($token, true);
56
    }
57
}
58