Passed
Push — master ( 2f714f...1c67eb )
by Sebastian
02:15
created

isComparator()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 7
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 9
rs 9.2222
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 getOperand() : string
24
    {
25
        return $this->matchedText;
26
    }
27
    
28
    public function getNormalized() : string
29
    {
30
        return $this->getOperand();
31
    }
32
    
33
   /**
34
    * Whether the operator is comparison related (equals, not equals, smaller, greater...).
35
    *  
36
    * @return bool
37
    */
38
    public function isComparator() : bool
39
    {
40
        return 
41
        $this->isEquals() || 
42
        $this->isNotEquals() ||
43
        $this->isGreaterThan() || 
44
        $this->isGreaterOrEquals() ||
45
        $this->isSmallerThan() ||
46
        $this->isSmallerOrEquals();
47
    }
48
    
49
   /**
50
    * Whether the operator is calculation related (minus, plus, divide, multiply).
51
    * 
52
    * @return bool
53
    */
54
    public function isCalculator() : bool
55
    {
56
        return 
57
        $this->isPlus() || 
58
        $this->isDivide() || 
59
        $this->isMinus() || 
60
        $this->isMultiply();
61
    }
62
    
63
    public function isAssignment() : bool
64
    {
65
        return $this->getOperand() === '=';
66
    }
67
    
68
    public function isEquals() : bool
69
    {
70
        return $this->getOperand() === '==';
71
    }
72
    
73
    public function isGreaterThan() : bool
74
    {
75
        return $this->getOperand() === '>';
76
    }
77
    
78
    public function isSmallerThan() : bool
79
    {
80
        return $this->getOperand() === '<';
81
    }
82
    
83
    public function isGreaterOrEquals() : bool
84
    {
85
        return $this->getOperand() === '>=';
86
    }
87
    
88
    public function isSmallerOrEquals() : bool
89
    {
90
        return $this->getOperand() === '<=';
91
    }
92
    
93
    public function isNotEquals() : bool
94
    {
95
        return $this->getOperand() === '!=';
96
    }
97
    
98
    public function isMinus() : bool
99
    {
100
        return $this->getOperand() === '-';
101
    }
102
    
103
    public function isMultiply() : bool
104
    {
105
        return $this->getOperand() === '*';
106
    }
107
    
108
    public function isDivide() : bool
109
    {
110
        return $this->getOperand() === '/';
111
    }
112
    
113
    public function isPlus() : bool
114
    {
115
        return $this->getOperand() === '+';
116
    }
117
}
118