Test Failed
Push — master ( 9ff364...742ef2 )
by Sebastian
03:58
created

setText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Parser
7
 * @see Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
use Mailcode\Parser\Statement\Tokenizer\SpecialChars;
15
16
/**
17
 * Token representing a quoted string literal.
18
 *
19
 * @package Mailcode
20
 * @subpackage Parser
21
 * @author Sebastian Mordziol <[email protected]>
22
 */
23
class Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral extends Mailcode_Parser_Statement_Tokenizer_Token implements Mailcode_Parser_Statement_Tokenizer_ValueInterface
24
{
25
    private string $text;
26
27
    protected function init() : void
28
    {
29
        $this->setText($this->stripQuotes($this->matchedText));
30
    }
31
32
    private function stripQuotes(string $text) : string
33
    {
34
        return trim($text, '"');
35
    }
36
37
    /**
38
    * Retrieves the text with the surrounding quotes,
39
    * and special characters escaped for Mailcode.
40
    *
41
    * @return string
42
    */
43
    public function getNormalized() : string
44
    {
45
        return '"'.SpecialChars::escape($this->text).'"';
46
    }
47
    
48
   /**
49
    * Retrieves the text with the surrounding quotes.
50
    * @return string
51
    */
52
    public function getValue() : string
53
    {
54
        return $this->getNormalized();
55
    }
56
    
57
   /**
58
    * Retrieves the text without the surrounding quotes,
59
    * and special Mailcode characters not escaped.
60
    *
61
    * @return string
62
    */
63
    public function getText() : string
64
    {
65
        return SpecialChars::decode($this->text);
66
    }
67
68
    public function setText(string $text) : self
69
    {
70
        $this->text = SpecialChars::escape($text);
71
        $this->matchedText = '"'.$this->text.'"';
72
73
        return $this;
74
    }
75
}
76