-
Notifications
You must be signed in to change notification settings - Fork 430
/
Copy pathAtan.php
62 lines (50 loc) · 1.74 KB
/
Atan.php
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
<?php
namespace DoctrineExtensions\Query\Mysql;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;
/**
* AtanFunction ::= "ATAN" "(" SimpleArithmeticExpression [ "," SimpleArithmeticExpression ] ")"
*
* @link https://dev.mysql.com/doc/refman/en/mathematical-functions.html#function_atan
*
* @example SELECT ATAN(foo.bar) FROM entity
* @example SELECT ATAN(-2, 2)
* @example SELECT ATAN(PI(), 2)
*/
class Atan extends FunctionNode
{
/** @var Node|string */
public $arithmeticExpression;
/** @var Node|string */
public $optionalSecondExpression;
public function getSql(SqlWalker $sqlWalker): string
{
$secondArgument = '';
if ($this->optionalSecondExpression) {
$secondArgument = $sqlWalker->walkSimpleArithmeticExpression(
$this->optionalSecondExpression
);
}
return 'ATAN(' . $sqlWalker->walkSimpleArithmeticExpression(
$this->arithmeticExpression
) . ($secondArgument ? ', ' . $secondArgument : '')
. ')';
}
public function parse(Parser $parser): void
{
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->arithmeticExpression = $parser->SimpleArithmeticExpression();
try {
$parser->match(TokenType::T_COMMA);
$this->optionalSecondExpression = $parser->SimpleArithmeticExpression();
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
} catch (QueryException $e) {
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
}