FiqlOperatorSubLexer::getValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
namespace Xiag\Rql\Parser\SubLexer;
3
4
use Xiag\Rql\Parser\Token;
5
use Xiag\Rql\Parser\SubLexerInterface;
6
7
class FiqlOperatorSubLexer implements SubLexerInterface
8
{
9
    private static $operatorMap = [
10
        '='  => 'eq',
11
        '==' => 'eq',
12
13
        '!=' => 'ne',
14
        '<>' => 'ne',
15
16
        '>'  => 'gt',
17
        '<'  => 'lt',
18
19
        '>=' => 'ge',
20
        '<=' => 'le',
21
    ];
22
23
    /**
24
     * @inheritdoc
25
     */
26 85
    public function getTokenAt($code, $cursor)
27
    {
28 85
        if (!preg_match('/(=[a-z]\w*=|==|!=|<>|>=|<=|<|>|==|=)/Ai', $code, $matches, null, $cursor)) {
29 85
            return null;
30
        }
31
32 11
        return new Token(
33 11
            Token::T_OPERATOR,
34 11
            $this->getValue($matches[0]),
35 11
            $cursor,
36 11
            $cursor + strlen($matches[0])
37 11
        );
38
    }
39
40 11
    private function getValue($match)
41
    {
42 11
        if (isset(self::$operatorMap[$match])) {
43 9
            return self::$operatorMap[$match];
44
        } else {
45 4
            return substr($match, 1, -1);
46
        }
47
    }
48
}
49