Completed
Push — master ( 2a128c...18787f )
by Alexey
02:20
created

AbstractToken::isOperator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * AbstractToken.php
5
 *
6
 * @date 28.03.2015 2:49:42
7
 * @copyright Sklyarov Alexey <[email protected]>
8
 */
9
10
namespace Sufir\Calc\Token;
11
12
use Sufir\Calc\Token;
13
/**
14
 * AbstractToken
15
 *
16
 * Description of AbstractToken
17
 *
18
 * @author Sklyarov Alexey <[email protected]>
19
 * @package Sufir\Calc\Token
20
 */
21
abstract class AbstractToken implements Token
22
{
23
    /**
24
     *
25
     * @var mixed
26
     */
27
    protected $value;
28
29
    /**
30
     *
31
     * @param string $value
32
     * @return \Sufir\Calc\Token\AbstractToken
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
33
     */
34 87
    public function __construct($value)
35
    {
36 87
        if (!$this->validate($value)) {
37 59
            throw new \InvalidArgumentException("Недопустимое значение {$value} для токена " . __CLASS__ . "!");
38
        }
39
40 28
        $this->value = $this->sanitize($value);
41
42 28
        return $this;
43
    }
44
45
    /**
46
     *
47
     * @return mixed
48
     */
49 17
    public function getValue()
50
    {
51 17
        return $this->value;
52
    }
53
54
    /**
55
     *
56
     * @return boolean
57
     */
58 14
    public function isNumber()
59
    {
60 14
        return ($this instanceof NumberToken);
61
    }
62
63
    /**
64
     *
65
     * @return boolean
66
     */
67 14
    public function isFunction()
68
    {
69 14
        return ($this instanceof FunctionToken);
70
    }
71
72
    /**
73
     *
74
     * @return boolean
75
     */
76 13
    public function isOperator()
77
    {
78 13
        return ($this instanceof OperatorToken);
79
    }
80
81
    /**
82
     *
83
     * @return boolean
84
     */
85 14
    public function isBracket()
86
    {
87 14
        return ($this instanceof BracketToken);
88
    }
89
90
    /**
91
     *
92
     * @return boolean
93
     */
94 9
    public function isVariable()
95
    {
96 9
        return ($this instanceof VariableToken);
97
    }
98
99
    /**
100
     *
101
     * @return boolean
102
     */
103 14
    public function isDelimiter()
104
    {
105 14
        return ($this instanceof DelimiterToken);
106
    }
107
108
    /**
109
     *
110
     * @return string
111
     */
112 12
    public function __toString()
113
    {
114 12
        return strval($this->getValue());
115
    }
116
117
    /**
118
     *
119
     * @param string $value
120
     * @return mixed
121
     */
122
    abstract protected function sanitize($value);
123
124
    /**
125
     *
126
     * @param string $value
127
     * @return boolean
128
     */
129
    abstract protected function validate($value);
130
}
131