SetStatement   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 35
c 0
b 0
f 0
dl 0
loc 87
rs 10
ccs 5
cts 5
cp 1
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\SqlParser\Statements;
6
7
use PhpMyAdmin\SqlParser\Components\OptionsArray;
8
use PhpMyAdmin\SqlParser\Components\SetOperation;
9
use PhpMyAdmin\SqlParser\Parsers\SetOperations;
10
use PhpMyAdmin\SqlParser\Statement;
11
12
use function trim;
13
14
/**
15
 * `SET` statement.
16
 */
17
class SetStatement extends Statement
18
{
19
    /**
20
     * The clauses of this statement, in order.
21
     *
22
     * @see Statement::$clauses
23
     *
24
     * @var array<string, array{non-empty-string, int-mask-of<self::ADD_*>}>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string, array{non-...-mask-of<self::ADD_*>}> at position 6 could not be parsed: Expected ':' at position 6, but found 'non-empty-string'.
Loading history...
25
     */
26
    public static array $clauses = [
27
        'SET' => [
28
            'SET',
29
            Statement::ADD_CLAUSE | Statement::ADD_KEYWORD,
30
        ],
31
        '_END_OPTIONS' => [
32
            '_END_OPTIONS',
33
            Statement::ADD_CLAUSE,
34
        ],
35
    ];
36
37
    /**
38
     * Possible exceptions in SET statement.
39
     *
40
     * @var array<string, int|array<int, int|string>>
41
     * @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
42
     */
43
    public static array $statementOptions = [
44
        'CHARSET' => [
45
            3,
46
            'var',
47
        ],
48
        'CHARACTER SET' => [
49
            3,
50
            'var',
51
        ],
52
        'NAMES' => [
53
            3,
54
            'var',
55
        ],
56
        'PASSWORD' => [
57
            3,
58
            'expr',
59
        ],
60
        'SESSION' => 3,
61
        'GLOBAL' => 3,
62
        'PERSIST' => 3,
63
        'PERSIST_ONLY' => 3,
64
        '@@SESSION' => 3,
65
        '@@GLOBAL' => 3,
66
        '@@PERSIST' => 3,
67
        '@@PERSIST_ONLY' => 3,
68
    ];
69
70
    protected const STATEMENT_END_OPTIONS = [
71
        'COLLATE' => [
72
            1,
73
            'var',
74
        ],
75
        'DEFAULT' => 1,
76
    ];
77
78
    /**
79
     * Options used in current statement.
80
     */
81
    public OptionsArray|null $options = null;
82
83
    /**
84
     * The end options of this query.
85
     *
86
     * @see SetStatement::STATEMENT_END_OPTIONS
87
     */
88
    public OptionsArray|null $endOptions = null;
89
90
    /**
91
     * The updated values.
92
     *
93
     * @var SetOperation[]|null
94
     */
95
    public array|null $set = null;
96
97 28
    public function build(): string
98
    {
99 28
        $ret = 'SET ' . $this->options->build()
0 ignored issues
show
Bug introduced by
The method build() does not exist on null. ( Ignorable by Annotation )

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

99
        $ret = 'SET ' . $this->options->/** @scrutinizer ignore-call */ build()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100 28
            . ' ' . SetOperations::buildAll($this->set)
0 ignored issues
show
Bug introduced by
It seems like $this->set can also be of type null; however, parameter $component of PhpMyAdmin\SqlParser\Par...tOperations::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

100
            . ' ' . SetOperations::buildAll(/** @scrutinizer ignore-type */ $this->set)
Loading history...
101 28
            . ' ' . ($this->endOptions?->build() ?? '');
102
103 28
        return trim($ret);
104
    }
105
}
106