NotImplementedStatement::parse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\SqlParser\Statements;
6
7
use PhpMyAdmin\SqlParser\Parser;
8
use PhpMyAdmin\SqlParser\Statement;
9
use PhpMyAdmin\SqlParser\Token;
10
use PhpMyAdmin\SqlParser\TokensList;
11
use PhpMyAdmin\SqlParser\TokenType;
12
13
/**
14
 * Not implemented (yet) statements.
15
 *
16
 * The `after` function makes the parser jump straight to the first delimiter.
17
 */
18
class NotImplementedStatement extends Statement
19
{
20
    /**
21
     * The part of the statement that can't be parsed.
22
     *
23
     * @var Token[]
24
     */
25
    public array $unknown = [];
26
27
    public function build(): string
28
    {
29
        // Building the parsed part of the query (if any).
30
        $query = parent::build() . ' ';
31
32
        // Rebuilding the unknown part from tokens.
33
        foreach ($this->unknown as $token) {
34
            $query .= $token->token;
35
        }
36
37
        return $query;
38
    }
39
40
    /**
41
     * @param Parser     $parser the instance that requests parsing
42
     * @param TokensList $list   the list of tokens to be parsed
43
     */
44 2
    public function parse(Parser $parser, TokensList $list): void
45
    {
46 2
        for (; $list->idx < $list->count; ++$list->idx) {
47 2
            if ($list->tokens[$list->idx]->type === TokenType::Delimiter) {
48 2
                break;
49
            }
50
51 2
            $this->unknown[] = $list->tokens[$list->idx];
52
        }
53
    }
54
}
55