Issues (119)

src/Statements/RenameStatement.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\SqlParser\Statements;
6
7
use PhpMyAdmin\SqlParser\Components\RenameOperation;
8
use PhpMyAdmin\SqlParser\Parser;
9
use PhpMyAdmin\SqlParser\Parsers\RenameOperations;
10
use PhpMyAdmin\SqlParser\Statement;
11
use PhpMyAdmin\SqlParser\Token;
12
use PhpMyAdmin\SqlParser\TokensList;
13
use PhpMyAdmin\SqlParser\TokenType;
14
15
/**
16
 * `RENAME` statement.
17
 *
18
 * RENAME TABLE tbl_name TO new_tbl_name
19
 *  [, tbl_name2 TO new_tbl_name2] ...
20
 */
21
class RenameStatement extends Statement
22
{
23
    /**
24
     * The old and new names of the tables.
25
     *
26
     * @var RenameOperation[]|null
27
     */
28
    public array|null $renames = null;
29
30
    /**
31
     * Function called before the token is processed.
32
     *
33
     * Skips the `TABLE` keyword after `RENAME`.
34
     *
35
     * @param Parser     $parser the instance that requests parsing
36
     * @param TokensList $list   the list of tokens to be parsed
37
     * @param Token      $token  the token that is being parsed
38
     */
39 18
    public function before(Parser $parser, TokensList $list, Token $token): void
40
    {
41 18
        if (($token->type !== TokenType::Keyword) || ($token->keyword !== 'RENAME')) {
42 2
            return;
43
        }
44
45
        // Checking if it is the beginning of the query.
46 18
        $list->getNextOfTypeAndValue(TokenType::Keyword, 'TABLE');
47
    }
48
49 2
    public function build(): string
50
    {
51 2
        return 'RENAME TABLE ' . RenameOperations::buildAll($this->renames);
0 ignored issues
show
It seems like $this->renames can also be of type null; however, parameter $component of PhpMyAdmin\SqlParser\Par...eOperations::buildAll() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        return 'RENAME TABLE ' . RenameOperations::buildAll(/** @scrutinizer ignore-type */ $this->renames);
Loading history...
52
    }
53
}
54