doctrine / orm

@@ -4,51 +4,43 @@
Loading
4 4
5 5
namespace Doctrine\ORM\Query\Expr;
6 6
7 +
use Stringable;
8 +
7 9
/**
8 10
 * Expression class for DQL comparison expressions.
9 11
 *
10 12
 * @link    www.doctrine-project.org
11 13
 */
12 -
class Comparison
14 +
class Comparison implements Stringable
13 15
{
14 -
    public const EQ  = '=';
15 -
    public const NEQ = '<>';
16 -
    public const LT  = '<';
17 -
    public const LTE = '<=';
18 -
    public const GT  = '>';
19 -
    public const GTE = '>=';
20 -
21 -
    /**
22 -
     * Creates a comparison expression with the given arguments.
23 -
     *
24 -
     * @param mixed  $leftExpr
25 -
     * @param string $operator
26 -
     * @param mixed  $rightExpr
27 -
     */
28 -
    public function __construct(protected $leftExpr, protected $operator, protected $rightExpr)
16 +
    final public const EQ  = '=';
17 +
    final public const NEQ = '<>';
18 +
    final public const LT  = '<';
19 +
    final public const LTE = '<=';
20 +
    final public const GT  = '>';
21 +
    final public const GTE = '>=';
22 +
23 +
    /** Creates a comparison expression with the given arguments. */
24 +
    public function __construct(protected mixed $leftExpr, protected string $operator, protected mixed $rightExpr)
29 25
    {
30 26
    }
31 27
32 -
    /** @return mixed */
33 -
    public function getLeftExpr()
28 +
    public function getLeftExpr(): mixed
34 29
    {
35 30
        return $this->leftExpr;
36 31
    }
37 32
38 -
    /** @return string */
39 -
    public function getOperator()
33 +
    public function getOperator(): string
40 34
    {
41 35
        return $this->operator;
42 36
    }
43 37
44 -
    /** @return mixed */
45 -
    public function getRightExpr()
38 +
    public function getRightExpr(): mixed
46 39
    {
47 40
        return $this->rightExpr;
48 41
    }
49 42
50 -
    /** @return string */
51 -
    public function __toString()
43 +
    public function __toString(): string
52 44
    {
53 45
        return $this->leftExpr . ' ' . $this->operator . ' ' . $this->rightExpr;
54 46
    }

@@ -4,6 +4,8 @@
Loading
4 4
5 5
namespace Doctrine\ORM\Query\Expr;
6 6
7 +
use Stringable;
8 +
7 9
use function implode;
8 10
9 11
/**
@@ -11,37 +13,36 @@
Loading
11 13
 *
12 14
 * @link    www.doctrine-project.org
13 15
 */
14 -
class Func
16 +
class Func implements Stringable
15 17
{
16 18
    /** @var mixed[] */
17 -
    protected $arguments;
19 +
    protected array $arguments;
18 20
19 21
    /**
20 22
     * Creates a function, with the given argument.
21 23
     *
22 -
     * @param string        $name
23 24
     * @param mixed[]|mixed $arguments
24 25
     * @psalm-param list<mixed>|mixed $arguments
25 26
     */
26 -
    public function __construct(protected $name, $arguments)
27 -
    {
27 +
    public function __construct(
28 +
        protected string $name,
29 +
        $arguments,
30 +
    ) {
28 31
        $this->arguments = (array) $arguments;
29 32
    }
30 33
31 -
    /** @return string */
32 -
    public function getName()
34 +
    public function getName(): string
33 35
    {
34 36
        return $this->name;
35 37
    }
36 38
37 39
    /** @psalm-return list<mixed> */
38 -
    public function getArguments()
40 +
    public function getArguments(): array
39 41
    {
40 42
        return $this->arguments;
41 43
    }
42 44
43 -
    /** @return string */
44 -
    public function __toString()
45 +
    public function __toString(): string
45 46
    {
46 47
        return $this->name . '(' . implode(', ', $this->arguments) . ')';
47 48
    }

@@ -4,6 +4,8 @@
Loading
4 4
5 5
namespace Doctrine\ORM\Query\Expr;
6 6
7 +
use Stringable;
8 +
7 9
use function strtoupper;
8 10
9 11
/**
@@ -11,13 +13,13 @@
Loading
11 13
 *
12 14
 * @link    www.doctrine-project.org
13 15
 */
14 -
class Join
16 +
class Join implements Stringable
15 17
{
16 -
    public const INNER_JOIN = 'INNER';
17 -
    public const LEFT_JOIN  = 'LEFT';
18 +
    final public const INNER_JOIN = 'INNER';
19 +
    final public const LEFT_JOIN  = 'LEFT';
18 20
19 -
    public const ON   = 'ON';
20 -
    public const WITH = 'WITH';
21 +
    final public const ON   = 'ON';
22 +
    final public const WITH = 'WITH';
21 23
22 24
    /**
23 25
     * @psalm-param self::INNER_JOIN|self::LEFT_JOIN $joinType

@@ -23,88 +23,88 @@
Loading
23 23
class Lexer extends AbstractLexer
24 24
{
25 25
    // All tokens that are not valid identifiers must be < 100
26 -
    public const T_NONE              = 1;
27 -
    public const T_INTEGER           = 2;
28 -
    public const T_STRING            = 3;
29 -
    public const T_INPUT_PARAMETER   = 4;
30 -
    public const T_FLOAT             = 5;
31 -
    public const T_CLOSE_PARENTHESIS = 6;
32 -
    public const T_OPEN_PARENTHESIS  = 7;
33 -
    public const T_COMMA             = 8;
34 -
    public const T_DIVIDE            = 9;
35 -
    public const T_DOT               = 10;
36 -
    public const T_EQUALS            = 11;
37 -
    public const T_GREATER_THAN      = 12;
38 -
    public const T_LOWER_THAN        = 13;
39 -
    public const T_MINUS             = 14;
40 -
    public const T_MULTIPLY          = 15;
41 -
    public const T_NEGATE            = 16;
42 -
    public const T_PLUS              = 17;
43 -
    public const T_OPEN_CURLY_BRACE  = 18;
44 -
    public const T_CLOSE_CURLY_BRACE = 19;
26 +
    final public const T_NONE              = 1;
27 +
    final public const T_INTEGER           = 2;
28 +
    final public const T_STRING            = 3;
29 +
    final public const T_INPUT_PARAMETER   = 4;
30 +
    final public const T_FLOAT             = 5;
31 +
    final public const T_CLOSE_PARENTHESIS = 6;
32 +
    final public const T_OPEN_PARENTHESIS  = 7;
33 +
    final public const T_COMMA             = 8;
34 +
    final public const T_DIVIDE            = 9;
35 +
    final public const T_DOT               = 10;
36 +
    final public const T_EQUALS            = 11;
37 +
    final public const T_GREATER_THAN      = 12;
38 +
    final public const T_LOWER_THAN        = 13;
39 +
    final public const T_MINUS             = 14;
40 +
    final public const T_MULTIPLY          = 15;
41 +
    final public const T_NEGATE            = 16;
42 +
    final public const T_PLUS              = 17;
43 +
    final public const T_OPEN_CURLY_BRACE  = 18;
44 +
    final public const T_CLOSE_CURLY_BRACE = 19;
45 45
46 46
    // All tokens that are identifiers or keywords that could be considered as identifiers should be >= 100
47 -
    public const T_FULLY_QUALIFIED_NAME = 101;
48 -
    public const T_IDENTIFIER           = 102;
47 +
    final public const T_FULLY_QUALIFIED_NAME = 101;
48 +
    final public const T_IDENTIFIER           = 102;
49 49
50 50
    // All keyword tokens should be >= 200
51 -
    public const T_ALL      = 200;
52 -
    public const T_AND      = 201;
53 -
    public const T_ANY      = 202;
54 -
    public const T_AS       = 203;
55 -
    public const T_ASC      = 204;
56 -
    public const T_AVG      = 205;
57 -
    public const T_BETWEEN  = 206;
58 -
    public const T_BOTH     = 207;
59 -
    public const T_BY       = 208;
60 -
    public const T_CASE     = 209;
61 -
    public const T_COALESCE = 210;
62 -
    public const T_COUNT    = 211;
63 -
    public const T_DELETE   = 212;
64 -
    public const T_DESC     = 213;
65 -
    public const T_DISTINCT = 214;
66 -
    public const T_ELSE     = 215;
67 -
    public const T_EMPTY    = 216;
68 -
    public const T_END      = 217;
69 -
    public const T_ESCAPE   = 218;
70 -
    public const T_EXISTS   = 219;
71 -
    public const T_FALSE    = 220;
72 -
    public const T_FROM     = 221;
73 -
    public const T_GROUP    = 222;
74 -
    public const T_HAVING   = 223;
75 -
    public const T_HIDDEN   = 224;
76 -
    public const T_IN       = 225;
77 -
    public const T_INDEX    = 226;
78 -
    public const T_INNER    = 227;
79 -
    public const T_INSTANCE = 228;
80 -
    public const T_IS       = 229;
81 -
    public const T_JOIN     = 230;
82 -
    public const T_LEADING  = 231;
83 -
    public const T_LEFT     = 232;
84 -
    public const T_LIKE     = 233;
85 -
    public const T_MAX      = 234;
86 -
    public const T_MEMBER   = 235;
87 -
    public const T_MIN      = 236;
88 -
    public const T_NEW      = 237;
89 -
    public const T_NOT      = 238;
90 -
    public const T_NULL     = 239;
91 -
    public const T_NULLIF   = 240;
92 -
    public const T_OF       = 241;
93 -
    public const T_OR       = 242;
94 -
    public const T_ORDER    = 243;
95 -
    public const T_OUTER    = 244;
96 -
    public const T_PARTIAL  = 245;
97 -
    public const T_SELECT   = 246;
98 -
    public const T_SET      = 247;
99 -
    public const T_SOME     = 248;
100 -
    public const T_SUM      = 249;
101 -
    public const T_THEN     = 250;
102 -
    public const T_TRAILING = 251;
103 -
    public const T_TRUE     = 252;
104 -
    public const T_UPDATE   = 253;
105 -
    public const T_WHEN     = 254;
106 -
    public const T_WHERE    = 255;
107 -
    public const T_WITH     = 256;
51 +
    final public const T_ALL      = 200;
52 +
    final public const T_AND      = 201;
53 +
    final public const T_ANY      = 202;
54 +
    final public const T_AS       = 203;
55 +
    final public const T_ASC      = 204;
56 +
    final public const T_AVG      = 205;
57 +
    final public const T_BETWEEN  = 206;
58 +
    final public const T_BOTH     = 207;
59 +
    final public const T_BY       = 208;
60 +
    final public const T_CASE     = 209;
61 +
    final public const T_COALESCE = 210;
62 +
    final public const T_COUNT    = 211;
63 +
    final public const T_DELETE   = 212;
64 +
    final public const T_DESC     = 213;
65 +
    final public const T_DISTINCT = 214;
66 +
    final public const T_ELSE     = 215;
67 +
    final public const T_EMPTY    = 216;
68 +
    final public const T_END      = 217;
69 +
    final public const T_ESCAPE   = 218;
70 +
    final public const T_EXISTS   = 219;
71 +
    final public const T_FALSE    = 220;
72 +
    final public const T_FROM     = 221;
73 +
    final public const T_GROUP    = 222;
74 +
    final public const T_HAVING   = 223;
75 +
    final public const T_HIDDEN   = 224;
76 +
    final public const T_IN       = 225;
77 +
    final public const T_INDEX    = 226;
78 +
    final public const T_INNER    = 227;
79 +
    final public const T_INSTANCE = 228;
80 +
    final public const T_IS       = 229;
81 +
    final public const T_JOIN     = 230;
82 +
    final public const T_LEADING  = 231;
83 +
    final public const T_LEFT     = 232;
84 +
    final public const T_LIKE     = 233;
85 +
    final public const T_MAX      = 234;
86 +
    final public const T_MEMBER   = 235;
87 +
    final public const T_MIN      = 236;
88 +
    final public const T_NEW      = 237;
89 +
    final public const T_NOT      = 238;
90 +
    final public const T_NULL     = 239;
91 +
    final public const T_NULLIF   = 240;
92 +
    final public const T_OF       = 241;
93 +
    final public const T_OR       = 242;
94 +
    final public const T_ORDER    = 243;
95 +
    final public const T_OUTER    = 244;
96 +
    final public const T_PARTIAL  = 245;
97 +
    final public const T_SELECT   = 246;
98 +
    final public const T_SET      = 247;
99 +
    final public const T_SOME     = 248;
100 +
    final public const T_SUM      = 249;
101 +
    final public const T_THEN     = 250;
102 +
    final public const T_TRAILING = 251;
103 +
    final public const T_TRUE     = 252;
104 +
    final public const T_UPDATE   = 253;
105 +
    final public const T_WHEN     = 254;
106 +
    final public const T_WHERE    = 255;
107 +
    final public const T_WITH     = 256;
108 108
109 109
    /**
110 110
     * Creates a new query scanner object.
@@ -119,7 +119,7 @@
Loading
119 119
    /**
120 120
     * {@inheritdoc}
121 121
     */
122 -
    protected function getCatchablePatterns()
122 +
    protected function getCatchablePatterns(): array
123 123
    {
124 124
        return [
125 125
            '[a-z_][a-z0-9_]*\:[a-z_][a-z0-9_]*(?:\\\[a-z_][a-z0-9_]*)*', // aliased name
@@ -133,7 +133,7 @@
Loading
133 133
    /**
134 134
     * {@inheritdoc}
135 135
     */
136 -
    protected function getNonCatchablePatterns()
136 +
    protected function getNonCatchablePatterns(): array
137 137
    {
138 138
        return ['\s+', '--.*', '(.)'];
139 139
    }

@@ -11,20 +11,17 @@
Loading
11 11
 */
12 12
class Select extends Base
13 13
{
14 -
    /** @var string */
15 -
    protected $preSeparator = '';
16 -
17 -
    /** @var string */
18 -
    protected $postSeparator = '';
14 +
    protected string $preSeparator  = '';
15 +
    protected string $postSeparator = '';
19 16
20 17
    /** @var string[] */
21 -
    protected $allowedClasses = [Func::class];
18 +
    protected array $allowedClasses = [Func::class];
22 19
23 20
    /** @psalm-var list<string|Func> */
24 -
    protected $parts = [];
21 +
    protected array $parts = [];
25 22
26 23
    /** @psalm-return list<string|Func> */
27 -
    public function getParts()
24 +
    public function getParts(): array
28 25
    {
29 26
        return $this->parts;
30 27
    }

@@ -4,42 +4,43 @@
Loading
4 4
5 5
namespace Doctrine\ORM\Query\Expr;
6 6
7 +
use Stringable;
8 +
7 9
/**
8 10
 * Expression class for DQL from.
9 11
 *
10 12
 * @link    www.doctrine-project.org
11 13
 */
12 -
class From
14 +
class From implements Stringable
13 15
{
14 16
    /**
15 -
     * @param class-string $from    The class name.
16 -
     * @param string       $alias   The alias of the class.
17 -
     * @param string       $indexBy The index for the from.
17 +
     * @param class-string $from  The class name.
18 +
     * @param string       $alias The alias of the class.
18 19
     */
19 -
    public function __construct(protected $from, protected $alias, protected $indexBy = null)
20 -
    {
20 +
    public function __construct(
21 +
        protected string $from,
22 +
        protected string $alias,
23 +
        protected string|null $indexBy = null,
24 +
    ) {
21 25
    }
22 26
23 27
    /** @return class-string */
24 -
    public function getFrom()
28 +
    public function getFrom(): string
25 29
    {
26 30
        return $this->from;
27 31
    }
28 32
29 -
    /** @return string */
30 -
    public function getAlias()
33 +
    public function getAlias(): string
31 34
    {
32 35
        return $this->alias;
33 36
    }
34 37
35 -
    /** @return string|null */
36 -
    public function getIndexBy()
38 +
    public function getIndexBy(): string|null
37 39
    {
38 40
        return $this->indexBy;
39 41
    }
40 42
41 -
    /** @return string */
42 -
    public function __toString()
43 +
    public function __toString(): string
43 44
    {
44 45
        return $this->from . ' ' . $this->alias .
45 46
                ($this->indexBy ? ' INDEX BY ' . $this->indexBy : '');

@@ -36,7 +36,7 @@
Loading
36 36
     *                                                                  but requires at least one defined
37 37
     *                                                                  when converting to string.
38 38
     */
39 -
    public function andX(...$x): Expr\Andx
39 +
    public function andX(Expr\Comparison|Expr\Func|Expr\Andx|Expr\Orx|string ...$x): Expr\Andx
40 40
    {
41 41
        return new Expr\Andx($x);
42 42
    }
@@ -54,31 +54,23 @@
Loading
54 54
     *                                                                  but requires at least one defined
55 55
     *                                                                  when converting to string.
56 56
     */
57 -
    public function orX(...$x): Expr\Orx
57 +
    public function orX(Expr\Comparison|Expr\Func|Expr\Andx|Expr\Orx|string ...$x): Expr\Orx
58 58
    {
59 59
        return new Expr\Orx($x);
60 60
    }
61 61
62 62
    /**
63 63
     * Creates an ASCending order expression.
64 -
     *
65 -
     * @param mixed $expr
66 -
     *
67 -
     * @return Expr\OrderBy
68 64
     */
69 -
    public function asc($expr)
65 +
    public function asc(mixed $expr): Expr\OrderBy
70 66
    {
71 67
        return new Expr\OrderBy($expr, 'ASC');
72 68
    }
73 69
74 70
    /**
75 71
     * Creates a DESCending order expression.
76 -
     *
77 -
     * @param mixed $expr
78 -
     *
79 -
     * @return Expr\OrderBy
80 72
     */
81 -
    public function desc($expr)
73 +
    public function desc(mixed $expr): Expr\OrderBy
82 74
    {
83 75
        return new Expr\OrderBy($expr, 'DESC');
84 76
    }
@@ -95,10 +87,8 @@
Loading
95 87
     *
96 88
     * @param mixed $x Left expression.
97 89
     * @param mixed $y Right expression.
98 -
     *
99 -
     * @return Expr\Comparison
100 90
     */
101 -
    public function eq($x, $y)
91 +
    public function eq(mixed $x, mixed $y): Expr\Comparison
102 92
    {
103 93
        return new Expr\Comparison($x, Expr\Comparison::EQ, $y);
104 94
    }
@@ -114,10 +104,8 @@
Loading
114 104
     *
115 105
     * @param mixed $x Left expression.
116 106
     * @param mixed $y Right expression.
117 -
     *
118 -
     * @return Expr\Comparison
119 107
     */
120 -
    public function neq($x, $y)
108 +
    public function neq(mixed $x, mixed $y): Expr\Comparison
121 109
    {
122 110
        return new Expr\Comparison($x, Expr\Comparison::NEQ, $y);
123 111
    }
@@ -133,10 +121,8 @@
Loading
133 121
     *
134 122
     * @param mixed $x Left expression.
135 123
     * @param mixed $y Right expression.
136 -
     *
137 -
     * @return Expr\Comparison
138 124
     */
139 -
    public function lt($x, $y)
125 +
    public function lt(mixed $x, mixed $y): Expr\Comparison
140 126
    {
141 127
        return new Expr\Comparison($x, Expr\Comparison::LT, $y);
142 128
    }
@@ -152,10 +138,8 @@
Loading
152 138
     *
153 139
     * @param mixed $x Left expression.
154 140
     * @param mixed $y Right expression.
155 -
     *
156 -
     * @return Expr\Comparison
157 141
     */
158 -
    public function lte($x, $y)
142 +
    public function lte(mixed $x, mixed $y): Expr\Comparison
159 143
    {
160 144
        return new Expr\Comparison($x, Expr\Comparison::LTE, $y);
161 145
    }
@@ -171,10 +155,8 @@
Loading
171 155
     *
172 156
     * @param mixed $x Left expression.
173 157
     * @param mixed $y Right expression.
174 -
     *
175 -
     * @return Expr\Comparison
176 158
     */
177 -
    public function gt($x, $y)
159 +
    public function gt(mixed $x, mixed $y): Expr\Comparison
178 160
    {
179 161
        return new Expr\Comparison($x, Expr\Comparison::GT, $y);
180 162
    }
@@ -190,10 +172,8 @@
Loading
190 172
     *
191 173
     * @param mixed $x Left expression.
192 174
     * @param mixed $y Right expression.
193 -
     *
194 -
     * @return Expr\Comparison
195 175
     */
196 -
    public function gte($x, $y)
176 +
    public function gte(mixed $x, mixed $y): Expr\Comparison
197 177
    {
198 178
        return new Expr\Comparison($x, Expr\Comparison::GTE, $y);
199 179
    }
@@ -202,10 +182,8 @@
Loading
202 182
     * Creates an instance of AVG() function, with the given argument.
203 183
     *
204 184
     * @param mixed $x Argument to be used in AVG() function.
205 -
     *
206 -
     * @return Expr\Func
207 185
     */
208 -
    public function avg($x)
186 +
    public function avg(mixed $x): Expr\Func
209 187
    {
210 188
        return new Expr\Func('AVG', [$x]);
211 189
    }
@@ -214,10 +192,8 @@
Loading
214 192
     * Creates an instance of MAX() function, with the given argument.
215 193
     *
216 194
     * @param mixed $x Argument to be used in MAX() function.
217 -
     *
218 -
     * @return Expr\Func
219 195
     */
220 -
    public function max($x)
196 +
    public function max(mixed $x): Expr\Func
221 197
    {
222 198
        return new Expr\Func('MAX', [$x]);
223 199
    }
@@ -226,10 +202,8 @@
Loading
226 202
     * Creates an instance of MIN() function, with the given argument.
227 203
     *
228 204
     * @param mixed $x Argument to be used in MIN() function.
229 -
     *
230 -
     * @return Expr\Func
231 205
     */
232 -
    public function min($x)
206 +
    public function min(mixed $x): Expr\Func
233 207
    {
234 208
        return new Expr\Func('MIN', [$x]);
235 209
    }
@@ -238,10 +212,8 @@
Loading
238 212
     * Creates an instance of COUNT() function, with the given argument.
239 213
     *
240 214
     * @param mixed $x Argument to be used in COUNT() function.
241 -
     *
242 -
     * @return Expr\Func
243 215
     */
244 -
    public function count($x)
216 +
    public function count(mixed $x): Expr\Func
245 217
    {
246 218
        return new Expr\Func('COUNT', [$x]);
247 219
    }
@@ -250,10 +222,8 @@
Loading
250 222
     * Creates an instance of COUNT(DISTINCT) function, with the given argument.
251 223
     *
252 224
     * @param mixed ...$x Argument to be used in COUNT(DISTINCT) function.
253 -
     *
254 -
     * @return string
255 225
     */
256 -
    public function countDistinct(mixed ...$x)
226 +
    public function countDistinct(mixed ...$x): string
257 227
    {
258 228
        return 'COUNT(DISTINCT ' . implode(', ', $x) . ')';
259 229
    }
@@ -262,10 +232,8 @@
Loading
262 232
     * Creates an instance of EXISTS() function, with the given DQL Subquery.
263 233
     *
264 234
     * @param mixed $subquery DQL Subquery to be used in EXISTS() function.
265 -
     *
266 -
     * @return Expr\Func
267 235
     */
268 -
    public function exists($subquery)
236 +
    public function exists(mixed $subquery): Expr\Func
269 237
    {
270 238
        return new Expr\Func('EXISTS', [$subquery]);
271 239
    }
@@ -274,10 +242,8 @@
Loading
274 242
     * Creates an instance of ALL() function, with the given DQL Subquery.
275 243
     *
276 244
     * @param mixed $subquery DQL Subquery to be used in ALL() function.
277 -
     *
278 -
     * @return Expr\Func
279 245
     */
280 -
    public function all($subquery)
246 +
    public function all(mixed $subquery): Expr\Func
281 247
    {
282 248
        return new Expr\Func('ALL', [$subquery]);
283 249
    }
@@ -286,10 +252,8 @@
Loading
286 252
     * Creates a SOME() function expression with the given DQL subquery.
287 253
     *
288 254
     * @param mixed $subquery DQL Subquery to be used in SOME() function.
289 -
     *
290 -
     * @return Expr\Func
291 255
     */
292 -
    public function some($subquery)
256 +
    public function some(mixed $subquery): Expr\Func
293 257
    {
294 258
        return new Expr\Func('SOME', [$subquery]);
295 259
    }
@@ -298,10 +262,8 @@
Loading
298 262
     * Creates an ANY() function expression with the given DQL subquery.
299 263
     *
300 264
     * @param mixed $subquery DQL Subquery to be used in ANY() function.
301 -
     *
302 -
     * @return Expr\Func
303 265
     */
304 -
    public function any($subquery)
266 +
    public function any(mixed $subquery): Expr\Func
305 267
    {
306 268
        return new Expr\Func('ANY', [$subquery]);
307 269
    }
@@ -310,10 +272,8 @@
Loading
310 272
     * Creates a negation expression of the given restriction.
311 273
     *
312 274
     * @param mixed $restriction Restriction to be used in NOT() function.
313 -
     *
314 -
     * @return Expr\Func
315 275
     */
316 -
    public function not($restriction)
276 +
    public function not(mixed $restriction): Expr\Func
317 277
    {
318 278
        return new Expr\Func('NOT', [$restriction]);
319 279
    }
@@ -322,21 +282,16 @@
Loading
322 282
     * Creates an ABS() function expression with the given argument.
323 283
     *
324 284
     * @param mixed $x Argument to be used in ABS() function.
325 -
     *
326 -
     * @return Expr\Func
327 285
     */
328 -
    public function abs($x)
286 +
    public function abs(mixed $x): Expr\Func
329 287
    {
330 288
        return new Expr\Func('ABS', [$x]);
331 289
    }
332 290
333 291
    /**
334 292
     * Creates a MOD($x, $y) function expression to return the remainder of $x divided by $y.
335 -
     *
336 -
     * @param mixed $x
337 -
     * @param mixed $y
338 293
     */
339 -
    public function mod($x, $y): Expr\Func
294 +
    public function mod(mixed $x, mixed $y): Expr\Func
340 295
    {
341 296
        return new Expr\Func('MOD', [$x, $y]);
342 297
    }
@@ -353,10 +308,8 @@
Loading
353 308
     *
354 309
     * @param mixed $x Left expression.
355 310
     * @param mixed $y Right expression.
356 -
     *
357 -
     * @return Expr\Math
358 311
     */
359 -
    public function prod($x, $y)
312 +
    public function prod(mixed $x, mixed $y): Expr\Math
360 313
    {
361 314
        return new Expr\Math($x, '*', $y);
362 315
    }
@@ -372,10 +325,8 @@
Loading
372 325
     *
373 326
     * @param mixed $x Left expression.
374 327
     * @param mixed $y Right expression.
375 -
     *
376 -
     * @return Expr\Math
377 328
     */
378 -
    public function diff($x, $y)
329 +
    public function diff(mixed $x, mixed $y): Expr\Math
379 330
    {
380 331
        return new Expr\Math($x, '-', $y);
381 332
    }
@@ -391,10 +342,8 @@
Loading
391 342
     *
392 343
     * @param mixed $x Left expression.
393 344
     * @param mixed $y Right expression.
394 -
     *
395 -
     * @return Expr\Math
396 345
     */
397 -
    public function sum($x, $y)
346 +
    public function sum(mixed $x, mixed $y): Expr\Math
398 347
    {
399 348
        return new Expr\Math($x, '+', $y);
400 349
    }
@@ -410,10 +359,8 @@
Loading
410 359
     *
411 360
     * @param mixed $x Left expression.
412 361
     * @param mixed $y Right expression.
413 -
     *
414 -
     * @return Expr\Math
415 362
     */
416 -
    public function quot($x, $y)
363 +
    public function quot(mixed $x, mixed $y): Expr\Math
417 364
    {
418 365
        return new Expr\Math($x, '/', $y);
419 366
    }
@@ -422,10 +369,8 @@
Loading
422 369
     * Creates a SQRT() function expression with the given argument.
423 370
     *
424 371
     * @param mixed $x Argument to be used in SQRT() function.
425 -
     *
426 -
     * @return Expr\Func
427 372
     */
428 -
    public function sqrt($x)
373 +
    public function sqrt(mixed $x): Expr\Func
429 374
    {
430 375
        return new Expr\Func('SQRT', [$x]);
431 376
    }
@@ -435,10 +380,8 @@
Loading
435 380
     *
436 381
     * @param string $x Field in string format to be restricted by IN() function.
437 382
     * @param mixed  $y Argument to be used in IN() function.
438 -
     *
439 -
     * @return Expr\Func
440 383
     */
441 -
    public function in($x, $y)
384 +
    public function in(string $x, mixed $y): Expr\Func
442 385
    {
443 386
        if (is_iterable($y)) {
444 387
            if ($y instanceof Traversable) {
@@ -460,10 +403,8 @@
Loading
460 403
     *
461 404
     * @param string $x Field in string format to be restricted by NOT IN() function.
462 405
     * @param mixed  $y Argument to be used in NOT IN() function.
463 -
     *
464 -
     * @return Expr\Func
465 406
     */
466 -
    public function notIn($x, $y)
407 +
    public function notIn(string $x, mixed $y): Expr\Func
467 408
    {
468 409
        if (is_iterable($y)) {
469 410
            if ($y instanceof Traversable) {
@@ -484,10 +425,8 @@
Loading
484 425
     * Creates an IS NULL expression with the given arguments.
485 426
     *
486 427
     * @param string $x Field in string format to be restricted by IS NULL.
487 -
     *
488 -
     * @return string
489 428
     */
490 -
    public function isNull($x)
429 +
    public function isNull(string $x): string
491 430
    {
492 431
        return $x . ' IS NULL';
493 432
    }
@@ -496,10 +435,8 @@
Loading
496 435
     * Creates an IS NOT NULL expression with the given arguments.
497 436
     *
498 437
     * @param string $x Field in string format to be restricted by IS NOT NULL.
499 -
     *
500 -
     * @return string
501 438
     */
502 -
    public function isNotNull($x)
439 +
    public function isNotNull(string $x): string
503 440
    {
504 441
        return $x . ' IS NOT NULL';
505 442
    }
@@ -509,10 +446,8 @@
Loading
509 446
     *
510 447
     * @param string $x Field in string format to be inspected by LIKE() comparison.
511 448
     * @param mixed  $y Argument to be used in LIKE() comparison.
512 -
     *
513 -
     * @return Expr\Comparison
514 449
     */
515 -
    public function like($x, $y)
450 +
    public function like(string $x, mixed $y): Expr\Comparison
516 451
    {
517 452
        return new Expr\Comparison($x, 'LIKE', $y);
518 453
    }
@@ -522,10 +457,8 @@
Loading
522 457
     *
523 458
     * @param string $x Field in string format to be inspected by LIKE() comparison.
524 459
     * @param mixed  $y Argument to be used in LIKE() comparison.
525 -
     *
526 -
     * @return Expr\Comparison
527 460
     */
528 -
    public function notLike($x, $y)
461 +
    public function notLike(string $x, mixed $y): Expr\Comparison
529 462
    {
530 463
        return new Expr\Comparison($x, 'NOT LIKE', $y);
531 464
    }
@@ -534,10 +467,8 @@
Loading
534 467
     * Creates a CONCAT() function expression with the given arguments.
535 468
     *
536 469
     * @param mixed ...$x Arguments to be used in CONCAT() function.
537 -
     *
538 -
     * @return Expr\Func
539 470
     */
540 -
    public function concat(mixed ...$x)
471 +
    public function concat(mixed ...$x): Expr\Func
541 472
    {
542 473
        return new Expr\Func('CONCAT', $x);
543 474
    }
@@ -548,10 +479,8 @@
Loading
548 479
     * @param mixed    $x    Argument to be used as string to be cropped by SUBSTRING() function.
549 480
     * @param int      $from Initial offset to start cropping string. May accept negative values.
550 481
     * @param int|null $len  Length of crop. May accept negative values.
551 -
     *
552 -
     * @return Expr\Func
553 482
     */
554 -
    public function substring($x, $from, $len = null)
483 +
    public function substring(mixed $x, int $from, $len = null): Expr\Func
555 484
    {
556 485
        $args = [$x, $from];
557 486
        if ($len !== null) {
@@ -568,7 +497,7 @@
Loading
568 497
     *
569 498
     * @return Expr\Func A LOWER function expression.
570 499
     */
571 -
    public function lower($x)
500 +
    public function lower(mixed $x): Expr\Func
572 501
    {
573 502
        return new Expr\Func('LOWER', [$x]);
574 503
    }
@@ -580,7 +509,7 @@
Loading
580 509
     *
581 510
     * @return Expr\Func An UPPER function expression.
582 511
     */
583 -
    public function upper($x)
512 +
    public function upper(mixed $x): Expr\Func
584 513
    {
585 514
        return new Expr\Func('UPPER', [$x]);
586 515
    }
@@ -592,7 +521,7 @@
Loading
592 521
     *
593 522
     * @return Expr\Func A LENGTH function expression.
594 523
     */
595 -
    public function length($x)
524 +
    public function length(mixed $x): Expr\Func
596 525
    {
597 526
        return new Expr\Func('LENGTH', [$x]);
598 527
    }
@@ -601,10 +530,8 @@
Loading
601 530
     * Creates a literal expression of the given argument.
602 531
     *
603 532
     * @param scalar $literal Argument to be converted to literal.
604 -
     *
605 -
     * @return Expr\Literal
606 533
     */
607 -
    public function literal($literal)
534 +
    public function literal(mixed $literal): Expr\Literal
608 535
    {
609 536
        return new Expr\Literal($this->quoteLiteral($literal));
610 537
    }
@@ -614,7 +541,7 @@
Loading
614 541
     *
615 542
     * @param scalar $literal The literal value.
616 543
     */
617 -
    private function quoteLiteral($literal): string
544 +
    private function quoteLiteral(mixed $literal): string
618 545
    {
619 546
        if (is_int($literal) || is_float($literal)) {
620 547
            return (string) $literal;
@@ -636,7 +563,7 @@
Loading
636 563
     *
637 564
     * @return string A BETWEEN expression.
638 565
     */
639 -
    public function between($val, $x, $y)
566 +
    public function between(mixed $val, int|string $x, int|string $y): string
640 567
    {
641 568
        return $val . ' BETWEEN ' . $x . ' AND ' . $y;
642 569
    }
@@ -648,7 +575,7 @@
Loading
648 575
     *
649 576
     * @return Expr\Func a TRIM expression.
650 577
     */
651 -
    public function trim($x)
578 +
    public function trim(mixed $x): Expr\Func
652 579
    {
653 580
        return new Expr\Func('TRIM', $x);
654 581
    }
@@ -658,10 +585,8 @@
Loading
658 585
     *
659 586
     * @param string $x Value to be checked
660 587
     * @param string $y Value to be checked against
661 -
     *
662 -
     * @return Expr\Comparison
663 588
     */
664 -
    public function isMemberOf($x, $y)
589 +
    public function isMemberOf(string $x, string $y): Expr\Comparison
665 590
    {
666 591
        return new Expr\Comparison($x, 'MEMBER OF', $y);
667 592
    }
@@ -671,10 +596,8 @@
Loading
671 596
     *
672 597
     * @param string $x Value to be checked
673 598
     * @param string $y Value to be checked against
674 -
     *
675 -
     * @return Expr\Comparison
676 599
     */
677 -
    public function isInstanceOf($x, $y)
600 +
    public function isInstanceOf(string $x, string $y): Expr\Comparison
678 601
    {
679 602
        return new Expr\Comparison($x, 'INSTANCE OF', $y);
680 603
    }

@@ -4,6 +4,8 @@
Loading
4 4
5 5
namespace Doctrine\ORM\Query\Expr;
6 6
7 +
use Stringable;
8 +
7 9
use function count;
8 10
use function implode;
9 11
@@ -12,63 +14,46 @@
Loading
12 14
 *
13 15
 * @link    www.doctrine-project.org
14 16
 */
15 -
class OrderBy
17 +
class OrderBy implements Stringable
16 18
{
17 -
    /** @var string */
18 -
    protected $preSeparator = '';
19 -
20 -
    /** @var string */
21 -
    protected $separator = ', ';
22 -
23 -
    /** @var string */
24 -
    protected $postSeparator = '';
19 +
    protected string $preSeparator  = '';
20 +
    protected string $separator     = ', ';
21 +
    protected string $postSeparator = '';
25 22
26 23
    /** @var string[] */
27 -
    protected $allowedClasses = [];
24 +
    protected array $allowedClasses = [];
28 25
29 26
    /** @psalm-var list<string> */
30 -
    protected $parts = [];
27 +
    protected array $parts = [];
31 28
32 -
    /**
33 -
     * @param string|null $sort
34 -
     * @param string|null $order
35 -
     */
36 -
    public function __construct($sort = null, $order = null)
37 -
    {
29 +
    public function __construct(
30 +
        string|null $sort = null,
31 +
        string|null $order = null,
32 +
    ) {
38 33
        if ($sort) {
39 34
            $this->add($sort, $order);
40 35
        }
41 36
    }
42 37
43 -
    /**
44 -
     * @param string      $sort
45 -
     * @param string|null $order
46 -
     *
47 -
     * @return void
48 -
     */
49 -
    public function add($sort, $order = null)
38 +
    public function add(string $sort, string|null $order = null): void
50 39
    {
51 40
        $order         = ! $order ? 'ASC' : $order;
52 41
        $this->parts[] = $sort . ' ' . $order;
53 42
    }
54 43
55 -
    /**
56 -
     * @return int
57 -
     * @psalm-return 0|positive-int
58 -
     */
59 -
    public function count()
44 +
    /** @psalm-return 0|positive-int */
45 +
    public function count(): int
60 46
    {
61 47
        return count($this->parts);
62 48
    }
63 49
64 50
    /** @psalm-return list<string> */
65 -
    public function getParts()
51 +
    public function getParts(): array
66 52
    {
67 53
        return $this->parts;
68 54
    }
69 55
70 -
    /** @return string */
71 -
    public function __toString()
56 +
    public function __toString(): string
72 57
    {
73 58
        return $this->preSeparator . implode($this->separator, $this->parts) . $this->postSeparator;
74 59
    }

@@ -11,17 +11,14 @@
Loading
11 11
 */
12 12
class Literal extends Base
13 13
{
14 -
    /** @var string */
15 -
    protected $preSeparator = '';
16 -
17 -
    /** @var string */
18 -
    protected $postSeparator = '';
14 +
    protected string $preSeparator  = '';
15 +
    protected string $postSeparator = '';
19 16
20 17
    /** @psalm-var list<string> */
21 -
    protected $parts = [];
18 +
    protected array $parts = [];
22 19
23 20
    /** @psalm-return list<string> */
24 -
    public function getParts()
21 +
    public function getParts(): array
25 22
    {
26 23
        return $this->parts;
27 24
    }

@@ -8,7 +8,6 @@
Loading
8 8
use Stringable;
9 9
10 10
use function count;
11 -
use function get_class;
12 11
use function get_debug_type;
13 12
use function implode;
14 13
use function in_array;
@@ -20,25 +19,19 @@
Loading
20 19
 *
21 20
 * @link    www.doctrine-project.org
22 21
 */
23 -
abstract class Base
22 +
abstract class Base implements Stringable
24 23
{
25 -
    /** @var string */
26 -
    protected $preSeparator = '(';
27 -
28 -
    /** @var string */
29 -
    protected $separator = ', ';
30 -
31 -
    /** @var string */
32 -
    protected $postSeparator = ')';
24 +
    protected string $preSeparator  = '(';
25 +
    protected string $separator     = ', ';
26 +
    protected string $postSeparator = ')';
33 27
34 28
    /** @var list<class-string> */
35 -
    protected $allowedClasses = [];
29 +
    protected array $allowedClasses = [];
36 30
37 31
    /** @var list<string|Stringable> */
38 -
    protected $parts = [];
32 +
    protected array $parts = [];
39 33
40 -
    /** @param mixed $args */
41 -
    public function __construct($args = [])
34 +
    public function __construct(mixed $args = [])
42 35
    {
43 36
        $this->addMultiple($args);
44 37
    }
@@ -49,7 +42,7 @@
Loading
49 42
     *
50 43
     * @return $this
51 44
     */
52 -
    public function addMultiple($args = [])
45 +
    public function addMultiple($args = []): static
53 46
    {
54 47
        foreach ((array) $args as $arg) {
55 48
            $this->add($arg);
@@ -59,17 +52,15 @@
Loading
59 52
    }
60 53
61 54
    /**
62 -
     * @param mixed $arg
63 -
     *
64 55
     * @return $this
65 56
     *
66 57
     * @throws InvalidArgumentException
67 58
     */
68 -
    public function add($arg)
59 +
    public function add(mixed $arg): static
69 60
    {
70 61
        if ($arg !== null && (! $arg instanceof self || $arg->count() > 0)) {
71 62
            // If we decide to keep Expr\Base instances, we can use this check
72 -
            if (! is_string($arg) && ! in_array(get_class($arg), $this->allowedClasses, true)) {
63 +
            if (! is_string($arg) && ! in_array($arg::class, $this->allowedClasses, true)) {
73 64
                throw new InvalidArgumentException(sprintf(
74 65
                    "Expression of type '%s' not allowed in this context.",
75 66
                    get_debug_type($arg),
@@ -82,17 +73,13 @@
Loading
82 73
        return $this;
83 74
    }
84 75
85 -
    /**
86 -
     * @return int
87 -
     * @psalm-return 0|positive-int
88 -
     */
89 -
    public function count()
76 +
    /** @psalm-return 0|positive-int */
77 +
    public function count(): int
90 78
    {
91 79
        return count($this->parts);
92 80
    }
93 81
94 -
    /** @return string */
95 -
    public function __toString()
82 +
    public function __toString(): string
96 83
    {
97 84
        if ($this->count() === 1) {
98 85
            return (string) $this->parts[0];

@@ -4,6 +4,8 @@
Loading
4 4
5 5
namespace Doctrine\ORM\Query\Expr;
6 6
7 +
use Stringable;
8 +
7 9
use function implode;
8 10
use function is_object;
9 11
use function preg_match;
@@ -15,8 +17,7 @@
Loading
15 17
 */
16 18
class Composite extends Base
17 19
{
18 -
    /** @return string */
19 -
    public function __toString()
20 +
    public function __toString(): string
20 21
    {
21 22
        if ($this->count() === 1) {
22 23
            return (string) $this->parts[0];
@@ -31,8 +32,7 @@
Loading
31 32
        return implode($this->separator, $components);
32 33
    }
33 34
34 -
    /** @param string|object $part */
35 -
    private function processQueryPart($part): string
35 +
    private function processQueryPart(string|Stringable $part): string
36 36
    {
37 37
        $queryPart = (string) $part;
38 38

@@ -11,11 +11,10 @@
Loading
11 11
 */
12 12
class Andx extends Composite
13 13
{
14 -
    /** @var string */
15 -
    protected $separator = ' AND ';
14 +
    protected string $separator = ' AND ';
16 15
17 16
    /** @var string[] */
18 -
    protected $allowedClasses = [
17 +
    protected array $allowedClasses = [
19 18
        Comparison::class,
20 19
        Func::class,
21 20
        Orx::class,
@@ -23,10 +22,10 @@
Loading
23 22
    ];
24 23
25 24
    /** @psalm-var list<string|Comparison|Func|Orx|self> */
26 -
    protected $parts = [];
25 +
    protected array $parts = [];
27 26
28 27
    /** @psalm-return list<string|Comparison|Func|Orx|self> */
29 -
    public function getParts()
28 +
    public function getParts(): array
30 29
    {
31 30
        return $this->parts;
32 31
    }

@@ -11,17 +11,14 @@
Loading
11 11
 */
12 12
class GroupBy extends Base
13 13
{
14 -
    /** @var string */
15 -
    protected $preSeparator = '';
16 -
17 -
    /** @var string */
18 -
    protected $postSeparator = '';
14 +
    protected string $preSeparator  = '';
15 +
    protected string $postSeparator = '';
19 16
20 17
    /** @psalm-var list<string> */
21 -
    protected $parts = [];
18 +
    protected array $parts = [];
22 19
23 20
    /** @psalm-return list<string> */
24 -
    public function getParts()
21 +
    public function getParts(): array
25 22
    {
26 23
        return $this->parts;
27 24
    }

@@ -11,11 +11,10 @@
Loading
11 11
 */
12 12
class Orx extends Composite
13 13
{
14 -
    /** @var string */
15 -
    protected $separator = ' OR ';
14 +
    protected string $separator = ' OR ';
16 15
17 16
    /** @var string[] */
18 -
    protected $allowedClasses = [
17 +
    protected array $allowedClasses = [
19 18
        Comparison::class,
20 19
        Func::class,
21 20
        Andx::class,
@@ -23,10 +22,10 @@
Loading
23 22
    ];
24 23
25 24
    /** @psalm-var list<string|Comparison|Func|Andx|self> */
26 -
    protected $parts = [];
25 +
    protected array $parts = [];
27 26
28 27
    /** @psalm-return list<string|Comparison|Func|Andx|self> */
29 -
    public function getParts()
28 +
    public function getParts(): array
30 29
    {
31 30
        return $this->parts;
32 31
    }

@@ -4,44 +4,41 @@
Loading
4 4
5 5
namespace Doctrine\ORM\Query\Expr;
6 6
7 +
use Stringable;
8 +
7 9
/**
8 10
 * Expression class for DQL math statements.
9 11
 *
10 12
 * @link    www.doctrine-project.org
11 13
 */
12 -
class Math
14 +
class Math implements Stringable
13 15
{
14 16
    /**
15 17
     * Creates a mathematical expression with the given arguments.
16 -
     *
17 -
     * @param mixed  $leftExpr
18 -
     * @param string $operator
19 -
     * @param mixed  $rightExpr
20 18
     */
21 -
    public function __construct(protected $leftExpr, protected $operator, protected $rightExpr)
22 -
    {
19 +
    public function __construct(
20 +
        protected mixed $leftExpr,
21 +
        protected string $operator,
22 +
        protected mixed $rightExpr,
23 +
    ) {
23 24
    }
24 25
25 -
    /** @return mixed */
26 -
    public function getLeftExpr()
26 +
    public function getLeftExpr(): mixed
27 27
    {
28 28
        return $this->leftExpr;
29 29
    }
30 30
31 -
    /** @return string */
32 -
    public function getOperator()
31 +
    public function getOperator(): string
33 32
    {
34 33
        return $this->operator;
35 34
    }
36 35
37 -
    /** @return mixed */
38 -
    public function getRightExpr()
36 +
    public function getRightExpr(): mixed
39 37
    {
40 38
        return $this->rightExpr;
41 39
    }
42 40
43 -
    /** @return string */
44 -
    public function __toString()
41 +
    public function __toString(): string
45 42
    {
46 43
        // Adjusting Left Expression
47 44
        $leftExpr = (string) $this->leftExpr;
Files Coverage
lib/Doctrine/ORM 89.64%
Project Totals (330 files) 89.64%

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