Mailcode_Parser_Statement_Tokenizer_Token_Operand   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
c 0
b 0
f 0
dl 0
loc 130
rs 10
wmc 26

18 Methods

Rating   Name   Duplication   Size   Complexity  
A getSign() 0 3 1
A getNormalized() 0 3 1
A getComparisonSigns() 0 9 1
A isComparator() 0 9 6
A isMinus() 0 3 1
A isMultiply() 0 3 1
A isAssignment() 0 3 1
A isNotEquals() 0 3 1
A isSmallerOrEquals() 0 3 1
A isPlus() 0 3 1
A hasSpacing() 0 3 1
A getArithmeticSigns() 0 7 1
A isDivide() 0 3 1
A isCalculator() 0 7 4
A isGreaterThan() 0 3 1
A isGreaterOrEquals() 0 3 1
A isSmallerThan() 0 3 1
A isEquals() 0 3 1
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
    public function hasSpacing(): bool
34
    {
35
        return true;
36
    }
37
    
38
   /**
39
    * Retrieves all known comparison operator signs.
40
    * @return string[]
41
    */
42
    public static function getComparisonSigns() : array
43
    {
44
        return array(
45
            '==',
46
            '>',
47
            '<',
48
            '>=',
49
            '<=',
50
            '!='
51
        );
52
    }
53
    
54
   /**
55
    * Retrieves all known arithmetic operator signs.
56
    * @return string[]
57
    */
58
    public static function getArithmeticSigns() : array
59
    {
60
        return array(
61
            '+',
62
            '-',
63
            '/',
64
            '*'
65
        );
66
    }
67
    
68
   /**
69
    * Whether the operator is comparison related (equals, not equals, smaller, greater...).
70
    *  
71
    * @return bool
72
    */
73
    public function isComparator() : bool
74
    {
75
        return 
76
        $this->isEquals() || 
77
        $this->isNotEquals() ||
78
        $this->isGreaterThan() || 
79
        $this->isGreaterOrEquals() ||
80
        $this->isSmallerThan() ||
81
        $this->isSmallerOrEquals();
82
    }
83
    
84
   /**
85
    * Whether the operator is calculation related (minus, plus, divide, multiply).
86
    * 
87
    * @return bool
88
    */
89
    public function isCalculator() : bool
90
    {
91
        return 
92
        $this->isPlus() || 
93
        $this->isDivide() || 
94
        $this->isMinus() || 
95
        $this->isMultiply();
96
    }
97
    
98
    public function isAssignment() : bool
99
    {
100
        return $this->getSign() === '=';
101
    }
102
    
103
    public function isEquals() : bool
104
    {
105
        return $this->getSign() === '==';
106
    }
107
    
108
    public function isGreaterThan() : bool
109
    {
110
        return $this->getSign() === '>';
111
    }
112
    
113
    public function isSmallerThan() : bool
114
    {
115
        return $this->getSign() === '<';
116
    }
117
    
118
    public function isGreaterOrEquals() : bool
119
    {
120
        return $this->getSign() === '>=';
121
    }
122
    
123
    public function isSmallerOrEquals() : bool
124
    {
125
        return $this->getSign() === '<=';
126
    }
127
    
128
    public function isNotEquals() : bool
129
    {
130
        return $this->getSign() === '!=';
131
    }
132
    
133
    public function isMinus() : bool
134
    {
135
        return $this->getSign() === '-';
136
    }
137
    
138
    public function isMultiply() : bool
139
    {
140
        return $this->getSign() === '*';
141
    }
142
    
143
    public function isDivide() : bool
144
    {
145
        return $this->getSign() === '/';
146
    }
147
    
148
    public function isPlus() : bool
149
    {
150
        return $this->getSign() === '+';
151
    }
152
}
153