Passed
Push — master ( b864c0...663ed6 )
by Zaahid
14:05
created

Token::getRawValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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\MbWrapper\MbWrapper;
12
13
/**
14
 * Holds a string value token that will require additional processing by a
15
 * consumer prior to returning to a client.
16
 *
17
 * A Token is meant to hold a value for further processing -- for instance when
18
 * consuming an address list header (like From or To) -- before it's known what
19
 * type of IHeaderPart it is (could be an email address, could be a name, or
20
 * could be a group.)
21
 *
22
 * @author Zaahid Bateson
23
 */
24
class Token extends HeaderPart
25
{
26
    /**
27
     * @var string the raw value of the part.
28
     */
29
    protected string $rawValue;
30
31 111
    public function __construct(
32
        LoggerInterface $logger,
33
        MbWrapper $charsetConverter,
34
        string $value,
35
        bool $isLiteral = false,
36
        bool $preserveSpaces = false
37
    ) {
38 111
        parent::__construct($logger, $charsetConverter, $value);
39 111
        $this->rawValue = $value;
40 111
        if (!$isLiteral) {
41 111
            $this->value = \preg_replace(['/(\r|\n)+(\s)/', '/(\r|\n)+/'], ['$2', ' '], $value);
42 111
            if (!$preserveSpaces) {
43 111
                $this->value = \preg_replace('/^\s+$/m', ' ', $this->value);
44
            }
45
        }
46 111
        $this->isSpace = ($this->value === '' || (!$isLiteral && \preg_match('/^\s*$/m', $this->value) === 1));
47 111
        $this->canIgnoreSpacesBefore = $this->canIgnoreSpacesAfter = $this->isSpace;
48
    }
49
50
    /**
51
     * Returns the part's representative value after any necessary processing
52
     * has been performed.  For the raw value, call getRawValue().
53
     */
54 111
    public function getValue() : string
55
    {
56 111
        return $this->convertEncoding($this->value);
57
    }
58
59
    /**
60
     * Returns the part's raw value.
61
     */
62
    public function getRawValue() : string
63
    {
64
        return $this->rawValue;
65
    }
66
}
67