Skip to content

Commit 59d612b

Browse files
committed
Add $not constructor parameter to AST classes
1 parent fa18e13 commit 59d612b

18 files changed

+251
-72
lines changed

UPGRADE.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Upgrade to 2.14
22

3+
## Deprecated `Doctrine\ORM\Query\AST\InExpression`
4+
5+
The AST parser will create a `InListExpression` or a `InSubselectExpression` when
6+
encountering an `IN ()` DQL expression instead of a generic `InExpression`.
7+
8+
As a consequence, `SqlWalker::walkInExpression()` has been deprecated in favor of
9+
`SqlWalker::walkInListExpression()` and `SqlWalker::walkInSubselectExpression()`.
10+
311
## Deprecated constructing a `CacheKey` without `$hash`
412

513
The `Doctrine\ORM\Cache\CacheKey` class has an explicit constructor now with

lib/Doctrine/ORM/Query/AST/BetweenExpression.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ class BetweenExpression extends Node
2323
* @param ArithmeticExpression $leftExpr
2424
* @param ArithmeticExpression $rightExpr
2525
*/
26-
public function __construct($expr, $leftExpr, $rightExpr)
26+
public function __construct($expr, $leftExpr, $rightExpr, bool $not = false)
2727
{
2828
$this->expression = $expr;
2929
$this->leftBetweenExpression = $leftExpr;
3030
$this->rightBetweenExpression = $rightExpr;
31+
$this->not = $not;
3132
}
3233

3334
/**

lib/Doctrine/ORM/Query/AST/CollectionMemberExpression.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ class CollectionMemberExpression extends Node
2424
* @param mixed $entityExpr
2525
* @param PathExpression $collValuedPathExpr
2626
*/
27-
public function __construct($entityExpr, $collValuedPathExpr)
27+
public function __construct($entityExpr, $collValuedPathExpr, bool $not = false)
2828
{
2929
$this->entityExpression = $entityExpr;
3030
$this->collectionValuedPathExpression = $collValuedPathExpr;
31+
$this->not = $not;
3132
}
3233

3334
/**

lib/Doctrine/ORM/Query/AST/ConditionalFactor.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ class ConditionalFactor extends Node
1818
public $conditionalPrimary;
1919

2020
/** @param ConditionalPrimary $conditionalPrimary */
21-
public function __construct($conditionalPrimary)
21+
public function __construct($conditionalPrimary, bool $not = false)
2222
{
2323
$this->conditionalPrimary = $conditionalPrimary;
24+
$this->not = $not;
2425
}
2526

2627
/**

lib/Doctrine/ORM/Query/AST/EmptyCollectionComparisonExpression.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ class EmptyCollectionComparisonExpression extends Node
1818
public $not;
1919

2020
/** @param PathExpression $expression */
21-
public function __construct($expression)
21+
public function __construct($expression, bool $not = false)
2222
{
2323
$this->expression = $expression;
24+
$this->not = $not;
2425
}
2526

2627
/**

lib/Doctrine/ORM/Query/AST/ExistsExpression.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ class ExistsExpression extends Node
1818
public $subselect;
1919

2020
/** @param Subselect $subselect */
21-
public function __construct($subselect)
21+
public function __construct($subselect, bool $not = false)
2222
{
2323
$this->subselect = $subselect;
24+
$this->not = $not;
2425
}
2526

2627
/**

lib/Doctrine/ORM/Query/AST/InExpression.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace Doctrine\ORM\Query\AST;
66

7+
use Doctrine\Deprecations\Deprecation;
8+
79
/**
810
* InExpression ::= ArithmeticExpression ["NOT"] "IN" "(" (Literal {"," Literal}* | Subselect) ")"
911
*
10-
* @link www.doctrine-project.org
12+
* @deprecated Use {@see InListExpression} or {@see InSubselectExpression} instead.
1113
*/
1214
class InExpression extends Node
1315
{
@@ -26,6 +28,17 @@ class InExpression extends Node
2628
/** @param ArithmeticExpression $expression */
2729
public function __construct($expression)
2830
{
31+
if (! $this instanceof InListExpression && ! $this instanceof InSubselectExpression) {
32+
Deprecation::trigger(
33+
'doctrine/orm',
34+
'https://github.com/doctrine/orm/pull/10267',
35+
'%s is deprecated, use %s or %s instead.',
36+
self::class,
37+
InListExpression::class,
38+
InSubselectExpression::class
39+
);
40+
}
41+
2942
$this->expression = $expression;
3043
}
3144

@@ -34,6 +47,7 @@ public function __construct($expression)
3447
*/
3548
public function dispatch($sqlWalker)
3649
{
50+
// We still call the deprecated method in order to not break existing custom SQL walkers.
3751
return $sqlWalker->walkInExpression($this);
3852
}
3953
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Query\AST;
6+
7+
class InListExpression extends InExpression
8+
{
9+
/** @var non-empty-list<mixed> */
10+
public $literals;
11+
12+
/** @param non-empty-list<mixed> $literals */
13+
public function __construct(ArithmeticExpression $expression, array $literals, bool $not = false)
14+
{
15+
$this->literals = $literals;
16+
$this->not = $not;
17+
18+
parent::__construct($expression);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Query\AST;
6+
7+
class InSubselectExpression extends InExpression
8+
{
9+
/** @var Subselect */
10+
public $subselect;
11+
12+
public function __construct(ArithmeticExpression $expression, Subselect $subselect, bool $not = false)
13+
{
14+
$this->subselect = $subselect;
15+
$this->not = $not;
16+
17+
parent::__construct($expression);
18+
}
19+
}

lib/Doctrine/ORM/Query/AST/InstanceOfExpression.php

+21-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Doctrine\ORM\Query\AST;
66

7+
use Doctrine\Deprecations\Deprecation;
8+
9+
use function func_num_args;
10+
711
/**
812
* InstanceOfExpression ::= IdentificationVariable ["NOT"] "INSTANCE" ["OF"] (InstanceOfParameter | "(" InstanceOfParameter {"," InstanceOfParameter}* ")")
913
* InstanceOfParameter ::= AbstractSchemaName | InputParameter
@@ -18,13 +22,27 @@ class InstanceOfExpression extends Node
1822
/** @var string */
1923
public $identificationVariable;
2024

21-
/** @var mixed[] */
25+
/** @var non-empty-list<InputParameter|string> */
2226
public $value;
2327

24-
/** @param string $identVariable */
25-
public function __construct($identVariable)
28+
/**
29+
* @param string $identVariable
30+
* @param non-empty-list<InputParameter|string> $value
31+
*/
32+
public function __construct($identVariable, array $value = [], bool $not = false)
2633
{
34+
if (func_num_args() < 2) {
35+
Deprecation::trigger(
36+
'doctrine/orm',
37+
'https://github.com/doctrine/orm/pull/10267',
38+
'Not passing a value for $value to %s() is deprecated.',
39+
__METHOD__
40+
);
41+
}
42+
2743
$this->identificationVariable = $identVariable;
44+
$this->value = $value;
45+
$this->not = $not;
2846
}
2947

3048
/**

lib/Doctrine/ORM/Query/AST/LikeExpression.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ class LikeExpression extends Node
3030
* @param InputParameter|FunctionNode|PathExpression|Literal $stringPattern
3131
* @param Literal|null $escapeChar
3232
*/
33-
public function __construct($stringExpression, $stringPattern, $escapeChar = null)
33+
public function __construct($stringExpression, $stringPattern, $escapeChar = null, bool $not = false)
3434
{
3535
$this->stringExpression = $stringExpression;
3636
$this->stringPattern = $stringPattern;
3737
$this->escapeChar = $escapeChar;
38+
$this->not = $not;
3839
}
3940

4041
/**

lib/Doctrine/ORM/Query/AST/NullComparisonExpression.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ class NullComparisonExpression extends Node
1818
public $expression;
1919

2020
/** @param Node $expression */
21-
public function __construct($expression)
21+
public function __construct($expression, bool $not = false)
2222
{
2323
$this->expression = $expression;
24+
$this->not = $not;
2425
}
2526

2627
/**

0 commit comments

Comments
 (0)