Passed
Pull Request — master (#15)
by Sebastian
04:12
created

hasSpacing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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
    public function hasSpacing(): bool
49
    {
50
        return true;
51
    }
52
    
53
   /**
54
    * Retrieves the text with the surrounding quotes.
55
    * @return string
56
    */
57
    public function getValue() : string
58
    {
59
        return $this->getNormalized();
60
    }
61
    
62
   /**
63
    * Retrieves the text without the surrounding quotes,
64
    * and special Mailcode characters not escaped.
65
    *
66
    * @return string
67
    */
68
    public function getText() : string
69
    {
70
        return SpecialChars::decode($this->text);
71
    }
72
73
    public function setText(string $text) : self
74
    {
75
        $this->text = SpecialChars::escape($text);
76
        $this->matchedText = '"'.$this->text.'"';
77
78
        return $this;
79
    }
80
}
81