DoctrineLexer::isPre200()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 1
c 1
b 1
f 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\Utils;
6
7
use Doctrine\ORM\Query\Lexer;
8
9
/**
10
 * @internal
11
 */
12
final class DoctrineLexer
13
{
14
    /**
15
     * Checks if the Lexer is prior to version 2.0.0.
16
     *
17
     * In Lexer versions prior to 2.0.0, the lookahead property is an array,
18
     * while in 2.0.0+ it's an object.
19
     */
20 133
    public static function isPre200(Lexer $lexer): bool
21
    {
22
        // @phpstan-ignore-next-line
23 133
        return \is_array($lexer->lookahead);
24
    }
25
26
    /**
27
     * @return mixed|null
28
     */
29 132
    public static function getLookaheadType(Lexer $lexer)
30
    {
31 132
        if (self::isPre200($lexer)) {
32
            // @phpstan-ignore-next-line
33
            return $lexer->lookahead['type'];
34
        }
35
36
        // @phpstan-ignore-next-line
37 132
        return $lexer->lookahead?->type;
38
    }
39
40
    /**
41
     * @return mixed|null
42
     */
43 1
    public static function getTokenValue(Lexer $lexer)
44
    {
45 1
        if (self::isPre200($lexer)) {
46
            // @phpstan-ignore-next-line
47
            if ($lexer->token === null) {
48
                return null;
49
            }
50
51
            // @phpstan-ignore-next-line
52
            return $lexer->token['value'];
53
        }
54
55
        // @phpstan-ignore-next-line
56 1
        return $lexer->token?->value;
57
    }
58
}
59