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

Mailcode_Parser_Statement_Tokenizer_Token::restoreQuotes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 10
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Parser_Statement_Tokenizer_Token} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Parser
7
 * @see Mailcode_Parser_Statement_Tokenizer_Token
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Abstract base class for a single token in a statement.
16
 *
17
 * @package Mailcode
18
 * @subpackage Parser
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
abstract class Mailcode_Parser_Statement_Tokenizer_Token implements Mailcode_Parser_Statement_Tokenizer_TypeInterface
22
{
23
    protected string $tokenID;
24
    protected string $matchedText;
25
    private ?Mailcode_Commands_Command $sourceCommand;
26
27
   /**
28
    * @var mixed
29
    */
30
    protected $subject;
31
32
    /**
33
     * @param string $tokenID
34
     * @param string $matchedText
35
     * @param mixed $subject
36
     * @param Mailcode_Commands_Command|null $sourceCommand
37
     */
38
    public function __construct(string $tokenID, string $matchedText, $subject=null, ?Mailcode_Commands_Command $sourceCommand=null)
39
    {
40
        $this->tokenID = $tokenID;
41
        $this->matchedText = $matchedText;
42
        $this->subject = $subject;
43
        $this->sourceCommand = $sourceCommand;
44
45
        $this->init();
46
    }
47
48
    protected function init() : void
49
    {
50
51
    }
52
53
    /**
54
     * @return Mailcode_Commands_Command|null
55
     */
56
    public function getSourceCommand(): ?Mailcode_Commands_Command
57
    {
58
        return $this->sourceCommand;
59
    }
60
    
61
   /**
62
    * The ID of the type. i.e. the class name ("Keyword", "StringLiteral").
63
    * @return string
64
    */
65
    public function getTypeID() : string
66
    {
67
        $parts = explode('_', get_class($this));
68
        return array_pop($parts);
69
    }
70
    
71
   /**
72
    * Retrieves a unique ID of the token.
73
    * @return string  
74
    */
75
    public function getID() : string
76
    {
77
        return $this->tokenID;
78
    }
79
    
80
    public function getMatchedText() : string
81
    {
82
        return $this->matchedText;
83
    }
84
85
    abstract public function getNormalized() : string;
86
    
87
    final public function isValue() : bool
88
    {
89
        return $this instanceof Mailcode_Parser_Statement_Tokenizer_ValueInterface;
90
    }
91
}
92