Passed
Pull Request — main (#300)
by Martin
12:42
created

DoctrineLexer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 3
eloc 5
c 2
b 1
f 1
dl 0
loc 26
ccs 5
cts 6
cp 0.8333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLookaheadType() 0 9 2
A isPre200() 0 4 1
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 20
    public static function isPre200(Lexer $lexer): bool
21
    {
22
        // @phpstan-ignore-next-line
23 20
        return \is_array($lexer->lookahead);
24
    }
25
26
    /**
27
     * @return mixed|null
28
     */
29 20
    public static function getLookaheadType(Lexer $lexer)
30
    {
31 20
        if (self::isPre200($lexer)) {
32
            // @phpstan-ignore-next-line
33
            return $lexer->lookahead['type'];
34
        }
35
36
        // @phpstan-ignore-next-line
37 20
        return $lexer->lookahead?->type;
38
    }
39
}
40