From be11ef277cd5860597ee5f447008a1e155e33fc8 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 18 Dec 2021 11:26:59 -0800 Subject: [PATCH 1/3] Improve compatibility with AbstractPlatform::getLocateExpression() in DBAL 4 --- .../Query/AST/Functions/LocateFunction.php | 22 ++++++++++++------- phpstan-dbal2.neon | 5 +++++ phpstan.neon | 5 +++++ 3 files changed, 24 insertions(+), 8 deletions(-) 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/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 From fa5fa7451e5544cb38cb62c59044a59629803272 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 18 Dec 2021 11:27:33 -0800 Subject: [PATCH 2/3] Improve compatibility with AbstractPlatform::getTrimExpression() in DBAL 4 --- .../ORM/Query/AST/Functions/TrimFunction.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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); } /** From 8c2136fbfbc7925ab29e5d90fc6ce0ad01e73635 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 18 Dec 2021 11:28:12 -0800 Subject: [PATCH 3/3] Improve compatibility with Connection::quote() in DBAL 4 --- lib/Doctrine/ORM/Query/AST/ComparisonExpression.php | 10 +++++----- phpstan-baseline.neon | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) 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/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 -