diff --git a/mailpoet/lib/Subscribers/SubscribersEmailCountsController.php b/mailpoet/lib/Subscribers/SubscribersEmailCountsController.php index 9b044bfced..f897fad5f3 100644 --- a/mailpoet/lib/Subscribers/SubscribersEmailCountsController.php +++ b/mailpoet/lib/Subscribers/SubscribersEmailCountsController.php @@ -107,10 +107,12 @@ class SubscribersEmailCountsController { private function countAndMaxOfSubscribersInRange(int $startId, int $batchSize): array { $result = $this->entityManager->getConnection()->executeQuery(" - SELECT s.id FROM {$this->subscribersTable} as s - WHERE s.id >= :startId - ORDER BY s.id - LIMIT :batchSize + SELECT COUNT(ids.id) as count, COALESCE(MAX(ids.id), 0) as max FROM ( + SELECT s.id FROM {$this->subscribersTable} as s + WHERE s.id >= :startId + ORDER BY s.id + LIMIT :batchSize + ) ids ", [ 'startId' => $startId, @@ -124,16 +126,6 @@ class SubscribersEmailCountsController { $subscribersInRange = $result->fetchAllAssociative(); - $countSubscribersInRange = count(array_map( - function ($id) { - return (int)$id['id']; - }, - $subscribersInRange - )); - - if (!$countSubscribersInRange) { - return [0,0]; - } - return [$countSubscribersInRange,$subscribersInRange[$countSubscribersInRange - 1]['id']]; + return [$subscribersInRange[0]['count'], $subscribersInRange[0]['max']]; } } diff --git a/mailpoet/tasks/phpstan/phpstan-7-baseline.neon b/mailpoet/tasks/phpstan/phpstan-7-baseline.neon index 80c3270b7f..bb6b68b4cb 100644 --- a/mailpoet/tasks/phpstan/phpstan-7-baseline.neon +++ b/mailpoet/tasks/phpstan/phpstan-7-baseline.neon @@ -1106,11 +1106,6 @@ parameters: count: 2 path: ../../lib/Subscribers/InactiveSubscribersController.php - - - message: "#^Cannot cast mixed to int\\.$#" - count: 1 - path: ../../lib/Subscribers/SubscribersEmailCountsController.php - - message: "#^Cannot cast mixed to int\\.$#" count: 3 diff --git a/mailpoet/tasks/phpstan/phpstan-8-baseline.neon b/mailpoet/tasks/phpstan/phpstan-8-baseline.neon index 7379d5f5b0..b693bcf63a 100644 --- a/mailpoet/tasks/phpstan/phpstan-8-baseline.neon +++ b/mailpoet/tasks/phpstan/phpstan-8-baseline.neon @@ -1106,11 +1106,6 @@ parameters: count: 2 path: ../../lib/Subscribers/InactiveSubscribersController.php - - - message: "#^Cannot cast mixed to int\\.$#" - count: 1 - path: ../../lib/Subscribers/SubscribersEmailCountsController.php - - message: "#^Cannot cast mixed to int\\.$#" count: 3