doctrine / orm

@@ -26,10 +26,11 @@
Loading
26 26
     * @param mixed          $entityExpr
27 27
     * @param PathExpression $collValuedPathExpr
28 28
     */
29 -
    public function __construct($entityExpr, $collValuedPathExpr)
29 +
    public function __construct($entityExpr, $collValuedPathExpr, bool $not = false)
30 30
    {
31 31
        $this->entityExpression               = $entityExpr;
32 32
        $this->collectionValuedPathExpression = $collValuedPathExpr;
33 +
        $this->not                            = $not;
33 34
    }
34 35
35 36
    public function dispatch(SqlWalker $walker): string

@@ -9,6 +9,7 @@
Loading
9 9
use Doctrine\DBAL\LockMode;
10 10
use Doctrine\DBAL\Platforms\AbstractPlatform;
11 11
use Doctrine\DBAL\Types\Type;
12 +
use Doctrine\Deprecations\Deprecation;
12 13
use Doctrine\ORM\EntityManagerInterface;
13 14
use Doctrine\ORM\Mapping\ClassMetadata;
14 15
use Doctrine\ORM\Mapping\QuoteStrategy;
@@ -1945,9 +1946,25 @@
Loading
1945 1946
1946 1947
    /**
1947 1948
     * Walks down an InExpression AST node, thereby generating the appropriate SQL.
1949 +
     *
1950 +
     * @deprecated Use {@see walkInListExpression()} or {@see walkInSubselectExpression()} instead.
1948 1951
     */
1949 1952
    public function walkInExpression(AST\InExpression $inExpr): string
1950 1953
    {
1954 +
        Deprecation::triggerIfCalledFromOutside(
1955 +
            'doctrine/orm',
1956 +
            '%s() is deprecated, call walkInListExpression() or walkInSubselectExpression() instead.',
1957 +
            __METHOD__,
1958 +
        );
1959 +
1960 +
        if ($inExpr instanceof AST\InListExpression) {
1961 +
            return $this->walkInListExpression($inExpr);
1962 +
        }
1963 +
1964 +
        if ($inExpr instanceof AST\InSubselectExpression) {
1965 +
            return $this->walkInSubselectExpression($inExpr);
1966 +
        }
1967 +
1951 1968
        $sql = $this->walkArithmeticExpression($inExpr->expression) . ($inExpr->not ? ' NOT' : '') . ' IN (';
1952 1969
1953 1970
        $sql .= $inExpr->subselect
@@ -1959,6 +1976,28 @@
Loading
1959 1976
        return $sql;
1960 1977
    }
1961 1978
1979 +
    /**
1980 +
     * Walks down an InExpression AST node, thereby generating the appropriate SQL.
1981 +
     */
1982 +
    public function walkInListExpression(AST\InListExpression $inExpr): string
1983 +
    {
1984 +
        return $this->walkArithmeticExpression($inExpr->expression)
1985 +
            . ($inExpr->not ? ' NOT' : '') . ' IN ('
1986 +
            . implode(', ', array_map([$this, 'walkInParameter'], $inExpr->literals))
1987 +
            . ')';
1988 +
    }
1989 +
1990 +
    /**
1991 +
     * Walks down an InExpression AST node, thereby generating the appropriate SQL.
1992 +
     */
1993 +
    public function walkInSubselectExpression(AST\InSubselectExpression $inExpr): string
1994 +
    {
1995 +
        return $this->walkArithmeticExpression($inExpr->expression)
1996 +
            . ($inExpr->not ? ' NOT' : '') . ' IN ('
1997 +
            . $this->walkSubselect($inExpr->subselect)
1998 +
            . ')';
1999 +
    }
2000 +
1962 2001
    /**
1963 2002
     * Walks down an InstanceOfExpression AST node, thereby generating the appropriate SQL.
1964 2003
     *

@@ -13,12 +13,11 @@
Loading
13 13
 */
14 14
class NullComparisonExpression extends Node
15 15
{
16 -
    /** @var bool */
17 -
    public $not;
18 -
19 16
    /** @param Node $expression */
20 -
    public function __construct(public $expression)
21 -
    {
17 +
    public function __construct(
18 +
        public $expression,
19 +
        public bool $not = false,
20 +
    ) {
22 21
    }
23 22
24 23
    public function dispatch(SqlWalker $walker): string

@@ -0,0 +1,20 @@
Loading
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 +
}

@@ -25,11 +25,12 @@
Loading
25 25
     * @param ArithmeticExpression $leftExpr
26 26
     * @param ArithmeticExpression $rightExpr
27 27
     */
28 -
    public function __construct($expr, $leftExpr, $rightExpr)
28 +
    public function __construct($expr, $leftExpr, $rightExpr, bool $not = false)
29 29
    {
30 30
        $this->expression             = $expr;
31 31
        $this->leftBetweenExpression  = $leftExpr;
32 32
        $this->rightBetweenExpression = $rightExpr;
33 +
        $this->not                    = $not;
33 34
    }
34 35
35 36
    public function dispatch(SqlWalker $walker): string

@@ -0,0 +1,19 @@
Loading
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 +
}

@@ -14,16 +14,17 @@
Loading
14 14
 */
15 15
class LikeExpression extends Node
16 16
{
17 -
    /** @var bool */
18 -
    public $not = false;
19 -
20 17
    /**
21 18
     * @param Node|string                                        $stringExpression
22 19
     * @param InputParameter|FunctionNode|PathExpression|Literal $stringPattern
23 20
     * @param Literal|null                                       $escapeChar
24 21
     */
25 -
    public function __construct(public $stringExpression, public $stringPattern, public $escapeChar = null)
26 -
    {
22 +
    public function __construct(
23 +
        public $stringExpression,
24 +
        public $stringPattern,
25 +
        public $escapeChar = null,
26 +
        public bool $not = false,
27 +
    ) {
27 28
    }
28 29
29 30
    public function dispatch(SqlWalker $walker): string

@@ -9,7 +9,7 @@
Loading
9 9
use Doctrine\ORM\Query\AST\ConditionalFactor;
10 10
use Doctrine\ORM\Query\AST\ConditionalPrimary;
11 11
use Doctrine\ORM\Query\AST\ConditionalTerm;
12 -
use Doctrine\ORM\Query\AST\InExpression;
12 +
use Doctrine\ORM\Query\AST\InListExpression;
13 13
use Doctrine\ORM\Query\AST\InputParameter;
14 14
use Doctrine\ORM\Query\AST\NullComparisonExpression;
15 15
use Doctrine\ORM\Query\AST\PathExpression;
@@ -76,8 +76,10 @@
Loading
76 76
            $arithmeticExpression->simpleArithmeticExpression = new SimpleArithmeticExpression(
77 77
                [$pathExpression],
78 78
            );
79 -
            $expression                                       = new InExpression($arithmeticExpression);
80 -
            $expression->literals[]                           = new InputParameter(':' . self::PAGINATOR_ID_ALIAS);
79 +
            $expression                                       = new InListExpression(
80 +
                $arithmeticExpression,
81 +
                [new InputParameter(':' . self::PAGINATOR_ID_ALIAS)],
82 +
            );
81 83
82 84
            $this->convertWhereInIdentifiersToDatabaseValue(
83 85
                PersisterHelper::getTypeOfField(
@@ -88,8 +90,7 @@
Loading
88 90
                )[0],
89 91
            );
90 92
        } else {
91 -
            $expression      = new NullComparisonExpression($pathExpression);
92 -
            $expression->not = false;
93 +
            $expression = new NullComparisonExpression($pathExpression);
93 94
        }
94 95
95 96
        $conditionalPrimary                              = new ConditionalPrimary();

@@ -13,12 +13,11 @@
Loading
13 13
 */
14 14
class EmptyCollectionComparisonExpression extends Node
15 15
{
16 -
    /** @var bool */
17 -
    public $not;
18 -
19 16
    /** @param PathExpression $expression */
20 -
    public function __construct(public $expression)
21 -
    {
17 +
    public function __construct(
18 +
        public $expression,
19 +
        public bool $not = false,
20 +
    ) {
22 21
    }
23 22
24 23
    public function dispatch(SqlWalker $walker): string

@@ -13,12 +13,11 @@
Loading
13 13
 */
14 14
class ExistsExpression extends Node
15 15
{
16 -
    /** @var bool */
17 -
    public $not;
18 -
19 16
    /** @param Subselect $subselect */
20 -
    public function __construct(public $subselect)
21 -
    {
17 +
    public function __construct(
18 +
        public $subselect,
19 +
        public bool $not = false,
20 +
    ) {
22 21
    }
23 22
24 23
    public function dispatch(SqlWalker $walker): string

@@ -2477,10 +2477,7 @@
Loading
2477 2477
            return $conditionalPrimary;
2478 2478
        }
2479 2479
2480 -
        $conditionalFactor      = new AST\ConditionalFactor($conditionalPrimary);
2481 -
        $conditionalFactor->not = $not;
2482 -
2483 -
        return $conditionalFactor;
2480 +
        return new AST\ConditionalFactor($conditionalPrimary, $not);
2484 2481
    }
2485 2482
2486 2483
    /**
@@ -2635,19 +2632,21 @@
Loading
2635 2632
     */
2636 2633
    public function EmptyCollectionComparisonExpression()
2637 2634
    {
2638 -
        $emptyCollectionCompExpr = new AST\EmptyCollectionComparisonExpression(
2639 -
            $this->CollectionValuedPathExpression(),
2640 -
        );
2635 +
        $pathExpression = $this->CollectionValuedPathExpression();
2641 2636
        $this->match(Lexer::T_IS);
2642 2637
2638 +
        $not = false;
2643 2639
        if ($this->lexer->isNextToken(Lexer::T_NOT)) {
2644 2640
            $this->match(Lexer::T_NOT);
2645 -
            $emptyCollectionCompExpr->not = true;
2641 +
            $not = true;
2646 2642
        }
2647 2643
2648 2644
        $this->match(Lexer::T_EMPTY);
2649 2645
2650 -
        return $emptyCollectionCompExpr;
2646 +
        return new AST\EmptyCollectionComparisonExpression(
2647 +
            $pathExpression,
2648 +
            $not,
2649 +
        );
2651 2650
    }
2652 2651
2653 2652
    /**
@@ -2675,13 +2674,11 @@
Loading
2675 2674
            $this->match(Lexer::T_OF);
2676 2675
        }
2677 2676
2678 -
        $collMemberExpr      = new AST\CollectionMemberExpression(
2677 +
        return new AST\CollectionMemberExpression(
2679 2678
            $entityExpr,
2680 2679
            $this->CollectionValuedPathExpression(),
2680 +
            $not,
2681 2681
        );
2682 -
        $collMemberExpr->not = $not;
2683 -
2684 -
        return $collMemberExpr;
2685 2682
    }
2686 2683
2687 2684
    /**
@@ -3089,10 +3086,7 @@
Loading
3089 3086
        $this->match(Lexer::T_AND);
3090 3087
        $arithExpr3 = $this->ArithmeticExpression();
3091 3088
3092 -
        $betweenExpr      = new AST\BetweenExpression($arithExpr1, $arithExpr2, $arithExpr3);
3093 -
        $betweenExpr->not = $not;
3094 -
3095 -
        return $betweenExpr;
3089 +
        return new AST\BetweenExpression($arithExpr1, $arithExpr2, $arithExpr3, $not);
3096 3090
    }
3097 3091
3098 3092
    /**
@@ -3116,32 +3110,40 @@
Loading
3116 3110
    /**
3117 3111
     * InExpression ::= SingleValuedPathExpression ["NOT"] "IN" "(" (InParameter {"," InParameter}* | Subselect) ")"
3118 3112
     *
3119 -
     * @return AST\InExpression
3113 +
     * @return AST\InListExpression|AST\InSubselectExpression
3120 3114
     */
3121 3115
    public function InExpression()
3122 3116
    {
3123 -
        $inExpression = new AST\InExpression($this->ArithmeticExpression());
3117 +
        $expression = $this->ArithmeticExpression();
3124 3118
3119 +
        $not = false;
3125 3120
        if ($this->lexer->isNextToken(Lexer::T_NOT)) {
3126 3121
            $this->match(Lexer::T_NOT);
3127 -
            $inExpression->not = true;
3122 +
            $not = true;
3128 3123
        }
3129 3124
3130 3125
        $this->match(Lexer::T_IN);
3131 3126
        $this->match(Lexer::T_OPEN_PARENTHESIS);
3132 3127
3133 3128
        if ($this->lexer->isNextToken(Lexer::T_SELECT)) {
3134 -
            $inExpression->subselect = $this->Subselect();
3129 +
            $inExpression = new AST\InSubselectExpression(
3130 +
                $expression,
3131 +
                $this->Subselect(),
3132 +
                $not,
3133 +
            );
3135 3134
        } else {
3136 -
            $literals   = [];
3137 -
            $literals[] = $this->InParameter();
3135 +
            $literals = [$this->InParameter()];
3138 3136
3139 3137
            while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
3140 3138
                $this->match(Lexer::T_COMMA);
3141 3139
                $literals[] = $this->InParameter();
3142 3140
            }
3143 3141
3144 -
            $inExpression->literals = $literals;
3142 +
            $inExpression = new AST\InListExpression(
3143 +
                $expression,
3144 +
                $literals,
3145 +
                $not,
3146 +
            );
3145 3147
        }
3146 3148
3147 3149
        $this->match(Lexer::T_CLOSE_PARENTHESIS);
@@ -3156,47 +3158,50 @@
Loading
3156 3158
     */
3157 3159
    public function InstanceOfExpression()
3158 3160
    {
3159 -
        $instanceOfExpression = new AST\InstanceOfExpression($this->IdentificationVariable());
3161 +
        $identificationVariable = $this->IdentificationVariable();
3160 3162
3163 +
        $not = false;
3161 3164
        if ($this->lexer->isNextToken(Lexer::T_NOT)) {
3162 3165
            $this->match(Lexer::T_NOT);
3163 -
            $instanceOfExpression->not = true;
3166 +
            $not = true;
3164 3167
        }
3165 3168
3166 3169
        $this->match(Lexer::T_INSTANCE);
3167 3170
        $this->match(Lexer::T_OF);
3168 3171
3169 -
        $exprValues = [];
3170 -
3171 -
        if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) {
3172 -
            $this->match(Lexer::T_OPEN_PARENTHESIS);
3173 -
3174 -
            $exprValues[] = $this->InstanceOfParameter();
3172 +
        $exprValues = $this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)
3173 +
            ? $this->InstanceOfParameterList()
3174 +
            : [$this->InstanceOfParameter()];
3175 3175
3176 -
            while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
3177 -
                $this->match(Lexer::T_COMMA);
3176 +
        return new AST\InstanceOfExpression(
3177 +
            $identificationVariable,
3178 +
            $exprValues,
3179 +
            $not,
3180 +
        );
3181 +
    }
3178 3182
3179 -
                $exprValues[] = $this->InstanceOfParameter();
3180 -
            }
3183 +
    /** @return non-empty-list<AST\InputParameter|string> */
3184 +
    public function InstanceOfParameterList(): array
3185 +
    {
3186 +
        $this->match(Lexer::T_OPEN_PARENTHESIS);
3181 3187
3182 -
            $this->match(Lexer::T_CLOSE_PARENTHESIS);
3188 +
        $exprValues = [$this->InstanceOfParameter()];
3183 3189
3184 -
            $instanceOfExpression->value = $exprValues;
3190 +
        while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
3191 +
            $this->match(Lexer::T_COMMA);
3185 3192
3186 -
            return $instanceOfExpression;
3193 +
            $exprValues[] = $this->InstanceOfParameter();
3187 3194
        }
3188 3195
3189 -
        $exprValues[] = $this->InstanceOfParameter();
3190 -
3191 -
        $instanceOfExpression->value = $exprValues;
3196 +
        $this->match(Lexer::T_CLOSE_PARENTHESIS);
3192 3197
3193 -
        return $instanceOfExpression;
3198 +
        return $exprValues;
3194 3199
    }
3195 3200
3196 3201
    /**
3197 3202
     * InstanceOfParameter ::= AbstractSchemaName | InputParameter
3198 3203
     *
3199 -
     * @return mixed
3204 +
     * @return AST\InputParameter|string
3200 3205
     */
3201 3206
    public function InstanceOfParameter()
3202 3207
    {
@@ -3246,10 +3251,7 @@
Loading
3246 3251
            $escapeChar = new AST\Literal(AST\Literal::STRING, $this->lexer->token['value']);
3247 3252
        }
3248 3253
3249 -
        $likeExpr      = new AST\LikeExpression($stringExpr, $stringPattern, $escapeChar);
3250 -
        $likeExpr->not = $not;
3251 -
3252 -
        return $likeExpr;
3254 +
        return new AST\LikeExpression($stringExpr, $stringPattern, $escapeChar, $not);
3253 3255
    }
3254 3256
3255 3257
    /**
@@ -3311,19 +3313,18 @@
Loading
3311 3313
                break;
3312 3314
        }
3313 3315
3314 -
        $nullCompExpr = new AST\NullComparisonExpression($expr);
3315 -
3316 3316
        $this->match(Lexer::T_IS);
3317 3317
3318 +
        $not = false;
3318 3319
        if ($this->lexer->isNextToken(Lexer::T_NOT)) {
3319 3320
            $this->match(Lexer::T_NOT);
3320 3321
3321 -
            $nullCompExpr->not = true;
3322 +
            $not = true;
3322 3323
        }
3323 3324
3324 3325
        $this->match(Lexer::T_NULL);
3325 3326
3326 -
        return $nullCompExpr;
3327 +
        return new AST\NullComparisonExpression($expr, $not);
3327 3328
    }
3328 3329
3329 3330
    /**
@@ -3343,12 +3344,11 @@
Loading
3343 3344
        $this->match(Lexer::T_EXISTS);
3344 3345
        $this->match(Lexer::T_OPEN_PARENTHESIS);
3345 3346
3346 -
        $existsExpression      = new AST\ExistsExpression($this->Subselect());
3347 -
        $existsExpression->not = $not;
3347 +
        $subselect = $this->Subselect();
3348 3348
3349 3349
        $this->match(Lexer::T_CLOSE_PARENTHESIS);
3350 3350
3351 -
        return $existsExpression;
3351 +
        return new AST\ExistsExpression($subselect, $not);
3352 3352
    }
3353 3353
3354 3354
    /**

@@ -13,12 +13,11 @@
Loading
13 13
 */
14 14
class ConditionalFactor extends Node
15 15
{
16 -
    /** @var bool */
17 -
    public $not = false;
18 -
19 16
    /** @param ConditionalPrimary $conditionalPrimary */
20 -
    public function __construct(public $conditionalPrimary)
21 -
    {
17 +
    public function __construct(
18 +
        public $conditionalPrimary,
19 +
        public bool $not = false,
20 +
    ) {
22 21
    }
23 22
24 23
    public function dispatch(SqlWalker $walker): string

@@ -4,8 +4,11 @@
Loading
4 4
5 5
namespace Doctrine\ORM\Query\AST;
6 6
7 +
use Doctrine\Deprecations\Deprecation;
7 8
use Doctrine\ORM\Query\SqlWalker;
8 9
10 +
use function func_num_args;
11 +
9 12
/**
10 13
 * InstanceOfExpression ::= IdentificationVariable ["NOT"] "INSTANCE" ["OF"] (InstanceOfParameter | "(" InstanceOfParameter {"," InstanceOfParameter}* ")")
11 14
 * InstanceOfParameter  ::= AbstractSchemaName | InputParameter
@@ -14,18 +17,27 @@
Loading
14 17
 */
15 18
class InstanceOfExpression extends Node
16 19
{
17 -
    /** @var bool */
18 -
    public $not;
19 -
20 20
    /** @var string */
21 21
    public $identificationVariable;
22 22
23 -
    /** @var mixed[] */
24 -
    public $value;
23 +
    /**
24 +
     * @param string                                $identVariable
25 +
     * @param non-empty-list<InputParameter|string> $value
26 +
     */
27 +
    public function __construct(
28 +
        $identVariable,
29 +
        public array $value = [],
30 +
        public bool $not = false,
31 +
    ) {
32 +
        if (func_num_args() < 2) {
33 +
            Deprecation::trigger(
34 +
                'doctrine/orm',
35 +
                'https://github.com/doctrine/orm/pull/10267',
36 +
                'Not passing a value for $value to %s() is deprecated.',
37 +
                __METHOD__,
38 +
            );
39 +
        }
25 40
26 -
    /** @param string $identVariable */
27 -
    public function __construct($identVariable)
28 -
    {
29 41
        $this->identificationVariable = $identVariable;
30 42
    }
31 43

@@ -4,12 +4,13 @@
Loading
4 4
5 5
namespace Doctrine\ORM\Query\AST;
6 6
7 +
use Doctrine\Deprecations\Deprecation;
7 8
use Doctrine\ORM\Query\SqlWalker;
8 9
9 10
/**
10 11
 * InExpression ::= ArithmeticExpression ["NOT"] "IN" "(" (Literal {"," Literal}* | Subselect) ")"
11 12
 *
12 -
 * @link    www.doctrine-project.org
13 +
 * @deprecated Use {@see InListExpression} or {@see InSubselectExpression} instead.
13 14
 */
14 15
class InExpression extends Node
15 16
{
@@ -25,10 +26,21 @@
Loading
25 26
    /** @param ArithmeticExpression $expression */
26 27
    public function __construct(public $expression)
27 28
    {
29 +
        if (! $this instanceof InListExpression && ! $this instanceof InSubselectExpression) {
30 +
            Deprecation::trigger(
31 +
                'doctrine/orm',
32 +
                'https://github.com/doctrine/orm/pull/10267',
33 +
                '%s is deprecated, use %s or %s instead.',
34 +
                self::class,
35 +
                InListExpression::class,
36 +
                InSubselectExpression::class,
37 +
            );
38 +
        }
28 39
    }
29 40
30 41
    public function dispatch(SqlWalker $walker): string
31 42
    {
43 +
        // We still call the deprecated method in order to not break existing custom SQL walkers.
32 44
        return $walker->walkInExpression($this);
33 45
    }
34 46
}
Files Coverage
lib/Doctrine/ORM 89.61%
Project Totals (332 files) 89.61%

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading