Test Failed
Push — master ( e258e4...a626ba )
by Zaahid
15:25
created

ParameterNameValueConsumerService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 15
c 1
b 0
f 0
dl 0
loc 59
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isStartToken() 0 3 1
A processParts() 0 10 2
A isEndToken() 0 3 1
A __construct() 0 11 1
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 Psr\Log\LoggerInterface;
11
use ZBateson\MailMimeParser\Header\IHeaderPart;
12
use ZBateson\MailMimeParser\Header\Part\MimeTokenPartFactory;
13
use ZBateson\MailMimeParser\Header\Part\ContainerPart;
14
15
/**
16
 * @author Zaahid Bateson
17
 */
18
class ParameterNameValueConsumerService extends AbstractGenericConsumerService
19
{
20
    public function __construct(
21
        LoggerInterface $logger,
22
        MimeTokenPartFactory $partFactory,
23
        ParameterValueConsumerService $parameterValueConsumerService,
24
        CommentConsumerService $commentConsumerService,
25
        QuotedStringConsumerService $quotedStringConsumerService
26
    ) {
27
        parent::__construct(
28
            $logger,
29
            $partFactory,
30
            [$parameterValueConsumerService, $commentConsumerService, $quotedStringConsumerService]
31
        );
32
    }
33
34
    /**
35
     * Returns semi-colon and equals char as token separators.
36
     *
37
     * @return string[]
38
     */
39
    protected function getTokenSeparators() : array
40
    {
41
        return \array_merge(parent::getTokenSeparators(), [';']);
42
    }
43
    
44
    /**
45
     * Returns true if the token is an
46
     */
47
    protected function isStartToken(string $token) : bool
48
    {
49
        return true;
50
    }
51
52
    /**
53
     * Returns true if the token is a
54
     */
55
    protected function isEndToken(string $token) : bool
56
    {
57
        return ($token === ';');
58
    }
59
60
    /**
61
     * Post processing involves creating Part\LiteralPart or Part\ParameterPart
62
     * objects out of created Token and LiteralParts.
63
     *
64
     * @param IHeaderPart[] $parts The parsed parts.
65
     * @return IHeaderPart[] Array of resulting final parts.
66
     */
67
    protected function processParts(array $parts) : array
68
    {
69
        $nameOnly = $parts;
70
        $valuePart = \array_pop($nameOnly);
71
        if (!($valuePart instanceof ContainerPart)) {
72
            return [$this->partFactory->newContainerPart($parts)];
73
        }
74
        return [$this->partFactory->newParameterPart(
75
            $nameOnly,
76
            $valuePart
77
        )];
78
    }
79
}
80