diff --git a/lib/Doctrine/ORM/Query/AST/ConditionalFactor.php b/lib/Doctrine/ORM/Query/AST/ConditionalFactor.php
index 654b0259263..a39a02c819a 100644
--- a/lib/Doctrine/ORM/Query/AST/ConditionalFactor.php
+++ b/lib/Doctrine/ORM/Query/AST/ConditionalFactor.php
@@ -9,7 +9,7 @@
*
* @link www.doctrine-project.org
*/
-class ConditionalFactor extends Node
+class ConditionalFactor extends Node implements Phase2OptimizableConditional
{
/** @var bool */
public $not = false;
diff --git a/lib/Doctrine/ORM/Query/AST/ConditionalPrimary.php b/lib/Doctrine/ORM/Query/AST/ConditionalPrimary.php
index 381e81488ac..c0c7e917b20 100644
--- a/lib/Doctrine/ORM/Query/AST/ConditionalPrimary.php
+++ b/lib/Doctrine/ORM/Query/AST/ConditionalPrimary.php
@@ -9,12 +9,12 @@
*
* @link www.doctrine-project.org
*/
-class ConditionalPrimary extends Node
+class ConditionalPrimary extends Node implements Phase2OptimizableConditional
{
/** @var Node|null */
public $simpleConditionalExpression;
- /** @var ConditionalExpression|null */
+ /** @var ConditionalExpression|Phase2OptimizableConditional|null */
public $conditionalExpression;
/** @return bool */
diff --git a/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php b/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php
index 9444422be24..37cd95e4e30 100644
--- a/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php
+++ b/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php
@@ -9,7 +9,7 @@
*
* @link www.doctrine-project.org
*/
-class ConditionalTerm extends Node
+class ConditionalTerm extends Node implements Phase2OptimizableConditional
{
/** @var mixed[] */
public $conditionalFactors = [];
diff --git a/lib/Doctrine/ORM/Query/AST/HavingClause.php b/lib/Doctrine/ORM/Query/AST/HavingClause.php
index fbbc3930045..f2891a4c745 100644
--- a/lib/Doctrine/ORM/Query/AST/HavingClause.php
+++ b/lib/Doctrine/ORM/Query/AST/HavingClause.php
@@ -6,10 +6,10 @@
class HavingClause extends Node
{
- /** @var ConditionalExpression */
+ /** @var ConditionalExpression|Phase2OptimizableConditional */
public $conditionalExpression;
- /** @param ConditionalExpression $conditionalExpression */
+ /** @param ConditionalExpression|Phase2OptimizableConditional $conditionalExpression */
public function __construct($conditionalExpression)
{
$this->conditionalExpression = $conditionalExpression;
diff --git a/lib/Doctrine/ORM/Query/AST/Join.php b/lib/Doctrine/ORM/Query/AST/Join.php
index 7b0759228ad..9c595a457ae 100644
--- a/lib/Doctrine/ORM/Query/AST/Join.php
+++ b/lib/Doctrine/ORM/Query/AST/Join.php
@@ -25,7 +25,7 @@ class Join extends Node
/** @var Node|null */
public $joinAssociationDeclaration = null;
- /** @var ConditionalExpression|null */
+ /** @var ConditionalExpression|Phase2OptimizableConditional|null */
public $conditionalExpression = null;
/**
diff --git a/lib/Doctrine/ORM/Query/AST/Phase2OptimizableConditional.php b/lib/Doctrine/ORM/Query/AST/Phase2OptimizableConditional.php
new file mode 100644
index 00000000000..276f8f8d945
--- /dev/null
+++ b/lib/Doctrine/ORM/Query/AST/Phase2OptimizableConditional.php
@@ -0,0 +1,17 @@
+conditionalExpression = $conditionalExpression;
diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php
index a677ca26710..2bbd800c3b5 100644
--- a/lib/Doctrine/ORM/Query/SqlWalker.php
+++ b/lib/Doctrine/ORM/Query/SqlWalker.php
@@ -1010,9 +1010,9 @@ private function generateRangeVariableDeclarationSQL(
/**
* Walks down a JoinAssociationDeclaration AST node, thereby generating the appropriate SQL.
*
- * @param AST\JoinAssociationDeclaration $joinAssociationDeclaration
- * @param int $joinType
- * @param AST\ConditionalExpression $condExpr
+ * @param AST\JoinAssociationDeclaration $joinAssociationDeclaration
+ * @param int $joinType
+ * @param AST\ConditionalExpression|AST\Phase2OptimizableConditional $condExpr
* @psalm-param AST\Join::JOIN_TYPE_* $joinType
*
* @return string
@@ -2048,7 +2048,7 @@ public function walkWhereClause($whereClause)
/**
* Walk down a ConditionalExpression AST node, thereby generating the appropriate SQL.
*
- * @param AST\ConditionalExpression $condExpr
+ * @param AST\ConditionalExpression|AST\Phase2OptimizableConditional $condExpr
*
* @return string
*
@@ -2068,7 +2068,7 @@ public function walkConditionalExpression($condExpr)
/**
* Walks down a ConditionalTerm AST node, thereby generating the appropriate SQL.
*
- * @param AST\ConditionalTerm $condTerm
+ * @param AST\ConditionalTerm|AST\ConditionalFactor|AST\ConditionalPrimary $condTerm
*
* @return string
*
@@ -2088,7 +2088,7 @@ public function walkConditionalTerm($condTerm)
/**
* Walks down a ConditionalFactor AST node, thereby generating the appropriate SQL.
*
- * @param AST\ConditionalFactor $factor
+ * @param AST\ConditionalFactor|AST\ConditionalPrimary $factor
*
* @return string The SQL.
*
diff --git a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php
index 6613e1e7474..0e88dad6ef0 100644
--- a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php
+++ b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php
@@ -6,7 +6,6 @@
use Doctrine\ORM\Query\AST\ArithmeticExpression;
use Doctrine\ORM\Query\AST\ConditionalExpression;
-use Doctrine\ORM\Query\AST\ConditionalFactor;
use Doctrine\ORM\Query\AST\ConditionalPrimary;
use Doctrine\ORM\Query\AST\ConditionalTerm;
use Doctrine\ORM\Query\AST\InListExpression;
@@ -96,10 +95,7 @@ public function walkSelectStatement(SelectStatement $AST)
),
]
);
- } elseif (
- $AST->whereClause->conditionalExpression instanceof ConditionalExpression
- || $AST->whereClause->conditionalExpression instanceof ConditionalFactor
- ) {
+ } else {
$tmpPrimary = new ConditionalPrimary();
$tmpPrimary->conditionalExpression = $AST->whereClause->conditionalExpression;
$AST->whereClause->conditionalExpression = new ConditionalTerm(
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 87d9dc9837c..f85a4fc74cd 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -440,6 +440,11 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Query/SqlWalker.php
+ -
+ message: "#^Parameter \\#1 \\$condTerm of method Doctrine\\\\ORM\\\\Query\\\\SqlWalker\\:\\:walkConditionalTerm\\(\\) expects Doctrine\\\\ORM\\\\Query\\\\AST\\\\ConditionalFactor\\|Doctrine\\\\ORM\\\\Query\\\\AST\\\\ConditionalPrimary\\|Doctrine\\\\ORM\\\\Query\\\\AST\\\\ConditionalTerm, Doctrine\\\\ORM\\\\Query\\\\AST\\\\Phase2OptimizableConditional given\\.$#"
+ count: 1
+ path: lib/Doctrine/ORM/Query/SqlWalker.php
+
-
message: "#^Result of && is always false\\.$#"
count: 1
@@ -595,16 +600,6 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php
- -
- message: "#^Instanceof between \\*NEVER\\* and Doctrine\\\\ORM\\\\Query\\\\AST\\\\ConditionalFactor will always evaluate to false\\.$#"
- count: 1
- path: lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php
-
- -
- message: "#^Instanceof between Doctrine\\\\ORM\\\\Query\\\\AST\\\\ConditionalExpression and Doctrine\\\\ORM\\\\Query\\\\AST\\\\ConditionalPrimary will always evaluate to false\\.$#"
- count: 1
- path: lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php
-
-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 1414b70c24d..17103a694c0 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -2022,18 +2022,13 @@
$AST
- $conditionalExpression
$expr
$pathExp
- ConditionalExpression()]]>
- ConditionalExpression()]]>
lexer->getLiteral($token)]]>
lexer->getLiteral($token)]]>
lexer->getLiteral($token)]]>
- ConditionalExpression()]]>
- ConditionalExpression()]]>
SimpleArithmeticExpression()]]>
@@ -2145,11 +2140,6 @@
$expr
-
- $condExpr
- $condTerm
- $factor
-
string
@@ -2158,7 +2148,6 @@
pathExpression]]>
- conditionalExpression]]>
whereClause]]>
@@ -2194,7 +2183,6 @@
$whereClause !== null
- not ? 'NOT ' : '') . $this->walkConditionalPrimary($factor->conditionalPrimary)]]>
@@ -2633,21 +2621,6 @@
$orderByClause
-
-
- whereClause->conditionalExpression instanceof ConditionalExpression
- || $AST->whereClause->conditionalExpression instanceof ConditionalFactor]]>
- whereClause->conditionalExpression instanceof ConditionalFactor]]>
- whereClause->conditionalExpression instanceof ConditionalPrimary]]>
-
-
- whereClause->conditionalExpression]]>
-
-
- whereClause->conditionalExpression instanceof ConditionalExpression
- || $AST->whereClause->conditionalExpression instanceof ConditionalFactor]]>
-
-
$classes