-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathFunctionExpression.php
More file actions
108 lines (94 loc) · 2.23 KB
/
FunctionExpression.php
File metadata and controls
108 lines (94 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Vimeo\MysqlEngine\Query\Expression;
use Vimeo\MysqlEngine\Parser\Token;
final class FunctionExpression extends Expression
{
/**
* @var string
*/
public $functionName;
/**
* @var bool
*/
protected $evaluatesGroups = true;
/**
* @var Token
*/
public $token;
/**
* @var array<int, Expression>
*/
public $args;
/**
* @var bool
*/
public $distinct;
/** @var ?array<int, array{expression: Expression, direction: 'ASC'|'DESC'}> $order */
public $order;
/** @var ?Expression $separator */
public $separator;
/**
* @param Token $token
* @param array<int, Expression> $args
* @param ?array<int, array{expression: Expression, direction: 'ASC'|'DESC'}> $order
*/
public function __construct(
Token $token,
array $args,
bool $distinct,
?array $order,
?Expression $separator
)
{
$this->token = $token;
$this->args = $args;
$this->distinct = $distinct;
$this->type = $token->type;
$this->precedence = 0;
$this->functionName = $token->value;
$this->name = $token->value;
$this->operator = $this->type;
$this->start = $token->start;
$this->separator = $separator;
$this->order = $order;
}
/**
* @return string
*/
public function functionName()
{
return $this->functionName;
}
public function hasAggregate(): bool
{
if ($this->functionName === 'COUNT'
|| $this->functionName === 'SUM'
|| $this->functionName === 'MIN'
|| $this->functionName === 'MAX'
|| $this->functionName === 'AVG'
) {
return true;
}
foreach ($this->args as $arg) {
if ($arg->hasAggregate()) {
return true;
}
}
return false;
}
/**
* @return bool
*/
public function isWellFormed()
{
return true;
}
/**
* @return Expression
*/
public function getExpr()
{
\assert(\count($this->args) === 1, 'expression must have one argument');
return \reset($this->args);
}
}