diff --git a/lib/Doctrine/ORM/Query/AST/ComparisonExpression.php b/lib/Doctrine/ORM/Query/AST/ComparisonExpression.php index b3db86593a1..caf7baf32dc 100644 --- a/lib/Doctrine/ORM/Query/AST/ComparisonExpression.php +++ b/lib/Doctrine/ORM/Query/AST/ComparisonExpression.php @@ -16,19 +16,19 @@ */ class ComparisonExpression extends Node { - /** @var Node */ + /** @var Node|string */ public $leftExpression; - /** @var Node */ + /** @var Node|string */ public $rightExpression; /** @var string */ public $operator; /** - * @param Node $leftExpr - * @param string $operator - * @param Node $rightExpr + * @param Node|string $leftExpr + * @param string $operator + * @param Node|string $rightExpr */ public function __construct($leftExpr, $operator, $rightExpr) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php index 67d3415c6a3..670d299a9c2 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php @@ -32,14 +32,20 @@ class LocateFunction extends FunctionNode */ public function getSql(SqlWalker $sqlWalker) { - return $sqlWalker->getConnection()->getDatabasePlatform()->getLocateExpression( - $sqlWalker->walkStringPrimary($this->secondStringPrimary), // its the other way around in platform - $sqlWalker->walkStringPrimary($this->firstStringPrimary), - ($this->simpleArithmeticExpression - ? $sqlWalker->walkSimpleArithmeticExpression($this->simpleArithmeticExpression) - : false - ) - ); + $platform = $sqlWalker->getConnection()->getDatabasePlatform(); + + $firstString = $sqlWalker->walkStringPrimary($this->firstStringPrimary); + $secondString = $sqlWalker->walkStringPrimary($this->secondStringPrimary); + + if ($this->simpleArithmeticExpression) { + return $platform->getLocateExpression( + $secondString, + $firstString, + $sqlWalker->walkSimpleArithmeticExpression($this->simpleArithmeticExpression) + ); + } + + return $platform->getLocateExpression($secondString, $firstString); } /** diff --git a/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php index 9183cc6befc..c26313efdcc 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php @@ -28,7 +28,7 @@ class TrimFunction extends FunctionNode /** @var bool */ public $both; - /** @var bool */ + /** @var string|false */ public $trimChar = false; /** @var Node */ @@ -42,11 +42,16 @@ public function getSql(SqlWalker $sqlWalker) $stringPrimary = $sqlWalker->walkStringPrimary($this->stringPrimary); $platform = $sqlWalker->getConnection()->getDatabasePlatform(); $trimMode = $this->getTrimMode(); - $trimChar = $this->trimChar !== false - ? $sqlWalker->getConnection()->quote($this->trimChar) - : false; - return $platform->getTrimExpression($stringPrimary, $trimMode, $trimChar); + if ($this->trimChar !== false) { + return $platform->getTrimExpression( + $stringPrimary, + $trimMode, + $platform->quoteStringLiteral($this->trimChar) + ); + } + + return $platform->getTrimExpression($stringPrimary, $trimMode); } /** diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ba2039fa06c..01eff86d365 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1498,7 +1498,7 @@ parameters: - message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#" - count: 5 + count: 1 path: lib/Doctrine/ORM/Query/SqlWalker.php - diff --git a/phpstan-dbal2.neon b/phpstan-dbal2.neon index 528329b9276..19a300746a0 100644 --- a/phpstan-dbal2.neon +++ b/phpstan-dbal2.neon @@ -25,3 +25,8 @@ parameters: message: '/^Call to an undefined method Doctrine\\Common\\Cache\\Cache::deleteAll\(\)\.$/' count: 1 path: lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php + # See https://github.com/doctrine/dbal/pull/5129 + - + message: '/^Parameter #3 \$startPos of method Doctrine\\DBAL\\Platforms\\AbstractPlatform::getLocateExpression\(\) expects int\|false, string given\.$/' + count: 1 + path: lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php diff --git a/phpstan.neon b/phpstan.neon index 67a10eea343..6d0c031b284 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -38,3 +38,8 @@ parameters: message: '/^Call to an undefined method Doctrine\\Common\\Cache\\Cache::deleteAll\(\)\.$/' count: 1 path: lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php + # See https://github.com/doctrine/dbal/pull/5129 + - + message: '/^Parameter #3 \$startPos of method Doctrine\\DBAL\\Platforms\\AbstractPlatform::getLocateExpression\(\) expects int\|false, string given\.$/' + count: 1 + path: lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php