1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Parses a function call. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace PhpMyAdmin\SqlParser\Components; |
8
|
|
|
|
9
|
|
|
use PhpMyAdmin\SqlParser\Component; |
10
|
|
|
use PhpMyAdmin\SqlParser\Parser; |
11
|
|
|
use PhpMyAdmin\SqlParser\Token; |
12
|
|
|
use PhpMyAdmin\SqlParser\TokensList; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Parses a function call. |
16
|
|
|
* |
17
|
|
|
* @category Keywords |
18
|
|
|
* |
19
|
|
|
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ |
20
|
|
|
*/ |
21
|
|
|
class FunctionCall extends Component |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The name of this function. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $name; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The list of parameters. |
32
|
|
|
* |
33
|
|
|
* @var ArrayObj |
34
|
|
|
*/ |
35
|
|
|
public $parameters; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Constructor. |
39
|
|
|
* |
40
|
|
|
* @param string $name the name of the function to be called |
|
|
|
|
41
|
|
|
* @param array|ArrayObj $parameters the parameters of this function |
|
|
|
|
42
|
|
|
*/ |
43
|
7 |
|
public function __construct($name = null, $parameters = null) |
44
|
|
|
{ |
45
|
7 |
|
$this->name = $name; |
46
|
7 |
|
if (is_array($parameters)) { |
47
|
1 |
|
$this->parameters = new ArrayObj($parameters); |
48
|
|
|
} elseif ($parameters instanceof ArrayObj) { |
49
|
1 |
|
$this->parameters = $parameters; |
50
|
|
|
} |
51
|
7 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Parser $parser the parser that serves as context |
55
|
|
|
* @param TokensList $list the list of tokens that are being parsed |
56
|
|
|
* @param array $options parameters for parsing |
57
|
|
|
* |
58
|
|
|
* @return FunctionCall |
59
|
|
|
*/ |
60
|
5 |
|
public static function parse(Parser $parser, TokensList $list, array $options = array()) |
61
|
|
|
{ |
62
|
5 |
|
$ret = new self(); |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* The state of the parser. |
66
|
|
|
* |
67
|
|
|
* Below are the states of the parser. |
68
|
|
|
* |
69
|
|
|
* 0 ----------------------[ name ]-----------------------> 1 |
70
|
|
|
* |
71
|
|
|
* 1 --------------------[ parameters ]-------------------> (END) |
72
|
|
|
* |
73
|
|
|
* @var int |
74
|
|
|
*/ |
75
|
5 |
|
$state = 0; |
76
|
|
|
|
77
|
5 |
|
for (; $list->idx < $list->count; ++$list->idx) { |
78
|
|
|
/** |
79
|
|
|
* Token parsed at this moment. |
80
|
|
|
* |
81
|
|
|
* @var Token |
82
|
|
|
*/ |
83
|
5 |
|
$token = $list->tokens[$list->idx]; |
84
|
|
|
|
85
|
|
|
// End of statement. |
86
|
5 |
|
if ($token->type === Token::TYPE_DELIMITER) { |
87
|
1 |
|
break; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// Skipping whitespaces and comments. |
91
|
5 |
|
if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) { |
92
|
5 |
|
continue; |
93
|
|
|
} |
94
|
|
|
|
95
|
5 |
|
if ($state === 0) { |
96
|
5 |
|
$ret->name = $token->value; |
97
|
5 |
|
$state = 1; |
98
|
4 |
|
} elseif ($state === 1) { |
99
|
4 |
|
if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) { |
100
|
4 |
|
$ret->parameters = ArrayObj::parse($parser, $list); |
|
|
|
|
101
|
|
|
} |
102
|
4 |
|
break; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
5 |
|
return $ret; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param FunctionCall $component the component to be built |
111
|
|
|
* @param array $options parameters for building |
112
|
|
|
* |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
2 |
|
public static function build($component, array $options = array()) |
116
|
|
|
{ |
117
|
2 |
|
return $component->name . $component->parameters; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.