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

SubjectToken   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getValue() 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\Part;
9
10
use Psr\Log\LoggerInterface;
11
use ZBateson\MailMimeParser\Header\Part\HeaderPart;
12
use ZBateson\MbWrapper\MbWrapper;
13
14
/**
15
 * Holds a string value token that will require additional processing by a
16
 * consumer prior to returning to a client.
17
 *
18
 * A Token is meant to hold a value for further processing -- for instance when
19
 * consuming an address list header (like From or To) -- before it's known what
20
 * type of IHeaderPart it is (could be an email address, could be a name, or
21
 * could be a group.)
22
 *
23
 * @author Zaahid Bateson
24
 */
25
class SubjectToken extends Token
26
{
27
    public function __construct(
28
        LoggerInterface $logger,
29
        MbWrapper $charsetConverter,
30
        string $value
31
    ) {
32
        parent::__construct($logger, $charsetConverter, $value, true);
33
        $this->value = \preg_replace(['/(\r|\n)+(\s)\s*/', '/(\r|\n)+/'], ['$2', ' '], $value);
34
        $this->isSpace = (\preg_match('/^\s*$/m', $this->value) === 1);
35
        $this->canIgnoreSpacesBefore = $this->canIgnoreSpacesAfter = $this->isSpace;
36
    }
37
38
    /**
39
     * Returns the part's representative value after any necessary processing
40
     * has been performed.  For the raw value, call getRawValue().
41
     */
42
    public function getValue() : string
43
    {
44
        return $this->convertEncoding($this->value);
45
    }
46
}
47