1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace PhpMyAdmin\SqlParser\Components; |
||
6 | |||
7 | use PhpMyAdmin\SqlParser\Component; |
||
8 | use PhpMyAdmin\SqlParser\Context; |
||
9 | |||
10 | use function trim; |
||
11 | |||
12 | /** |
||
13 | * The definition of a parameter of a function or procedure. |
||
14 | */ |
||
15 | final class ParameterDefinition implements Component |
||
16 | { |
||
17 | /** |
||
18 | * The name of the new column. |
||
19 | */ |
||
20 | public string|null $name = null; |
||
21 | |||
22 | /** |
||
23 | * Parameter's direction (IN, OUT or INOUT). |
||
24 | */ |
||
25 | public string|null $inOut = null; |
||
26 | |||
27 | /** |
||
28 | * The data type of thew new column. |
||
29 | */ |
||
30 | public DataType|null $type = null; |
||
31 | |||
32 | /** |
||
33 | * @param string|null $name parameter's name |
||
34 | * @param string|null $inOut parameter's directional type (IN / OUT or None) |
||
35 | * @param DataType|null $type parameter's type |
||
36 | */ |
||
37 | 52 | public function __construct(string|null $name = null, string|null $inOut = null, DataType|null $type = null) |
|
38 | { |
||
39 | 52 | $this->name = $name; |
|
40 | 52 | $this->inOut = $inOut; |
|
41 | 52 | $this->type = $type; |
|
42 | } |
||
43 | |||
44 | 6 | public function build(): string |
|
45 | { |
||
46 | 6 | $tmp = ''; |
|
47 | 6 | if (! empty($this->inOut)) { |
|
48 | 4 | $tmp .= $this->inOut . ' '; |
|
49 | } |
||
50 | |||
51 | 6 | return trim( |
|
52 | 6 | $tmp . Context::escape($this->name) . ' ' . $this->type, |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
53 | 6 | ); |
|
54 | } |
||
55 | |||
56 | 6 | public function __toString(): string |
|
57 | { |
||
58 | 6 | return $this->build(); |
|
59 | } |
||
60 | } |
||
61 |