Doctrine\ORM\Query\Parser::AggregateExpression PHP Method

AggregateExpression() public method

AggregateExpression ::= ("AVG" | "MAX" | "MIN" | "SUM") "(" ["DISTINCT"] StateFieldPathExpression ")" | "COUNT" "(" ["DISTINCT"] (IdentificationVariable | SingleValuedPathExpression) ")"
public AggregateExpression ( ) : Doctrine\ORM\Query\AST\AggregateExpression
return Doctrine\ORM\Query\AST\AggregateExpression
    public function AggregateExpression()
    {
        $isDistinct = false;
        $functionName = '';

        if ($this->_lexer->isNextToken(Lexer::T_COUNT)) {
            $this->match(Lexer::T_COUNT);
            $functionName = $this->_lexer->token['value'];
            $this->match(Lexer::T_OPEN_PARENTHESIS);

            if ($this->_lexer->isNextToken(Lexer::T_DISTINCT)) {
                $this->match(Lexer::T_DISTINCT);
                $isDistinct = true;
            }

            $pathExp = $this->SingleValuedPathExpression();
            $this->match(Lexer::T_CLOSE_PARENTHESIS);
        } else {
            if ($this->_lexer->isNextToken(Lexer::T_AVG)) {
                $this->match(Lexer::T_AVG);
            } else if ($this->_lexer->isNextToken(Lexer::T_MAX)) {
                $this->match(Lexer::T_MAX);
            } else if ($this->_lexer->isNextToken(Lexer::T_MIN)) {
                $this->match(Lexer::T_MIN);
            } else if ($this->_lexer->isNextToken(Lexer::T_SUM)) {
                $this->match(Lexer::T_SUM);
            } else {
                $this->syntaxError('One of: MAX, MIN, AVG, SUM, COUNT');
            }

            $functionName = $this->_lexer->token['value'];
            $this->match(Lexer::T_OPEN_PARENTHESIS);
            $pathExp = $this->StateFieldPathExpression();
            $this->match(Lexer::T_CLOSE_PARENTHESIS);
        }

        return new AST\AggregateExpression($functionName, $pathExp, $isDistinct);
    }
Parser