1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\SqlParser\Components; |
6
|
|
|
|
7
|
|
|
use PhpMyAdmin\SqlParser\Component; |
8
|
|
|
use PhpMyAdmin\SqlParser\Parsers\PartitionDefinitions; |
9
|
|
|
use PhpMyAdmin\SqlParser\Token; |
10
|
|
|
use PhpMyAdmin\SqlParser\TokensList; |
11
|
|
|
|
12
|
|
|
use function trim; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Parses an alter operation. |
16
|
|
|
*/ |
17
|
|
|
final class AlterOperation implements Component |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Options of this operation. |
21
|
|
|
*/ |
22
|
|
|
public OptionsArray|null $options = null; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The altered field. |
26
|
|
|
*/ |
27
|
|
|
public Expression|string|null $field = null; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The partitions. |
31
|
|
|
* |
32
|
|
|
* @var PartitionDefinition[]|null |
33
|
|
|
*/ |
34
|
|
|
public array|null $partitions = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param OptionsArray|null $options options of alter operation |
38
|
|
|
* @param Expression|string|null $field altered field |
39
|
|
|
* @param PartitionDefinition[]|null $partitions partitions definition found in the operation |
40
|
|
|
* @param Token[] $unknown unparsed tokens found at the end of operation |
41
|
|
|
*/ |
42
|
236 |
|
public function __construct( |
43
|
|
|
OptionsArray|null $options = null, |
44
|
|
|
Expression|string|null $field = null, |
45
|
|
|
array|null $partitions = null, |
46
|
|
|
public array $unknown = [], |
47
|
|
|
) { |
48
|
236 |
|
$this->partitions = $partitions; |
49
|
236 |
|
$this->options = $options; |
50
|
236 |
|
$this->field = $field; |
51
|
236 |
|
$this->unknown = $unknown; |
52
|
|
|
} |
53
|
|
|
|
54
|
48 |
|
public function build(): string |
55
|
|
|
{ |
56
|
|
|
// Specific case of RENAME COLUMN that insert the field between 2 options. |
57
|
48 |
|
$afterFieldsOptions = new OptionsArray(); |
58
|
48 |
|
if ($this->options->has('RENAME') && $this->options->has('COLUMN')) { |
|
|
|
|
59
|
8 |
|
$afterFieldsOptions = clone $this->options; |
60
|
8 |
|
$afterFieldsOptions->remove('RENAME'); |
61
|
8 |
|
$afterFieldsOptions->remove('COLUMN'); |
62
|
8 |
|
$this->options->remove('TO'); |
63
|
|
|
} |
64
|
|
|
|
65
|
48 |
|
$ret = $this->options . ' '; |
66
|
48 |
|
if (isset($this->field) && ($this->field !== '')) { |
67
|
18 |
|
$ret .= $this->field . ' '; |
68
|
|
|
} |
69
|
|
|
|
70
|
48 |
|
$ret .= $afterFieldsOptions . TokensList::buildFromArray($this->unknown); |
71
|
|
|
|
72
|
48 |
|
if (isset($this->partitions)) { |
73
|
2 |
|
$ret .= PartitionDefinitions::buildAll($this->partitions); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
48 |
|
return trim($ret); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function __toString(): string |
80
|
|
|
{ |
81
|
|
|
return $this->build(); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
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.