Completed
Push — master ( 82eb41...4f6b0a )
by Alexander
03:49
created

DatetimeSubLexer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
c 2
b 1
f 0
lcom 0
cbo 2
dl 0
loc 25
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getTokenAt() 0 19 6
1
<?php
2
namespace Xiag\Rql\Parser\SubLexer;
3
4
use Xiag\Rql\Parser\Token;
5
use Xiag\Rql\Parser\SubLexerInterface;
6
use Xiag\Rql\Parser\Exception\SyntaxErrorException;
7
8
class DatetimeSubLexer implements SubLexerInterface
9
{
10
    /**
11
     * @inheritdoc
12
     */
13 45
    public function getTokenAt($code, $cursor)
14
    {
15 45
        $regExp = '/(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})T(?<h>\d{2}):(?<i>\d{2}):(?<s>\d{2})Z/A';
16 45
        if (!preg_match($regExp, $code, $matches, null, $cursor)) {
17 37
            return null;
18
        }
19
20 15
        if (!checkdate($matches['m'], $matches['d'], $matches['y']) ||
21 15
            !($matches['h'] < 24 && $matches['i'] < 60 && $matches['s'] < 60)) {
22 2
            throw new SyntaxErrorException(sprintf('Invalid datetime value "%s"', $matches[0]));
23
        }
24
25 15
        return new Token(
26 15
            Token::T_DATE,
27 15
            $matches[0],
28 15
            $cursor,
29 15
            $cursor + strlen($matches[0])
30 15
        );
31
    }
32
}
33