Skip to content

Commit

Permalink
Add $not constructor parameter to AST classes (#10267)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Dec 5, 2022
1 parent fa18e13 commit 5a8541b
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 72 deletions.
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Upgrade to 2.14

## Deprecated `Doctrine\ORM\Query\AST\InExpression`

The AST parser will create a `InListExpression` or a `InSubselectExpression` when
encountering an `IN ()` DQL expression instead of a generic `InExpression`.

As a consequence, `SqlWalker::walkInExpression()` has been deprecated in favor of
`SqlWalker::walkInListExpression()` and `SqlWalker::walkInSubselectExpression()`.

## Deprecated constructing a `CacheKey` without `$hash`

The `Doctrine\ORM\Cache\CacheKey` class has an explicit constructor now with
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Query/AST/BetweenExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class BetweenExpression extends Node
* @param ArithmeticExpression $leftExpr
* @param ArithmeticExpression $rightExpr
*/
public function __construct($expr, $leftExpr, $rightExpr)
public function __construct($expr, $leftExpr, $rightExpr, bool $not = false)
{
$this->expression = $expr;
$this->leftBetweenExpression = $leftExpr;
$this->rightBetweenExpression = $rightExpr;
$this->not = $not;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Query/AST/CollectionMemberExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ class CollectionMemberExpression extends Node
* @param mixed $entityExpr
* @param PathExpression $collValuedPathExpr
*/
public function __construct($entityExpr, $collValuedPathExpr)
public function __construct($entityExpr, $collValuedPathExpr, bool $not = false)
{
$this->entityExpression = $entityExpr;
$this->collectionValuedPathExpression = $collValuedPathExpr;
$this->not = $not;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Query/AST/ConditionalFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class ConditionalFactor extends Node
public $conditionalPrimary;

/** @param ConditionalPrimary $conditionalPrimary */
public function __construct($conditionalPrimary)
public function __construct($conditionalPrimary, bool $not = false)
{
$this->conditionalPrimary = $conditionalPrimary;
$this->not = $not;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class EmptyCollectionComparisonExpression extends Node
public $not;

/** @param PathExpression $expression */
public function __construct($expression)
public function __construct($expression, bool $not = false)
{
$this->expression = $expression;
$this->not = $not;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Query/AST/ExistsExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class ExistsExpression extends Node
public $subselect;

/** @param Subselect $subselect */
public function __construct($subselect)
public function __construct($subselect, bool $not = false)
{
$this->subselect = $subselect;
$this->not = $not;
}

/**
Expand Down
16 changes: 15 additions & 1 deletion lib/Doctrine/ORM/Query/AST/InExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace Doctrine\ORM\Query\AST;

use Doctrine\Deprecations\Deprecation;

/**
* InExpression ::= ArithmeticExpression ["NOT"] "IN" "(" (Literal {"," Literal}* | Subselect) ")"
*
* @link www.doctrine-project.org
* @deprecated Use {@see InListExpression} or {@see InSubselectExpression} instead.
*/
class InExpression extends Node
{
Expand All @@ -26,6 +28,17 @@ class InExpression extends Node
/** @param ArithmeticExpression $expression */
public function __construct($expression)
{
if (! $this instanceof InListExpression && ! $this instanceof InSubselectExpression) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/10267',
'%s is deprecated, use %s or %s instead.',
self::class,
InListExpression::class,
InSubselectExpression::class
);
}

$this->expression = $expression;
}

Expand All @@ -34,6 +47,7 @@ public function __construct($expression)
*/
public function dispatch($sqlWalker)
{
// We still call the deprecated method in order to not break existing custom SQL walkers.
return $sqlWalker->walkInExpression($this);
}
}
20 changes: 20 additions & 0 deletions lib/Doctrine/ORM/Query/AST/InListExpression.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Query\AST;

class InListExpression extends InExpression
{
/** @var non-empty-list<mixed> */
public $literals;

/** @param non-empty-list<mixed> $literals */
public function __construct(ArithmeticExpression $expression, array $literals, bool $not = false)
{
$this->literals = $literals;
$this->not = $not;

parent::__construct($expression);
}
}
19 changes: 19 additions & 0 deletions lib/Doctrine/ORM/Query/AST/InSubselectExpression.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Query\AST;

class InSubselectExpression extends InExpression
{
/** @var Subselect */
public $subselect;

public function __construct(ArithmeticExpression $expression, Subselect $subselect, bool $not = false)
{
$this->subselect = $subselect;
$this->not = $not;

parent::__construct($expression);
}
}
24 changes: 21 additions & 3 deletions lib/Doctrine/ORM/Query/AST/InstanceOfExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace Doctrine\ORM\Query\AST;

use Doctrine\Deprecations\Deprecation;

use function func_num_args;

/**
* InstanceOfExpression ::= IdentificationVariable ["NOT"] "INSTANCE" ["OF"] (InstanceOfParameter | "(" InstanceOfParameter {"," InstanceOfParameter}* ")")
* InstanceOfParameter ::= AbstractSchemaName | InputParameter
Expand All @@ -18,13 +22,27 @@ class InstanceOfExpression extends Node
/** @var string */
public $identificationVariable;

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

/** @param string $identVariable */
public function __construct($identVariable)
/**
* @param string $identVariable
* @param non-empty-list<InputParameter|string> $value
*/
public function __construct($identVariable, array $value = [], bool $not = false)
{
if (func_num_args() < 2) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/10267',
'Not passing a value for $value to %s() is deprecated.',
__METHOD__
);
}

$this->identificationVariable = $identVariable;
$this->value = $value;
$this->not = $not;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Query/AST/LikeExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ class LikeExpression extends Node
* @param InputParameter|FunctionNode|PathExpression|Literal $stringPattern
* @param Literal|null $escapeChar
*/
public function __construct($stringExpression, $stringPattern, $escapeChar = null)
public function __construct($stringExpression, $stringPattern, $escapeChar = null, bool $not = false)
{
$this->stringExpression = $stringExpression;
$this->stringPattern = $stringPattern;
$this->escapeChar = $escapeChar;
$this->not = $not;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Query/AST/NullComparisonExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class NullComparisonExpression extends Node
public $expression;

/** @param Node $expression */
public function __construct($expression)
public function __construct($expression, bool $not = false)
{
$this->expression = $expression;
$this->not = $not;
}

/**
Expand Down
Loading

0 comments on commit 5a8541b

Please sign in to comment.