FiqlOperatorSubLexer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 42
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTokenAt() 0 13 2
A getValue() 0 8 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