Passed
Push — master ( 1515ff...7c0b30 )
by Sebastian
04:21
created

getSign()   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_Operand} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Parser
7
 * @see Mailcode_Parser_Statement_Tokenizer_Token_Operand
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Token representing an operand sign.
16
 *
17
 * @package Mailcode
18
 * @subpackage Parser
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Parser_Statement_Tokenizer_Token_Operand extends Mailcode_Parser_Statement_Tokenizer_Token
22
{
23
    public function getSign() : string
24
    {
25
        return $this->matchedText;
26
    }
27
    
28
    public function getNormalized() : string
29
    {
30
        return $this->getSign();
31
    }
32
    
33
   /**
34
    * Retrieves all known comparison operator signs.
35
    * @return string[]
36
    */
37
    public static function getComparisonSigns() : array
38
    {
39
        return array(
40
            '==',
41
            '>',
42
            '<',
43
            '>=',
44
            '<=',
45
            '!='
46
        );
47
    }
48
    
49
   /**
50
    * Whether the operator is comparison related (equals, not equals, smaller, greater...).
51
    *  
52
    * @return bool
53
    */
54
    public function isComparator() : bool
55
    {
56
        return 
57
        $this->isEquals() || 
58
        $this->isNotEquals() ||
59
        $this->isGreaterThan() || 
60
        $this->isGreaterOrEquals() ||
61
        $this->isSmallerThan() ||
62
        $this->isSmallerOrEquals();
63
    }
64
    
65
   /**
66
    * Whether the operator is calculation related (minus, plus, divide, multiply).
67
    * 
68
    * @return bool
69
    */
70
    public function isCalculator() : bool
71
    {
72
        return 
73
        $this->isPlus() || 
74
        $this->isDivide() || 
75
        $this->isMinus() || 
76
        $this->isMultiply();
77
    }
78
    
79
    public function isAssignment() : bool
80
    {
81
        return $this->getSign() === '=';
82
    }
83
    
84
    public function isEquals() : bool
85
    {
86
        return $this->getSign() === '==';
87
    }
88
    
89
    public function isGreaterThan() : bool
90
    {
91
        return $this->getSign() === '>';
92
    }
93
    
94
    public function isSmallerThan() : bool
95
    {
96
        return $this->getSign() === '<';
97
    }
98
    
99
    public function isGreaterOrEquals() : bool
100
    {
101
        return $this->getSign() === '>=';
102
    }
103
    
104
    public function isSmallerOrEquals() : bool
105
    {
106
        return $this->getSign() === '<=';
107
    }
108
    
109
    public function isNotEquals() : bool
110
    {
111
        return $this->getSign() === '!=';
112
    }
113
    
114
    public function isMinus() : bool
115
    {
116
        return $this->getSign() === '-';
117
    }
118
    
119
    public function isMultiply() : bool
120
    {
121
        return $this->getSign() === '*';
122
    }
123
    
124
    public function isDivide() : bool
125
    {
126
        return $this->getSign() === '/';
127
    }
128
    
129
    public function isPlus() : bool
130
    {
131
        return $this->getSign() === '+';
132
    }
133
}
134