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

GlobParser::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
namespace Xiag\Rql\Parser\ValueParser;
3
4
use Xiag\Rql\Parser\Token;
5
use Xiag\Rql\Parser\TokenStream;
6
use Xiag\Rql\Parser\SubParserInterface;
7
use Xiag\Rql\Parser\Glob;
8
9
class GlobParser implements SubParserInterface
10
{
11
    /**
12
     * @var array Allowed types to convert to glob
13
     */
14
    protected static $allowedTypes = [
15
        Token::T_INTEGER,
16
        Token::T_FLOAT,
17
        Token::T_STRING,
18
        Token::T_DATE,
19
    ];
20
21
    /**
22
     * @inheritdoc
23
     */
24 32
    public function parse(TokenStream $tokenStream)
25
    {
26 32
        if ($tokenStream->test(Token::T_GLOB)) {
27 15
            return new Glob($tokenStream->next()->getValue());
28
        }
29
30 17
        if ($tokenStream->nextIf(Token::T_TYPE, 'glob')) {
31 1
            $tokenStream->expect(Token::T_COLON);
32 1
        }
33 17
        return new Glob(Glob::encode($tokenStream->expect(static::$allowedTypes)->getValue()));
34
    }
35
}
36