DoctrineLexer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 10
c 1
b 1
f 1
dl 0
loc 45
ccs 8
cts 12
cp 0.6667
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLookaheadType() 0 9 2
A isPre200() 0 4 1
A getTokenValue() 0 14 3
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