doctrine / orm

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

@@ -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;
@@ -2207,12 +2208,28 @@
Loading
2207 2208
    /**
2208 2209
     * Walks down an InExpression AST node, thereby generating the appropriate SQL.
2209 2210
     *
2211 +
     * @deprecated Use {@see walkInListExpression()} or {@see walkInSubselectExpression()} instead.
2212 +
     *
2210 2213
     * @param AST\InExpression $inExpr
2211 2214
     *
2212 2215
     * @return string
2213 2216
     */
2214 2217
    public function walkInExpression($inExpr)
2215 2218
    {
2219 +
        Deprecation::triggerIfCalledFromOutside(
2220 +
            'doctrine/orm',
2221 +
            '%s() is deprecated, call walkInListExpression() or walkInSubselectExpression() instead.',
2222 +
            __METHOD__
2223 +
        );
2224 +
2225 +
        if ($inExpr instanceof AST\InListExpression) {
2226 +
            return $this->walkInListExpression($inExpr);
2227 +
        }
2228 +
2229 +
        if ($inExpr instanceof AST\InSubselectExpression) {
2230 +
            return $this->walkInSubselectExpression($inExpr);
2231 +
        }
2232 +
2216 2233
        $sql = $this->walkArithmeticExpression($inExpr->expression) . ($inExpr->not ? ' NOT' : '') . ' IN (';
2217 2234
2218 2235
        $sql .= $inExpr->subselect
@@ -2224,6 +2241,28 @@
Loading
2224 2241
        return $sql;
2225 2242
    }
2226 2243
2244 +
    /**
2245 +
     * Walks down an InExpression AST node, thereby generating the appropriate SQL.
2246 +
     */
2247 +
    public function walkInListExpression(AST\InListExpression $inExpr): string
2248 +
    {
2249 +
        return $this->walkArithmeticExpression($inExpr->expression)
2250 +
            . ($inExpr->not ? ' NOT' : '') . ' IN ('
2251 +
            . implode(', ', array_map([$this, 'walkInParameter'], $inExpr->literals))
2252 +
            . ')';
2253 +
    }
2254 +
2255 +
    /**
2256 +
     * Walks down an InExpression AST node, thereby generating the appropriate SQL.
2257 +
     */
2258 +
    public function walkInSubselectExpression(AST\InSubselectExpression $inExpr): string
2259 +
    {
2260 +
        return $this->walkArithmeticExpression($inExpr->expression)
2261 +
            . ($inExpr->not ? ' NOT' : '') . ' IN ('
2262 +
            . $this->walkSubselect($inExpr->subselect)
2263 +
            . ')';
2264 +
    }
2265 +
2227 2266
    /**
2228 2267
     * Walks down an InstanceOfExpression AST node, thereby generating the appropriate SQL.
2229 2268
     *

@@ -18,9 +18,10 @@
Loading
18 18
    public $expression;
19 19
20 20
    /** @param Node $expression */
21 -
    public function __construct($expression)
21 +
    public function __construct($expression, bool $not = false)
22 22
    {
23 23
        $this->expression = $expression;
24 +
        $this->not        = $not;
24 25
    }
25 26
26 27
    /**

@@ -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 +
}

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

@@ -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 +
}

@@ -30,11 +30,12 @@
Loading
30 30
     * @param InputParameter|FunctionNode|PathExpression|Literal $stringPattern
31 31
     * @param Literal|null                                       $escapeChar
32 32
     */
33 -
    public function __construct($stringExpression, $stringPattern, $escapeChar = null)
33 +
    public function __construct($stringExpression, $stringPattern, $escapeChar = null, bool $not = false)
34 34
    {
35 35
        $this->stringExpression = $stringExpression;
36 36
        $this->stringPattern    = $stringPattern;
37 37
        $this->escapeChar       = $escapeChar;
38 +
        $this->not              = $not;
38 39
    }
39 40
40 41
    /**

@@ -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();

@@ -18,9 +18,10 @@
Loading
18 18
    public $not;
19 19
20 20
    /** @param PathExpression $expression */
21 -
    public function __construct($expression)
21 +
    public function __construct($expression, bool $not = false)
22 22
    {
23 23
        $this->expression = $expression;
24 +
        $this->not        = $not;
24 25
    }
25 26
26 27
    /**

@@ -18,9 +18,10 @@
Loading
18 18
    public $subselect;
19 19
20 20
    /** @param Subselect $subselect */
21 -
    public function __construct($subselect)
21 +
    public function __construct($subselect, bool $not = false)
22 22
    {
23 23
        $this->subselect = $subselect;
24 +
        $this->not       = $not;
24 25
    }
25 26
26 27
    /**

@@ -2493,10 +2493,7 @@
Loading
2493 2493
            return $conditionalPrimary;
2494 2494
        }
2495 2495
2496 -
        $conditionalFactor      = new AST\ConditionalFactor($conditionalPrimary);
2497 -
        $conditionalFactor->not = $not;
2498 -
2499 -
        return $conditionalFactor;
2496 +
        return new AST\ConditionalFactor($conditionalPrimary, $not);
2500 2497
    }
2501 2498
2502 2499
    /**
@@ -2651,19 +2648,21 @@
Loading
2651 2648
     */
2652 2649
    public function EmptyCollectionComparisonExpression()
2653 2650
    {
2654 -
        $emptyCollectionCompExpr = new AST\EmptyCollectionComparisonExpression(
2655 -
            $this->CollectionValuedPathExpression()
2656 -
        );
2651 +
        $pathExpression = $this->CollectionValuedPathExpression();
2657 2652
        $this->match(Lexer::T_IS);
2658 2653
2654 +
        $not = false;
2659 2655
        if ($this->lexer->isNextToken(Lexer::T_NOT)) {
2660 2656
            $this->match(Lexer::T_NOT);
2661 -
            $emptyCollectionCompExpr->not = true;
2657 +
            $not = true;
2662 2658
        }
2663 2659
2664 2660
        $this->match(Lexer::T_EMPTY);
2665 2661
2666 -
        return $emptyCollectionCompExpr;
2662 +
        return new AST\EmptyCollectionComparisonExpression(
2663 +
            $pathExpression,
2664 +
            $not
2665 +
        );
2667 2666
    }
2668 2667
2669 2668
    /**
@@ -2691,13 +2690,11 @@
Loading
2691 2690
            $this->match(Lexer::T_OF);
2692 2691
        }
2693 2692
2694 -
        $collMemberExpr      = new AST\CollectionMemberExpression(
2693 +
        return new AST\CollectionMemberExpression(
2695 2694
            $entityExpr,
2696 -
            $this->CollectionValuedPathExpression()
2695 +
            $this->CollectionValuedPathExpression(),
2696 +
            $not
2697 2697
        );
2698 -
        $collMemberExpr->not = $not;
2699 -
2700 -
        return $collMemberExpr;
2701 2698
    }
2702 2699
2703 2700
    /**
@@ -3105,10 +3102,7 @@
Loading
3105 3102
        $this->match(Lexer::T_AND);
3106 3103
        $arithExpr3 = $this->ArithmeticExpression();
3107 3104
3108 -
        $betweenExpr      = new AST\BetweenExpression($arithExpr1, $arithExpr2, $arithExpr3);
3109 -
        $betweenExpr->not = $not;
3110 -
3111 -
        return $betweenExpr;
3105 +
        return new AST\BetweenExpression($arithExpr1, $arithExpr2, $arithExpr3, $not);
3112 3106
    }
3113 3107
3114 3108
    /**
@@ -3132,32 +3126,40 @@
Loading
3132 3126
    /**
3133 3127
     * InExpression ::= SingleValuedPathExpression ["NOT"] "IN" "(" (InParameter {"," InParameter}* | Subselect) ")"
3134 3128
     *
3135 -
     * @return AST\InExpression
3129 +
     * @return AST\InListExpression|AST\InSubselectExpression
3136 3130
     */
3137 3131
    public function InExpression()
3138 3132
    {
3139 -
        $inExpression = new AST\InExpression($this->ArithmeticExpression());
3133 +
        $expression = $this->ArithmeticExpression();
3140 3134
3135 +
        $not = false;
3141 3136
        if ($this->lexer->isNextToken(Lexer::T_NOT)) {
3142 3137
            $this->match(Lexer::T_NOT);
3143 -
            $inExpression->not = true;
3138 +
            $not = true;
3144 3139
        }
3145 3140
3146 3141
        $this->match(Lexer::T_IN);
3147 3142
        $this->match(Lexer::T_OPEN_PARENTHESIS);
3148 3143
3149 3144
        if ($this->lexer->isNextToken(Lexer::T_SELECT)) {
3150 -
            $inExpression->subselect = $this->Subselect();
3145 +
            $inExpression = new AST\InSubselectExpression(
3146 +
                $expression,
3147 +
                $this->Subselect(),
3148 +
                $not
3149 +
            );
3151 3150
        } else {
3152 -
            $literals   = [];
3153 -
            $literals[] = $this->InParameter();
3151 +
            $literals = [$this->InParameter()];
3154 3152
3155 3153
            while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
3156 3154
                $this->match(Lexer::T_COMMA);
3157 3155
                $literals[] = $this->InParameter();
3158 3156
            }
3159 3157
3160 -
            $inExpression->literals = $literals;
3158 +
            $inExpression = new AST\InListExpression(
3159 +
                $expression,
3160 +
                $literals,
3161 +
                $not
3162 +
            );
3161 3163
        }
3162 3164
3163 3165
        $this->match(Lexer::T_CLOSE_PARENTHESIS);
@@ -3172,47 +3174,50 @@
Loading
3172 3174
     */
3173 3175
    public function InstanceOfExpression()
3174 3176
    {
3175 -
        $instanceOfExpression = new AST\InstanceOfExpression($this->IdentificationVariable());
3177 +
        $identificationVariable = $this->IdentificationVariable();
3176 3178
3179 +
        $not = false;
3177 3180
        if ($this->lexer->isNextToken(Lexer::T_NOT)) {
3178 3181
            $this->match(Lexer::T_NOT);
3179 -
            $instanceOfExpression->not = true;
3182 +
            $not = true;
3180 3183
        }
3181 3184
3182 3185
        $this->match(Lexer::T_INSTANCE);
3183 3186
        $this->match(Lexer::T_OF);
3184 3187
3185 -
        $exprValues = [];
3186 -
3187 -
        if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) {
3188 -
            $this->match(Lexer::T_OPEN_PARENTHESIS);
3189 -
3190 -
            $exprValues[] = $this->InstanceOfParameter();
3188 +
        $exprValues = $this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)
3189 +
            ? $this->InstanceOfParameterList()
3190 +
            : [$this->InstanceOfParameter()];
3191 3191
3192 -
            while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
3193 -
                $this->match(Lexer::T_COMMA);
3192 +
        return new AST\InstanceOfExpression(
3193 +
            $identificationVariable,
3194 +
            $exprValues,
3195 +
            $not
3196 +
        );
3197 +
    }
3194 3198
3195 -
                $exprValues[] = $this->InstanceOfParameter();
3196 -
            }
3199 +
    /** @return non-empty-list<AST\InputParameter|string> */
3200 +
    public function InstanceOfParameterList(): array
3201 +
    {
3202 +
        $this->match(Lexer::T_OPEN_PARENTHESIS);
3197 3203
3198 -
            $this->match(Lexer::T_CLOSE_PARENTHESIS);
3204 +
        $exprValues = [$this->InstanceOfParameter()];
3199 3205
3200 -
            $instanceOfExpression->value = $exprValues;
3206 +
        while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
3207 +
            $this->match(Lexer::T_COMMA);
3201 3208
3202 -
            return $instanceOfExpression;
3209 +
            $exprValues[] = $this->InstanceOfParameter();
3203 3210
        }
3204 3211
3205 -
        $exprValues[] = $this->InstanceOfParameter();
3206 -
3207 -
        $instanceOfExpression->value = $exprValues;
3212 +
        $this->match(Lexer::T_CLOSE_PARENTHESIS);
3208 3213
3209 -
        return $instanceOfExpression;
3214 +
        return $exprValues;
3210 3215
    }
3211 3216
3212 3217
    /**
3213 3218
     * InstanceOfParameter ::= AbstractSchemaName | InputParameter
3214 3219
     *
3215 -
     * @return mixed
3220 +
     * @return AST\InputParameter|string
3216 3221
     */
3217 3222
    public function InstanceOfParameter()
3218 3223
    {
@@ -3262,10 +3267,7 @@
Loading
3262 3267
            $escapeChar = new AST\Literal(AST\Literal::STRING, $this->lexer->token['value']);
3263 3268
        }
3264 3269
3265 -
        $likeExpr      = new AST\LikeExpression($stringExpr, $stringPattern, $escapeChar);
3266 -
        $likeExpr->not = $not;
3267 -
3268 -
        return $likeExpr;
3270 +
        return new AST\LikeExpression($stringExpr, $stringPattern, $escapeChar, $not);
3269 3271
    }
3270 3272
3271 3273
    /**
@@ -3327,19 +3329,18 @@
Loading
3327 3329
                break;
3328 3330
        }
3329 3331
3330 -
        $nullCompExpr = new AST\NullComparisonExpression($expr);
3331 -
3332 3332
        $this->match(Lexer::T_IS);
3333 3333
3334 +
        $not = false;
3334 3335
        if ($this->lexer->isNextToken(Lexer::T_NOT)) {
3335 3336
            $this->match(Lexer::T_NOT);
3336 3337
3337 -
            $nullCompExpr->not = true;
3338 +
            $not = true;
3338 3339
        }
3339 3340
3340 3341
        $this->match(Lexer::T_NULL);
3341 3342
3342 -
        return $nullCompExpr;
3343 +
        return new AST\NullComparisonExpression($expr, $not);
3343 3344
    }
3344 3345
3345 3346
    /**
@@ -3359,12 +3360,11 @@
Loading
3359 3360
        $this->match(Lexer::T_EXISTS);
3360 3361
        $this->match(Lexer::T_OPEN_PARENTHESIS);
3361 3362
3362 -
        $existsExpression      = new AST\ExistsExpression($this->Subselect());
3363 -
        $existsExpression->not = $not;
3363 +
        $subselect = $this->Subselect();
3364 3364
3365 3365
        $this->match(Lexer::T_CLOSE_PARENTHESIS);
3366 3366
3367 -
        return $existsExpression;
3367 +
        return new AST\ExistsExpression($subselect, $not);
3368 3368
    }
3369 3369
3370 3370
    /**

@@ -18,9 +18,10 @@
Loading
18 18
    public $conditionalPrimary;
19 19
20 20
    /** @param ConditionalPrimary $conditionalPrimary */
21 -
    public function __construct($conditionalPrimary)
21 +
    public function __construct($conditionalPrimary, bool $not = false)
22 22
    {
23 23
        $this->conditionalPrimary = $conditionalPrimary;
24 +
        $this->not                = $not;
24 25
    }
25 26
26 27
    /**

@@ -4,6 +4,10 @@
Loading
4 4
5 5
namespace Doctrine\ORM\Query\AST;
6 6
7 +
use Doctrine\Deprecations\Deprecation;
8 +
9 +
use function func_num_args;
10 +
7 11
/**
8 12
 * InstanceOfExpression ::= IdentificationVariable ["NOT"] "INSTANCE" ["OF"] (InstanceOfParameter | "(" InstanceOfParameter {"," InstanceOfParameter}* ")")
9 13
 * InstanceOfParameter  ::= AbstractSchemaName | InputParameter
@@ -18,13 +22,27 @@
Loading
18 22
    /** @var string */
19 23
    public $identificationVariable;
20 24
21 -
    /** @var mixed[] */
25 +
    /** @var non-empty-list<InputParameter|string> */
22 26
    public $value;
23 27
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)
26 33
    {
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 +
27 43
        $this->identificationVariable = $identVariable;
44 +
        $this->value                  = $value;
45 +
        $this->not                    = $not;
28 46
    }
29 47
30 48
    /**

@@ -4,10 +4,12 @@
Loading
4 4
5 5
namespace Doctrine\ORM\Query\AST;
6 6
7 +
use Doctrine\Deprecations\Deprecation;
8 +
7 9
/**
8 10
 * InExpression ::= ArithmeticExpression ["NOT"] "IN" "(" (Literal {"," Literal}* | Subselect) ")"
9 11
 *
10 -
 * @link    www.doctrine-project.org
12 +
 * @deprecated Use {@see InListExpression} or {@see InSubselectExpression} instead.
11 13
 */
12 14
class InExpression extends Node
13 15
{
@@ -26,6 +28,17 @@
Loading
26 28
    /** @param ArithmeticExpression $expression */
27 29
    public function __construct($expression)
28 30
    {
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 +
29 42
        $this->expression = $expression;
30 43
    }
31 44
@@ -34,6 +47,7 @@
Loading
34 47
     */
35 48
    public function dispatch($sqlWalker)
36 49
    {
50 +
        // We still call the deprecated method in order to not break existing custom SQL walkers.
37 51
        return $sqlWalker->walkInExpression($this);
38 52
    }
39 53
}
Files Coverage
lib/Doctrine/ORM 84.75%
Project Totals (373 files) 84.75%

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