Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add return types #103

Open
wants to merge 3 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class AbstractPlatformAwareFunctionNode extends FunctionNode
* @noinspection ReturnTypeCanBeDeclaredInspection
* {@inheritdoc}
*/
public function getSql(SqlWalker $sqlWalker)
public function getSql(SqlWalker $sqlWalker): string
{
$function = FunctionFactory::create(
$sqlWalker->getConnection()->getDatabasePlatform(),
Expand Down
28 changes: 14 additions & 14 deletions src/Oro/ORM/Query/AST/Functions/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

class Cast extends AbstractPlatformAwareFunctionNode
{
Expand Down Expand Up @@ -33,32 +33,32 @@ class Cast extends AbstractPlatformAwareFunctionNode
/**
* {@inheritdoc}
*/
public function parse(Parser $parser)
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::PARAMETER_KEY] = $parser->ArithmeticExpression();

$parser->match(Lexer::T_AS);
$parser->match(TokenType::T_AS);

$parser->match(Lexer::T_IDENTIFIER);
$lexer = $parser->getLexer();
$parser->match(TokenType::T_IDENTIFIER);
$lexer = $parser->getTokenType();
$type = $lexer->token['value'];

if ($lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) {
$parser->match(Lexer::T_OPEN_PARENTHESIS);
if ($lexer->isNextToken(TokenType::T_OPEN_PARENTHESIS)) {
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$parameter = $parser->Literal();
$parameters = [
$parameter->value
];
if ($lexer->isNextToken(Lexer::T_COMMA)) {
while ($lexer->isNextToken(Lexer::T_COMMA)) {
$parser->match(Lexer::T_COMMA);
if ($lexer->isNextToken(TokenType::T_COMMA)) {
while ($lexer->isNextToken(TokenType::T_COMMA)) {
$parser->match(TokenType::T_COMMA);
$parameter = $parser->Literal();
$parameters[] = $parameter->value;
}
}
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
$type .= '(' . \implode(', ', $parameters) . ')';
}

Expand All @@ -75,7 +75,7 @@ public function parse(Parser $parser)

$this->parameters[self::TYPE_KEY] = $type;

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}

protected function isSupportedType(string $type): bool
Expand Down
14 changes: 7 additions & 7 deletions src/Oro/ORM/Query/AST/Functions/DateTime/ConvertTz.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\DateTime;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class ConvertTz extends AbstractPlatformAwareFunctionNode
Expand All @@ -16,15 +16,15 @@ class ConvertTz extends AbstractPlatformAwareFunctionNode
/**
* {@inheritdoc}
*/
public function parse(Parser $parser)
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::VALUE_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->parameters[self::FROM_TZ_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->parameters[self::TO_TZ_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
12 changes: 6 additions & 6 deletions src/Oro/ORM/Query/AST/Functions/Numeric/Pow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\Numeric;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class Pow extends AbstractPlatformAwareFunctionNode
Expand All @@ -15,13 +15,13 @@ class Pow extends AbstractPlatformAwareFunctionNode
/**
* {@inheritdoc}
*/
public function parse(Parser $parser)
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::VALUE_KEY] = $parser->SimpleArithmeticExpression();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->parameters[self::POWER_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
16 changes: 8 additions & 8 deletions src/Oro/ORM/Query/AST/Functions/Numeric/Round.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\Numeric;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class Round extends AbstractPlatformAwareFunctionNode
Expand All @@ -15,19 +15,19 @@ class Round extends AbstractPlatformAwareFunctionNode
/**
* {@inheritdoc}
*/
public function parse(Parser $parser)
public function parse(Parser $parser): void
{
$lexer = $parser->getLexer();
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$lexer = $parser->getTokenType();
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::VALUE] = $parser->SimpleArithmeticExpression();

// parse second parameter if available
if (Lexer::T_COMMA === $lexer->lookahead['type']) {
$parser->match(Lexer::T_COMMA);
if (TokenType::T_COMMA === $lexer->lookahead['type']) {
$parser->match(TokenType::T_COMMA);
$this->parameters[self::PRECISION] = $parser->ArithmeticPrimary();
}

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
10 changes: 5 additions & 5 deletions src/Oro/ORM/Query/AST/Functions/Numeric/Sign.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\Numeric;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class Sign extends AbstractPlatformAwareFunctionNode
Expand All @@ -14,11 +14,11 @@ class Sign extends AbstractPlatformAwareFunctionNode
/**
* {@inheritdoc}
*/
public function parse(Parser $parser)
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::PARAMETER_KEY] = $parser->SimpleArithmeticExpression();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
18 changes: 9 additions & 9 deletions src/Oro/ORM/Query/AST/Functions/Numeric/TimestampDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\Numeric;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class TimestampDiff extends AbstractPlatformAwareFunctionNode
Expand All @@ -31,13 +31,13 @@ class TimestampDiff extends AbstractPlatformAwareFunctionNode
/**
* {@inheritdoc}
*/
public function parse(Parser $parser)
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);

$lexer = $parser->getLexer();
$lexer = $parser->getTokenType();
$unit = strtoupper(trim($lexer->token['value']));
if (!$this->isSupportedUnit($unit)) {
$parser->syntaxError(
Expand All @@ -51,11 +51,11 @@ public function parse(Parser $parser)
}

$this->parameters[self::UNIT_KEY] = $unit;
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->parameters[self::VAL1_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->parameters[self::VAL2_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}

protected function isSupportedUnit(string $unit): bool
Expand Down
10 changes: 5 additions & 5 deletions src/Oro/ORM/Query/AST/Functions/SimpleFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

class SimpleFunction extends AbstractPlatformAwareFunctionNode
{
Expand All @@ -13,11 +13,11 @@ class SimpleFunction extends AbstractPlatformAwareFunctionNode
/**
* {@inheritdoc}
*/
public function parse(Parser $parser)
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::PARAMETER_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
16 changes: 8 additions & 8 deletions src/Oro/ORM/Query/AST/Functions/String/ConcatWs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\String;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

Expand All @@ -16,22 +16,22 @@ class ConcatWs extends AbstractPlatformAwareFunctionNode
/**
* {@inheritdoc}
*/
public function parse(Parser $parser)
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->parameters[self::SEPARATOR_KEY] = $parser->StringPrimary();

$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);

$this->parameters[self::STRINGS_KEY][] = $parser->StringPrimary();

while ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) {
$parser->match(Lexer::T_COMMA);
while ($parser->getTokenType()->isNextToken(TokenType::T_COMMA)) {
$parser->match(TokenType::T_COMMA);
$this->parameters[self::STRINGS_KEY][] = $parser->StringPrimary();
}

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
12 changes: 6 additions & 6 deletions src/Oro/ORM/Query/AST/Functions/String/DateFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Oro\ORM\Query\AST\Functions\String;

use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Doctrine\ORM\Query\Parser;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

Expand Down Expand Up @@ -79,19 +79,19 @@ class DateFormat extends AbstractPlatformAwareFunctionNode
/**
* {@inheritdoc}
*/
public function parse(Parser $parser)
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->parameters[self::DATE_KEY] = $parser->ArithmeticPrimary();

$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);

$this->parameters[self::FORMAT_KEY] = $parser->StringPrimary();
$this->validateFormat($parser);

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}

private function validateFormat(Parser $parser): void
Expand Down
26 changes: 13 additions & 13 deletions src/Oro/ORM/Query/AST/Functions/String/GroupConcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\String;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class GroupConcat extends AbstractPlatformAwareFunctionNode
Expand All @@ -18,14 +18,14 @@ class GroupConcat extends AbstractPlatformAwareFunctionNode
* @url http://sysmagazine.com/posts/181666/
* {@inheritdoc}
*/
public function parse(Parser $parser)
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$lexer = $parser->getLexer();
if ($lexer->isNextToken(Lexer::T_DISTINCT)) {
$parser->match(Lexer::T_DISTINCT);
$lexer = $parser->getTokenType();
if ($lexer->isNextToken(TokenType::T_DISTINCT)) {
$parser->match(TokenType::T_DISTINCT);

$this->parameters[self::DISTINCT_KEY] = true;
}
Expand All @@ -34,24 +34,24 @@ public function parse(Parser $parser)
$this->parameters[self::PARAMETER_KEY] = [];
$this->parameters[self::PARAMETER_KEY][] = $parser->StringPrimary();

while ($lexer->isNextToken(Lexer::T_COMMA)) {
$parser->match(Lexer::T_COMMA);
while ($lexer->isNextToken(TokenType::T_COMMA)) {
$parser->match(TokenType::T_COMMA);
$this->parameters[self::PARAMETER_KEY][] = $parser->StringPrimary();
}

if ($lexer->isNextToken(Lexer::T_ORDER)) {
if ($lexer->isNextToken(TokenType::T_ORDER)) {
$this->parameters[self::ORDER_KEY] = $parser->OrderByClause();
}

if ($lexer->isNextToken(Lexer::T_IDENTIFIER)) {
if ($lexer->isNextToken(TokenType::T_IDENTIFIER)) {
if (\strtolower($lexer->lookahead['value']) !== 'separator') {
$parser->syntaxError('separator');
}
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(TokenType::T_IDENTIFIER);

$this->parameters[self::SEPARATOR_KEY] = $parser->StringPrimary();
}

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
Loading
Loading