Code Duplication    Length = 19-21 lines in 2 locations

src/SubLexer/NumberSubLexer.php 1 location

@@ 7-25 (lines=19) @@
4
use Xiag\Rql\Parser\Token;
5
use Xiag\Rql\Parser\SubLexerInterface;
6
7
class NumberSubLexer implements SubLexerInterface
8
{
9
    /**
10
     * @inheritdoc
11
     */
12
    public function getTokenAt($code, $cursor)
13
    {
14
        if (!preg_match('/[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?/A', $code, $matches, null, $cursor)) {
15
            return null;
16
        }
17
18
        return new Token(
19
            filter_var($matches[0], FILTER_VALIDATE_INT) === false ? Token::T_FLOAT : Token::T_INTEGER,
20
            $matches[0],
21
            $cursor,
22
            $cursor + strlen($matches[0])
23
        );
24
    }
25
}
26

src/SubLexer/StringSubLexer.php 1 location

@@ 7-27 (lines=21) @@
4
use Xiag\Rql\Parser\Token;
5
use Xiag\Rql\Parser\SubLexerInterface;
6
7
class StringSubLexer implements SubLexerInterface
8
{
9
    /**
10
     * @inheritdoc
11
     */
12
    public function getTokenAt($code, $cursor)
13
    {
14
        if (!preg_match('/([a-z0-9]|\%[0-9a-f]{2})+/Ai', $code, $matches, null, $cursor)) {
15
            return null;
16
        } elseif (ctype_digit($matches[0])) {
17
            return null;
18
        }
19
20
        return new Token(
21
            Token::T_STRING,
22
            rawurldecode($matches[0]),
23
            $cursor,
24
            $cursor + strlen($matches[0])
25
        );
26
    }
27
}
28