IdBaseConsumerService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 13
c 0
b 0
f 0
dl 0
loc 66
ccs 18
cts 18
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isStartToken() 0 3 1
A __construct() 0 14 1
A getPartForToken() 0 6 2
A getTokenSeparators() 0 3 1
A isEndToken() 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 Psr\Log\LoggerInterface;
11
use ZBateson\MailMimeParser\Header\IHeaderPart;
12
use ZBateson\MailMimeParser\Header\Part\HeaderPartFactory;
13
14
/**
15
 * Serves as a base-consumer for ID headers (like Message-ID and Content-ID).
16
 *
17
 * IdBaseConsumerService handles invalidly-formatted IDs not within '<' and '>'
18
 * characters.  Processing for validly-formatted IDs are passed on to its
19
 * sub-consumer, IdConsumer.
20
 *
21
 * @author Zaahid Bateson
22
 */
23
class IdBaseConsumerService extends AbstractConsumerService
24
{
25 4
    public function __construct(
26
        LoggerInterface $logger,
27
        HeaderPartFactory $partFactory,
28
        CommentConsumerService $commentConsumerService,
29
        QuotedStringConsumerService $quotedStringConsumerService,
30
        IdConsumerService $idConsumerService
31
    ) {
32 4
        parent::__construct(
33 4
            $logger,
34 4
            $partFactory,
35 4
            [
36 4
                $commentConsumerService,
37 4
                $quotedStringConsumerService,
38 4
                $idConsumerService
39 4
            ]
40 4
        );
41
    }
42
43
    /**
44
     * Returns '\s+' as a whitespace separator.
45
     *
46
     * @return string[] an array of regex pattern matchers.
47
     */
48 4
    protected function getTokenSeparators() : array
49
    {
50 4
        return ['\s+'];
51
    }
52
53
    /**
54
     * IdBaseConsumerService doesn't have start/end tokens, and so always
55
     * returns false.
56
     */
57 86
    protected function isEndToken(string $token) : bool
58
    {
59 86
        return false;
60
    }
61
62
    /**
63
     * IdBaseConsumerService doesn't have start/end tokens, and so always
64
     * returns false.
65
     *
66
     * @codeCoverageIgnore
67
     */
68
    protected function isStartToken(string $token) : bool
69
    {
70
        return false;
71
    }
72
73
    /**
74
     * Returns null for whitespace, and
75
     * {@see ZBateson\MailMimeParser\Header\Part\Token} for anything else.
76
     *
77
     * @param string $token the token
78
     * @param bool $isLiteral set to true if the token represents a literal -
79
     *        e.g. an escaped token
80
     * @return ?IHeaderPart The constructed header part or null if the token
81
     *         should be ignored
82
     */
83 3
    protected function getPartForToken(string $token, bool $isLiteral) : ?IHeaderPart
84
    {
85 3
        if (\preg_match('/^\s+$/', $token)) {
86 2
            return null;
87
        }
88 1
        return $this->partFactory->newToken($token, true);
89
    }
90
}
91