@@ -153,43 +153,11 @@ public function query(Query $query): iterable
153
153
->from ($ this ->table );
154
154
155
155
/**
156
- * @phpstan-var array<string, array<int, int|string> > $queryParameters
157
- * @phpstan-var array<string, int> $queryTypes
156
+ * @phpstan-var array<string, mixed > $queryParameters
157
+ * @phpstan-var array<string, string| int> $queryTypes
158
158
*/
159
159
[$ queryParameters , $ queryTypes ] = $ this ->addWheres ($ query , $ qb );
160
160
161
- if ($ query ->startTime ()) {
162
- $ qb ->andWhere ($ qb ->expr ()->isNotNull ('start_time ' ));
163
- }
164
- $ startDateFrom = $ query ->startTime ()?->getFrom();
165
- if ($ startDateFrom ) {
166
- $ qb ->andWhere ($ qb ->expr ()->gte ('start_time ' , ':startDateFrom ' ));
167
- $ queryParameters ['startDateFrom ' ] = $ startDateFrom ;
168
- $ queryTypes ['startDateFrom ' ] = Types::DATETIME_IMMUTABLE ;
169
- }
170
- $ startDateTo = $ query ->startTime ()?->getTo();
171
- if ($ startDateTo ) {
172
- $ qb ->andWhere ($ qb ->expr ()->lte ('start_time ' , ':startDateTo ' ));
173
- $ queryParameters ['startDateTo ' ] = $ startDateTo ;
174
- $ queryTypes ['startDateTo ' ] = Types::DATETIME_IMMUTABLE ;
175
- }
176
-
177
- if ($ query ->endTime ()) {
178
- $ qb ->andWhere ($ qb ->expr ()->isNotNull ('start_time ' ));
179
- }
180
- $ endDateFrom = $ query ->endTime ()?->getFrom();
181
- if ($ endDateFrom ) {
182
- $ qb ->andWhere ($ qb ->expr ()->gte ('end_time ' , ':endDateFrom ' ));
183
- $ queryParameters ['endDateFrom ' ] = $ endDateFrom ;
184
- $ queryTypes ['endDateFrom ' ] = Types::DATETIME_IMMUTABLE ;
185
- }
186
- $ endDateTo = $ query ->endTime ()?->getTo();
187
- if ($ endDateTo ) {
188
- $ qb ->andWhere ($ qb ->expr ()->lte ('end_time ' , ':endDateTo ' ));
189
- $ queryParameters ['endDateTo ' ] = $ endDateTo ;
190
- $ queryTypes ['endDateTo ' ] = Types::DATETIME_IMMUTABLE ;
191
- }
192
-
193
161
switch ($ query ->sort ()) {
194
162
case Query::SORT_BY_START_ASC :
195
163
$ qb ->orderBy ('start_time ' , 'asc ' );
@@ -217,8 +185,14 @@ public function count(Query $query): int
217
185
$ qb ->select ('count(*) ' )
218
186
->from ($ this ->table );
219
187
188
+ /**
189
+ * @phpstan-var array<string, mixed> $queryParameters
190
+ * @phpstan-var array<string, string|int> $queryTypes
191
+ */
192
+ [$ queryParameters , $ queryTypes ] = $ this ->addWheres ($ query , $ qb );
193
+
220
194
/** @var int $result */
221
- $ result = $ this ->connection ->executeQuery ($ qb ->getSQL (), ... $ this -> addWheres ( $ query , $ qb ) )->fetchOne ();
195
+ $ result = $ this ->connection ->executeQuery ($ qb ->getSQL (), $ queryParameters , $ queryTypes )->fetchOne ();
222
196
223
197
return $ result ;
224
198
}
@@ -354,7 +328,7 @@ private function getNormalizer(): JobExecutionRowNormalizer
354
328
}
355
329
356
330
/**
357
- * @return array<int, array<string, array<int| string> |int>>
331
+ * @return array{array<string, mixed>, array<string, string|int>}
358
332
*/
359
333
private function addWheres (Query $ query , QueryBuilder $ qb ): array
360
334
{
@@ -382,6 +356,38 @@ private function addWheres(Query $query, QueryBuilder $qb): array
382
356
$ queryTypes ['statuses ' ] = Connection::PARAM_INT_ARRAY ;
383
357
}
384
358
359
+ if ($ query ->startTime ()) {
360
+ $ qb ->andWhere ($ qb ->expr ()->isNotNull ('start_time ' ));
361
+ }
362
+ $ startDateFrom = $ query ->startTime ()?->getFrom();
363
+ if ($ startDateFrom ) {
364
+ $ qb ->andWhere ($ qb ->expr ()->gte ('start_time ' , ':startDateFrom ' ));
365
+ $ queryParameters ['startDateFrom ' ] = $ startDateFrom ;
366
+ $ queryTypes ['startDateFrom ' ] = Types::DATETIME_IMMUTABLE ;
367
+ }
368
+ $ startDateTo = $ query ->startTime ()?->getTo();
369
+ if ($ startDateTo ) {
370
+ $ qb ->andWhere ($ qb ->expr ()->lte ('start_time ' , ':startDateTo ' ));
371
+ $ queryParameters ['startDateTo ' ] = $ startDateTo ;
372
+ $ queryTypes ['startDateTo ' ] = Types::DATETIME_IMMUTABLE ;
373
+ }
374
+
375
+ if ($ query ->endTime ()) {
376
+ $ qb ->andWhere ($ qb ->expr ()->isNotNull ('start_time ' ));
377
+ }
378
+ $ endDateFrom = $ query ->endTime ()?->getFrom();
379
+ if ($ endDateFrom ) {
380
+ $ qb ->andWhere ($ qb ->expr ()->gte ('end_time ' , ':endDateFrom ' ));
381
+ $ queryParameters ['endDateFrom ' ] = $ endDateFrom ;
382
+ $ queryTypes ['endDateFrom ' ] = Types::DATETIME_IMMUTABLE ;
383
+ }
384
+ $ endDateTo = $ query ->endTime ()?->getTo();
385
+ if ($ endDateTo ) {
386
+ $ qb ->andWhere ($ qb ->expr ()->lte ('end_time ' , ':endDateTo ' ));
387
+ $ queryParameters ['endDateTo ' ] = $ endDateTo ;
388
+ $ queryTypes ['endDateTo ' ] = Types::DATETIME_IMMUTABLE ;
389
+ }
390
+
385
391
return [$ queryParameters , $ queryTypes ];
386
392
}
387
393
}
0 commit comments