From bdeb3a8c54121bc55f80cf247eefa611a12e00ad Mon Sep 17 00:00:00 2001
From: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
Date: Mon, 16 Mar 2026 11:36:53 +0100
Subject: [PATCH] fix(php): refactor int/float conversions
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
---
lib/BackgroundJob/QuotaJob.php | 2 +-
lib/Command/AddMissingTags.php | 3 +-
lib/Command/CreateAccount.php | 2 +-
lib/Command/DiagnoseAccount.php | 3 +-
lib/Command/ExportAccount.php | 9 +++--
lib/Command/Thread.php | 12 ++++---
lib/Db/MessageMapper.php | 2 +-
lib/IMAP/IMAPClientFactory.php | 2 +-
lib/IMAP/MessageMapper.php | 15 ++++----
lib/IMAP/Threading/ThreadBuilder.php | 3 +-
...countSynchronizedThreadUpdaterListener.php | 12 ++++---
...xesSynchronizedSpecialMailboxesUpdater.php | 12 +++----
.../MigrateImportantFromImapAndDb.php | 4 +--
lib/SMTP/SmtpClientFactory.php | 2 +-
.../AiIntegrations/AiIntegrationsService.php | 9 ++---
lib/Service/AntiSpamService.php | 4 +--
.../AutoCompletion/AddressCollector.php | 6 ++--
lib/Service/AutoConfig/MxRecord.php | 3 +-
.../Classification/ImportanceClassifier.php | 18 +++++++---
lib/Service/ItineraryService.php | 10 ++++--
lib/Service/MailManager.php | 2 +-
lib/Service/MailTransmission.php | 6 ++--
lib/Service/PreprocessingService.php | 4 ++-
lib/Service/SetupService.php | 2 +-
lib/Service/Sync/ImapToDbSynchronizer.php | 36 +++++++++----------
lib/SetupChecks/MailConnectionPerformance.php | 10 +++---
lib/Sieve/SieveClientFactory.php | 2 +-
lib/Support/PerformanceLoggerTask.php | 4 +--
lib/functions.php | 2 +-
29 files changed, 118 insertions(+), 83 deletions(-)
diff --git a/lib/BackgroundJob/QuotaJob.php b/lib/BackgroundJob/QuotaJob.php
index e747ad06c4..a067f5057e 100644
--- a/lib/BackgroundJob/QuotaJob.php
+++ b/lib/BackgroundJob/QuotaJob.php
@@ -86,7 +86,7 @@ protected function run($argument): void {
if ($quota->getLimit() === 0) {
$mailAccount->setQuotaPercentage(0);
} else {
- $mailAccount->setQuotaPercentage((int)round($quota->getUsage() / $quota->getLimit() * 100));
+ $mailAccount->setQuotaPercentage((int)round((float)$quota->getUsage() / (float)$quota->getLimit() * 100.0));
}
$this->accountService->update($mailAccount);
$current = $mailAccount->getQuotaPercentage();
diff --git a/lib/Command/AddMissingTags.php b/lib/Command/AddMissingTags.php
index a84c3bb2ab..f6711496ee 100644
--- a/lib/Command/AddMissingTags.php
+++ b/lib/Command/AddMissingTags.php
@@ -73,7 +73,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$progress->finish();
$output->writeln('');
- $output->writeln('Patched default tags for ' . count($accounts));
+ $n = count($accounts);
+ $output->writeln("Patched default tags for $n");
return 0;
}
}
diff --git a/lib/Command/CreateAccount.php b/lib/Command/CreateAccount.php
index af85924309..919fa21efe 100644
--- a/lib/Command/CreateAccount.php
+++ b/lib/Command/CreateAccount.php
@@ -122,7 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$account = $this->accountService->save($account);
- $output->writeln('Account ' . $account->getId() . " for $email created");
+ $output->writeln("Account {$account->getId()} for $email created");
return 0;
}
diff --git a/lib/Command/DiagnoseAccount.php b/lib/Command/DiagnoseAccount.php
index 60a3377b10..ff6e7a354c 100644
--- a/lib/Command/DiagnoseAccount.php
+++ b/lib/Command/DiagnoseAccount.php
@@ -120,6 +120,7 @@ protected function printMailboxesMessagesStats(OutputInterface $output,
$status = $imapClient->status($mb, Horde_Imap_Client::STATUS_MESSAGES);
return $c + $status['messages'];
}, 0);
- $output->writeln('Account has ' . $messages . ' messages in ' . count($mailboxes) . ' mailboxes');
+ $nMailboxes = count($mailboxes);
+ $output->writeln("Account has $messages messages in $nMailboxes mailboxes");
}
}
diff --git a/lib/Command/ExportAccount.php b/lib/Command/ExportAccount.php
index 812bb314f3..ddeb865e3b 100644
--- a/lib/Command/ExportAccount.php
+++ b/lib/Command/ExportAccount.php
@@ -80,14 +80,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln(json_encode($this->getAccountsData($accounts), JSON_PRETTY_PRINT));
} else {
foreach ($accounts as $account) {
- $output->writeln('Account ' . $account->getId() . ':');
+ $accountId = $account->getId();
+ $output->writeln("Account $accountId:");
$output->writeln('- E-Mail: ' . $account->getEmail());
$output->writeln('- Name: ' . $account->getName());
$output->writeln('- Provision: ' . ($account->getMailAccount()->getProvisioningId() ? 'set' : 'none') . ' ID: ' . ($account->getMailAccount()->getProvisioningId() ?: 'N/A'));
$output->writeln('- IMAP user: ' . $account->getMailAccount()->getInboundUser());
- $output->writeln('- IMAP host: ' . $account->getMailAccount()->getInboundHost() . ':' . $account->getMailAccount()->getInboundPort() . ', security: ' . $account->getMailAccount()->getInboundSslMode());
+ $inboundPort = $account->getMailAccount()->getInboundPort();
+ $output->writeln('- IMAP host: ' . $account->getMailAccount()->getInboundHost() . ":$inboundPort, security: " . $account->getMailAccount()->getInboundSslMode());
$output->writeln('- SMTP user: ' . $account->getMailAccount()->getOutboundUser());
- $output->writeln('- SMTP host: ' . $account->getMailAccount()->getOutboundHost() . ':' . $account->getMailAccount()->getOutboundPort() . ', security: ' . $account->getMailAccount()->getOutboundSslMode());
+ $outboundPort = $account->getMailAccount()->getOutboundPort();
+ $output->writeln('- SMTP host: ' . $account->getMailAccount()->getOutboundHost() . ":$outboundPort, security: " . $account->getMailAccount()->getOutboundSslMode());
}
}
diff --git a/lib/Command/Thread.php b/lib/Command/Thread.php
index 5bc60f615f..8531b613e6 100644
--- a/lib/Command/Thread.php
+++ b/lib/Command/Thread.php
@@ -63,9 +63,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('Could not read thread data');
return 2;
}
- $consoleLogger->debug(strlen($json) . 'B read');
+ $nRead = strlen($json);
+ $consoleLogger->debug("{$nRead}B read");
$parsed = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
- $consoleLogger->debug(count($parsed) . ' data sets loaded');
+ $nParsed = count($parsed);
+ $consoleLogger->debug("$nParsed data sets loaded");
$threadData = array_map(static fn ($serialized) => new DatabaseMessage(
$serialized['databaseId'],
$serialized['subject'],
@@ -75,10 +77,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
), $parsed);
$threads = $this->builder->build($threadData, $consoleLogger);
- $output->writeln(count($threads) . ' threads built from ' . count($threadData) . ' messages');
+ $nThreads = count($threads);
+ $nThreadData = count($threadData);
+ $output->writeln("$nThreads threads built from $nThreadData messages");
$mbs = (int)(memory_get_peak_usage() / 1024 / 1024);
- $output->writeln('' . $mbs . 'MB of memory used');
+ $output->writeln("{$mbs}MB of memory used");
return 0;
}
diff --git a/lib/Db/MessageMapper.php b/lib/Db/MessageMapper.php
index 63c961bfd3..ce29c480ed 100644
--- a/lib/Db/MessageMapper.php
+++ b/lib/Db/MessageMapper.php
@@ -371,7 +371,7 @@ public function updateBulk(Account $account, bool $permflagsEnabled, Message ...
$this->db->beginTransaction();
$perf = $this->performanceLogger->start(
- 'partial sync ' . $account->getId() . ':' . $account->getName()
+ "partial sync {$account->getId()}:{$account->getName()}"
);
// MailboxId is the same for all messages according to updateBulk() call
diff --git a/lib/IMAP/IMAPClientFactory.php b/lib/IMAP/IMAPClientFactory.php
index 229d09b641..3ec6bd42d6 100644
--- a/lib/IMAP/IMAPClientFactory.php
+++ b/lib/IMAP/IMAPClientFactory.php
@@ -130,7 +130,7 @@ public function getClient(Account $account, bool $useCache = true): Horde_Imap_C
];
}
if ($account->getMailAccount()->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) {
- $fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-imap.log';
+ $fn = "mail-{$account->getUserId()}-{$account->getId()}-imap.log";
$params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn;
}
diff --git a/lib/IMAP/MessageMapper.php b/lib/IMAP/MessageMapper.php
index 38b7485b8e..158c763b44 100644
--- a/lib/IMAP/MessageMapper.php
+++ b/lib/IMAP/MessageMapper.php
@@ -159,7 +159,7 @@ public function findAll(Horde_Imap_Client_Socket $client,
// Here we assume somewhat equally distributed UIDs
// +1 is added to fetch all messages with the rare case of strictly
// continuous UIDs and fractions
- $estimatedPageSize = (int)(($totalRange / $total) * $maxResults) + 1;
+ $estimatedPageSize = (int)((float)($totalRange / $total) * $maxResults) + 1;
// Determine min UID to fetch, but don't exceed the known maximum
$lower = max(
$min,
@@ -180,20 +180,20 @@ public function findAll(Horde_Imap_Client_Socket $client,
];
}
- $idsToFetch = new Horde_Imap_Client_Ids($lower . ':' . $upper);
+ $idsToFetch = new Horde_Imap_Client_Ids("$lower:$upper");
$actualPageSize = $this->getPageSize($client, $mailbox, $idsToFetch);
$logger->debug("Built range for findAll: min=$min max=$max total=$total totalRange=$totalRange estimatedPageSize=$estimatedPageSize actualPageSize=$actualPageSize lower=$lower upper=$upper highestKnownUid=$highestKnownUid");
while ($actualPageSize > $maxResults) {
$logger->debug("Range for findAll matches too many messages: min=$min max=$max total=$total estimatedPageSize=$estimatedPageSize actualPageSize=$actualPageSize");
- $estimatedPageSize = (int)($estimatedPageSize / 2);
+ $estimatedPageSize = (int)($estimatedPageSize / 2.0);
$upper = min(
$max,
$lower + $estimatedPageSize,
$lower + 1_000_000, // Somewhat sensible number of UIDs that fit into memory (Horde_Imap_ClientId bloat)
);
- $idsToFetch = new Horde_Imap_Client_Ids($lower . ':' . $upper);
+ $idsToFetch = new Horde_Imap_Client_Ids("$lower:$upper");
$actualPageSize = $this->getPageSize($client, $mailbox, $idsToFetch);
}
@@ -304,7 +304,8 @@ public function findByIds(Horde_Imap_Client_Base $client,
$fetchResults = array_values(array_filter($fetchResults, static fn (Horde_Imap_Client_Data_Fetch $fetchResult) => $fetchResult->exists(Horde_Imap_Client::FETCH_ENVELOPE)));
if ($fetchResults === []) {
- $this->logger->debug("findByIds in $mailbox got " . count($ids) . ' UIDs but found none');
+ $nIds = count($ids);
+ $this->logger->debug("findByIds in $mailbox got $nIds UIDs but found none");
} else {
$minFetched = $fetchResults[0]->getUid();
$maxFetched = $fetchResults[count($fetchResults) - 1]->getUid();
@@ -313,7 +314,9 @@ public function findByIds(Horde_Imap_Client_Base $client,
} else {
$range = 'literals';
}
- $this->logger->debug("findByIds in $mailbox got " . count($ids) . " UIDs ($range) and found " . count($fetchResults) . ". minFetched=$minFetched maxFetched=$maxFetched");
+ $nIds = count($ids);
+ $nFetched = count($fetchResults);
+ $this->logger->debug("findByIds in $mailbox got $nIds UIDs ($range) and found $nFetched. minFetched=$minFetched maxFetched=$maxFetched");
}
return array_map(fn (Horde_Imap_Client_Data_Fetch $fetchResult) => $this->imapMessageFactory
diff --git a/lib/IMAP/Threading/ThreadBuilder.php b/lib/IMAP/Threading/ThreadBuilder.php
index abbbc56add..1c649a8806 100644
--- a/lib/IMAP/Threading/ThreadBuilder.php
+++ b/lib/IMAP/Threading/ThreadBuilder.php
@@ -28,8 +28,9 @@ public function __construct(PerformanceLogger $performanceLogger) {
* @return Container[]
*/
public function build(array $messages, LoggerInterface $logger): array {
+ $n = count($messages);
$log = $this->performanceLogger->startWithLogger(
- 'Threading ' . count($messages) . ' messages',
+ "Threading $n messages",
$logger
);
diff --git a/lib/Listener/AccountSynchronizedThreadUpdaterListener.php b/lib/Listener/AccountSynchronizedThreadUpdaterListener.php
index b39d19a809..a74277a702 100644
--- a/lib/Listener/AccountSynchronizedThreadUpdaterListener.php
+++ b/lib/Listener/AccountSynchronizedThreadUpdaterListener.php
@@ -58,16 +58,20 @@ public function handle(Event $event): void {
$accountId = $event->getAccount()->getId();
$logger->debug("Building threads for account $accountId");
$messages = $this->mapper->findThreadingData($event->getAccount());
- $logger->debug("Account $accountId has " . count($messages) . ' messages with threading information');
+ $nMessages = count($messages);
+ $logger->debug("Account $accountId has $nMessages messages with threading information");
$threads = $this->builder->build($messages, $logger);
- $logger->debug("Account $accountId has " . count($threads) . ' threads');
+ $nThreads = count($threads);
+ $logger->debug("Account $accountId has $nThreads threads");
/** @var DatabaseMessage[] $flattened */
$flattened = iterator_to_array($this->flattenThreads($threads), false);
- $logger->debug("Account $accountId has " . count($flattened) . ' messages with a new thread IDs');
+ $nFlattened = count($flattened);
+ $logger->debug("Account $accountId has $nFlattened messages with a new thread IDs");
+ $chunkSize = self::WRITE_IDS_CHUNK_SIZE;
foreach (array_chunk($flattened, self::WRITE_IDS_CHUNK_SIZE) as $chunk) {
$this->mapper->writeThreadIds($chunk);
- $logger->debug('Chunk of ' . self::WRITE_IDS_CHUNK_SIZE . ' messages updated');
+ $logger->debug("Chunk of $chunkSize messages updated");
}
// Free memory
diff --git a/lib/Listener/MailboxesSynchronizedSpecialMailboxesUpdater.php b/lib/Listener/MailboxesSynchronizedSpecialMailboxesUpdater.php
index 02ff43c23e..8237a5f889 100644
--- a/lib/Listener/MailboxesSynchronizedSpecialMailboxesUpdater.php
+++ b/lib/Listener/MailboxesSynchronizedSpecialMailboxesUpdater.php
@@ -62,7 +62,7 @@ public function handle(Event $event): void {
$draftsMailbox = $this->findSpecial($mailboxes, 'drafts');
$mailAccount->setDraftsMailboxId($draftsMailbox->getId());
} catch (DoesNotExistException $e) {
- $this->logger->info('Account ' . $account->getId() . ' does not have a drafts mailbox');
+ $this->logger->info("Account {$account->getId()} does not have a drafts mailbox");
$mailAccount->setDraftsMailboxId(null);
}
@@ -72,7 +72,7 @@ public function handle(Event $event): void {
$sentMailbox = $this->findSpecial($mailboxes, 'sent');
$mailAccount->setSentMailboxId($sentMailbox->getId());
} catch (DoesNotExistException $e) {
- $this->logger->info('Account ' . $account->getId() . ' does not have a sent mailbox');
+ $this->logger->info("Account {$account->getId()} does not have a sent mailbox");
$mailAccount->setSentMailboxId(null);
}
@@ -82,7 +82,7 @@ public function handle(Event $event): void {
$trashMailbox = $this->findSpecial($mailboxes, 'trash');
$mailAccount->setTrashMailboxId($trashMailbox->getId());
} catch (DoesNotExistException $e) {
- $this->logger->info('Account ' . $account->getId() . ' does not have a trash mailbox');
+ $this->logger->info("Account {$account->getId()} does not have a trash mailbox");
$mailAccount->setTrashMailboxId(null);
}
@@ -92,7 +92,7 @@ public function handle(Event $event): void {
$archiveMailbox = $this->findSpecial($mailboxes, 'archive');
$mailAccount->setArchiveMailboxId($archiveMailbox->getId());
} catch (DoesNotExistException $e) {
- $this->logger->info('Account ' . $account->getId() . ' does not have an archive mailbox');
+ $this->logger->info("Account {$account->getId()} does not have an archive mailbox");
$mailAccount->setArchiveMailboxId(null);
}
@@ -102,7 +102,7 @@ public function handle(Event $event): void {
$junkMailbox = $this->findSpecial($mailboxes, 'junk');
$mailAccount->setJunkMailboxId($junkMailbox->getId());
} catch (DoesNotExistException) {
- $this->logger->info('Account ' . $account->getId() . ' does not have an junk mailbox');
+ $this->logger->info("Account {$account->getId()} does not have an junk mailbox");
$mailAccount->setJunkMailboxId(null);
}
}
@@ -111,7 +111,7 @@ public function handle(Event $event): void {
$snoozeMailbox = $this->findSpecial($mailboxes, 'snooze');
$mailAccount->setSnoozeMailboxId($snoozeMailbox->getId());
} catch (DoesNotExistException $e) {
- $this->logger->info('Account ' . $account->getId() . ' does not have an snooze mailbox');
+ $this->logger->info("Account {$account->getId()} does not have an snooze mailbox");
$mailAccount->setSnoozeMailboxId(null);
}
diff --git a/lib/Migration/MigrateImportantFromImapAndDb.php b/lib/Migration/MigrateImportantFromImapAndDb.php
index 27ebf48585..ce5d3ad3c1 100644
--- a/lib/Migration/MigrateImportantFromImapAndDb.php
+++ b/lib/Migration/MigrateImportantFromImapAndDb.php
@@ -54,7 +54,7 @@ public function migrateImportantOnImap(Horde_Imap_Client_Socket $client, Account
try {
$this->messageMapper->addFlag($client, $mailbox, $uids, Tag::LABEL_IMPORTANT);
} catch (Horde_Imap_Client_Exception $e) {
- $this->logger->debug('Could not flag messages in mailbox <' . $mailbox->getId() . '>');
+ $this->logger->debug("Could not flag messages in mailbox <{$mailbox->getId()}>");
throw new ServiceException($e->getMessage(), 0, $e);
}
}
@@ -67,7 +67,7 @@ public function migrateImportantFromDb(Horde_Imap_Client_Socket $client, Account
try {
$this->messageMapper->addFlag($client, $mailbox, $uids, Tag::LABEL_IMPORTANT);
} catch (Horde_Imap_Client_Exception $e) {
- $this->logger->debug('Could not flag messages in mailbox <' . $mailbox->getId() . '>');
+ $this->logger->debug("Could not flag messages in mailbox <{$mailbox->getId()}>");
throw new ServiceException($e->getMessage(), 0, $e);
}
}
diff --git a/lib/SMTP/SmtpClientFactory.php b/lib/SMTP/SmtpClientFactory.php
index 0315414a12..8216ddfb9e 100644
--- a/lib/SMTP/SmtpClientFactory.php
+++ b/lib/SMTP/SmtpClientFactory.php
@@ -83,7 +83,7 @@ public function create(Account $account): Horde_Mail_Transport {
);
}
if ($account->getMailAccount()->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) {
- $fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-smtp.log';
+ $fn = "mail-{$account->getUserId()}-{$account->getId()}-smtp.log";
$params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn;
}
return new Horde_Mail_Transport_Smtphorde($params);
diff --git a/lib/Service/AiIntegrations/AiIntegrationsService.php b/lib/Service/AiIntegrations/AiIntegrationsService.php
index a17e78c3aa..a2b2bdcaed 100644
--- a/lib/Service/AiIntegrations/AiIntegrationsService.php
+++ b/lib/Service/AiIntegrations/AiIntegrationsService.php
@@ -216,7 +216,7 @@ public function generateEventData(Account $account, string $threadId, array $mes
*/
public function getSmartReply(Account $account, Mailbox $mailbox, Message $message, string $currentUserId): ?array {
if (in_array(FreePromptTaskType::class, $this->textProcessingManager->getAvailableTaskTypes(), true)) {
- $cachedReplies = $this->cache->getValue('smartReplies_' . $message->getId());
+ $cachedReplies = $this->cache->getValue("smartReplies_{$message->getId()}");
if ($cachedReplies) {
return json_decode($cachedReplies, true, 512);
}
@@ -256,7 +256,7 @@ public function getSmartReply(Account $account, Mailbox $mailbox, Message $messa
try {
$cleaned = preg_replace('/^```json\s*|\s*```$/', '', trim($replies));
$decoded = json_decode($cleaned, true, 512, JSON_THROW_ON_ERROR);
- $this->cache->addValue('smartReplies_' . $message->getId(), $replies);
+ $this->cache->addValue("smartReplies_{$message->getId()}", $replies);
return $decoded;
} catch (JsonException $e) {
throw new ServiceException('Failed to decode smart replies JSON output', previous: $e);
@@ -341,7 +341,8 @@ public function requiresTranslation(
}
$language = explode('_', $this->l->getLanguageCode())[0];
- $cachedValue = $this->cache->getValue('needsTranslation_' . $language . $message->getId());
+ $messageId = $message->getId();
+ $cachedValue = $this->cache->getValue("needsTranslation_{$language}{$messageId}");
if ($cachedValue) {
return $cachedValue === 'true' ? true : false;
}
@@ -397,7 +398,7 @@ public function requiresTranslation(
}
// Can't use json_decode() here because the output contains additional garbage
$result = preg_match('/{\s*"needsTranslation"\s*:\s*true\s*}/i', $output) === 1;
- $this->cache->addValue('needsTranslation_' . $language . $message->getId(), $result ? 'true' : 'false');
+ $this->cache->addValue("needsTranslation_{$language}{$messageId}", $result ? 'true' : 'false');
return $result;
}
diff --git a/lib/Service/AntiSpamService.php b/lib/Service/AntiSpamService.php
index d991f036c9..b0b7658443 100644
--- a/lib/Service/AntiSpamService.php
+++ b/lib/Service/AntiSpamService.php
@@ -113,7 +113,7 @@ public function sendReportEmail(Account $account, Mailbox $mailbox, int $uid, st
try {
$attachmentMessage = $this->mailManager->getMessage($userId, $messageId);
} catch (DoesNotExistException $e) {
- $this->logger->error('Could not find reported email with message ID #' . $messageId, ['exception' => $e]);
+ $this->logger->error("Could not find reported email with message ID #$messageId", ['exception' => $e]);
return;
}
@@ -203,7 +203,7 @@ public function sendReportEmail(Account $account, Mailbox $mailbox, int $uid, st
$mail->getRaw(false)
);
} catch (Horde_Imap_Client_Exception $e) {
- $this->logger->error('Could not move report email to sent mailbox, but the report email was sent. Reported email was id: #' . $messageId, ['exception' => $e]);
+ $this->logger->error("Could not move report email to sent mailbox, but the report email was sent. Reported email was id: #$messageId", ['exception' => $e]);
} finally {
$client->logout();
}
diff --git a/lib/Service/AutoCompletion/AddressCollector.php b/lib/Service/AutoCompletion/AddressCollector.php
index 3f0575931e..e1aad45585 100644
--- a/lib/Service/AutoCompletion/AddressCollector.php
+++ b/lib/Service/AutoCompletion/AddressCollector.php
@@ -44,7 +44,8 @@ public function __construct(CollectedAddressMapper $mapper,
* @return void
*/
public function addAddresses(string $userId, AddressList $addressList): void {
- $this->logger->debug('collecting ' . count($addressList) . ' email addresses');
+ $nAddresses = count($addressList);
+ $this->logger->debug("collecting $nAddresses email addresses");
foreach ($addressList->iterate() as $address) {
/* @var $address Address */
$this->saveAddress($userId, $address);
@@ -82,7 +83,8 @@ private function saveAddress(string $userId, Address $address): void {
public function searchAddress(string $userId, string $term): array {
$this->logger->debug("searching for collected address <$term>");
$result = $this->mapper->findMatching($userId, $term);
- $this->logger->debug('found ' . count($result) . ' matches in collected addresses');
+ $nResult = count($result);
+ $this->logger->debug("found $nResult matches in collected addresses");
return $result;
}
}
diff --git a/lib/Service/AutoConfig/MxRecord.php b/lib/Service/AutoConfig/MxRecord.php
index e63c17f9e6..9905e0212a 100644
--- a/lib/Service/AutoConfig/MxRecord.php
+++ b/lib/Service/AutoConfig/MxRecord.php
@@ -37,7 +37,8 @@ public function query(string $host) {
asort($sortedRecords, SORT_NUMERIC);
$mxRecords = array_filter(array_keys($sortedRecords), static fn ($record) => !empty($record));
- $this->logger->debug('found ' . count($sortedRecords) . " MX records for host <$host>");
+ $nRecords = count($sortedRecords);
+ $this->logger->debug("found $nRecords MX records for host <$host>");
if (empty(($mxRecords))) {
return [];
}
diff --git a/lib/Service/Classification/ImportanceClassifier.php b/lib/Service/Classification/ImportanceClassifier.php
index 8b1d93ffa1..bf8ee00b9e 100644
--- a/lib/Service/Classification/ImportanceClassifier.php
+++ b/lib/Service/Classification/ImportanceClassifier.php
@@ -167,10 +167,12 @@ public function buildDataSet(
$perf ??= $this->performanceLogger->start('build data set for importance classifier training');
$incomingMailboxes = $this->getIncomingMailboxes($account);
- $logger->debug('found ' . count($incomingMailboxes) . ' incoming mailbox(es)');
+ $nIncoming = count($incomingMailboxes);
+ $logger->debug("found $nIncoming incoming mailbox(es)");
$perf->step('find incoming mailboxes');
$outgoingMailboxes = $this->getOutgoingMailboxes($account);
- $logger->debug('found ' . count($outgoingMailboxes) . ' outgoing mailbox(es)');
+ $nOutgoing = count($outgoingMailboxes);
+ $logger->debug("found $nOutgoing outgoing mailbox(es)");
$perf->step('find outgoing mailboxes');
$mailboxIds = array_map(static fn (Mailbox $mailbox) => $mailbox->getId(), $incomingMailboxes);
@@ -179,7 +181,9 @@ public function buildDataSet(
[$this, 'filterMessageHasSenderEmail']
);
$importantMessages = array_filter($messages, static fn (Message $message) => $message->getFlagImportant() === true);
- $logger->debug('found ' . count($messages) . ' messages of which ' . count($importantMessages) . ' are important');
+ $nMessages = count($messages);
+ $nImportant = count($importantMessages);
+ $logger->debug("found $nMessages messages of which $nImportant are important");
if (count($importantMessages) < self::COLD_START_THRESHOLD) {
$logger->info('not enough messages to train a classifier');
return null;
@@ -275,7 +279,7 @@ private function trainWithCustomDataSet(
*/
$validationThreshold = max(
5,
- (int)(count($dataSet) * 0.2)
+ (int)((float)count($dataSet) * 0.2)
);
$validationSet = array_slice($dataSet, 0, $validationThreshold);
$trainingSet = array_slice($dataSet, $validationThreshold);
@@ -293,7 +297,11 @@ private function trainWithCustomDataSet(
}
}
- $logger->debug('data set split into ' . count($trainingSet) . ' (' . self::LABEL_IMPORTANT . ': ' . $trainingSetImportantCount . ') training and ' . count($validationSet) . ' (' . self::LABEL_IMPORTANT . ': ' . $validationSetImportantCount . ') validation sets with ' . count($trainingSet[0]['features'] ?? []) . ' dimensions');
+ $nTraining = count($trainingSet);
+ $nValidation = count($validationSet);
+ $nFeatures = count($trainingSet[0]['features'] ?? []);
+ $labelImportant = self::LABEL_IMPORTANT;
+ $logger->debug("data set split into $nTraining ($labelImportant: $trainingSetImportantCount) training and $nValidation ($labelImportant: $validationSetImportantCount) validation sets with $nFeatures dimensions");
if ($validationSet === [] || $trainingSet === []) {
$logger->info('not enough messages to train a classifier');
diff --git a/lib/Service/ItineraryService.php b/lib/Service/ItineraryService.php
index 37c296bab8..b19492d112 100644
--- a/lib/Service/ItineraryService.php
+++ b/lib/Service/ItineraryService.php
@@ -78,7 +78,8 @@ public function extract(Account $account, Mailbox $mailbox, int $id): Itinerary
$itinerary = $itinerary->merge(
$this->extractor->extract($htmlBody)
);
- $this->logger->debug('Extracted ' . count($itinerary) . ' itinerary entries from the message HTML body');
+ $nItinerary = count($itinerary);
+ $this->logger->debug("Extracted $nItinerary itinerary entries from the message HTML body");
} else {
$this->logger->debug('Message does not have an HTML body, can\'t extract itinerary info');
}
@@ -88,14 +89,17 @@ public function extract(Account $account, Mailbox $mailbox, int $id): Itinerary
}
$itinerary = array_reduce($attachments, function (Itinerary $combined, string $attachment) {
$extracted = $this->extractor->extract($attachment);
- $this->logger->debug('Extracted ' . count($extracted) . ' itinerary entries from an attachment');
+ $nExtracted = count($extracted);
+ $this->logger->debug("Extracted $nExtracted itinerary entries from an attachment");
return $combined->merge($extracted);
}, $itinerary);
// Lastly, we put the extracted data through the tool again, so it can combine
// and pick the most relevant information
$final = $this->extractor->extract(json_encode($itinerary));
- $this->logger->debug('Reduced ' . count($itinerary) . ' itinerary entries to ' . count($final) . ' entries');
+ $nItinerary = count($itinerary);
+ $nFinal = count($final);
+ $this->logger->debug("Reduced $nItinerary itinerary entries to $nFinal entries");
$cache_key = $this->buildCacheKey($account, $mailbox, $id);
$this->cache->set($cache_key, json_encode($final), self::CACHE_TTL);
diff --git a/lib/Service/MailManager.php b/lib/Service/MailManager.php
index 1c36a7508f..5fe372c752 100644
--- a/lib/Service/MailManager.php
+++ b/lib/Service/MailManager.php
@@ -415,7 +415,7 @@ public function updateSubscription(Account $account, Mailbox $mailbox, bool $sub
$client->subscribeMailbox($mailbox->getName(), $subscribed);
} catch (Horde_Imap_Client_Exception $e) {
throw new ServiceException(
- 'Could not set subscription status for mailbox ' . $mailbox->getId() . ' on IMAP: ' . $e->getMessage(),
+ "Could not set subscription status for mailbox {$mailbox->getId()} on IMAP: {$e->getMessage()}",
$e->getCode(),
$e
);
diff --git a/lib/Service/MailTransmission.php b/lib/Service/MailTransmission.php
index b90ca05d38..d8e400c095 100644
--- a/lib/Service/MailTransmission.php
+++ b/lib/Service/MailTransmission.php
@@ -387,7 +387,7 @@ public function sendMdn(Account $account, Mailbox $mailbox, Message $message): v
}
if (count($fetchResults) < 1) {
- throw new ServiceException('Message "' . $message->getId() . '" not found.');
+ throw new ServiceException("Message \"{$message->getId()}\" not found.");
}
$imapDate = $fetchResults[0]->getImapDate();
@@ -399,7 +399,7 @@ public function sendMdn(Account $account, Mailbox $mailbox, Message $message): v
$originalRecipient = $mdnHeaders->getHeader('original-recipient');
if ($dispositionNotificationTo === null) {
- throw new ServiceException('Message "' . $message->getId() . '" has no disposition-notification-to header.');
+ throw new ServiceException("Message \"{$message->getId()}\" has no disposition-notification-to header.");
}
$headers = new Horde_Mime_Headers();
@@ -431,7 +431,7 @@ public function sendMdn(Account $account, Mailbox $mailbox, Message $message): v
]
);
} catch (Horde_Mime_Exception $e) {
- throw new ServiceException('Unable to send mdn for message "' . $message->getId() . '" caused by: ' . $e->getMessage(), 0, $e);
+ throw new ServiceException("Unable to send mdn for message \"{$message->getId()}\" caused by: {$e->getMessage()}", 0, $e);
}
}
diff --git a/lib/Service/PreprocessingService.php b/lib/Service/PreprocessingService.php
index 79f528900a..976b174891 100644
--- a/lib/Service/PreprocessingService.php
+++ b/lib/Service/PreprocessingService.php
@@ -57,7 +57,9 @@ public function process(int $limitTimestamp, Account $account): void {
}
$processedMessages = $this->previewEnhancer->process($account, $mailbox, $filteredMessages);
- $this->logger->debug('Processed ' . count($processedMessages) . ' messages for structure data for mailbox ' . $mailbox->getId());
+ $nProcessed = count($processedMessages);
+ $mailboxId = $mailbox->getId();
+ $this->logger->debug("Processed $nProcessed messages for structure data for mailbox $mailboxId");
}
}
}
diff --git a/lib/Service/SetupService.php b/lib/Service/SetupService.php
index e55daa741a..20775b51ec 100644
--- a/lib/Service/SetupService.php
+++ b/lib/Service/SetupService.php
@@ -113,7 +113,7 @@ public function createNewAccount(string $accountName,
}
$this->accountService->save($newAccount);
- $this->logger->debug('account created ' . $newAccount->getId());
+ $this->logger->debug("account created {$newAccount->getId()}");
$this->tagMapper->createDefaultTags($newAccount);
diff --git a/lib/Service/Sync/ImapToDbSynchronizer.php b/lib/Service/Sync/ImapToDbSynchronizer.php
index 2613067a4b..69235bf29f 100644
--- a/lib/Service/Sync/ImapToDbSynchronizer.php
+++ b/lib/Service/Sync/ImapToDbSynchronizer.php
@@ -127,10 +127,10 @@ public function syncAccount(Account $account,
$syncSent = $sentMailboxId === $mailbox->getId() || $mailbox->isSpecialUse('sent');
if (!$syncTrash && !$mailbox->isInbox() && !$syncSnooze && !$mailbox->getSyncInBackground() && !$syncSent) {
- $logger->debug('Skipping mailbox sync for ' . $mailbox->getId());
+ $logger->debug("Skipping mailbox sync for {$mailbox->getId()}");
continue;
}
- $logger->debug('Syncing ' . $mailbox->getId());
+ $logger->debug("Syncing {$mailbox->getId()}");
if ($this->sync(
$account,
$client,
@@ -239,15 +239,15 @@ public function sync(Account $account,
}
if ($force || ($criteria & Horde_Imap_Client::SYNC_NEWMSGSUIDS)) {
- $logger->debug('Locking mailbox ' . $mailbox->getId() . ' for new messages sync');
+ $logger->debug("Locking mailbox {$mailbox->getId()} for new messages sync");
$this->mailboxMapper->lockForNewSync($mailbox);
}
if ($force || ($criteria & Horde_Imap_Client::SYNC_FLAGSUIDS)) {
- $logger->debug('Locking mailbox ' . $mailbox->getId() . ' for changed messages sync');
+ $logger->debug("Locking mailbox {$mailbox->getId()} for changed messages sync");
$this->mailboxMapper->lockForChangeSync($mailbox);
}
if ($force || ($criteria & Horde_Imap_Client::SYNC_VANISHEDUIDS)) {
- $logger->debug('Locking mailbox ' . $mailbox->getId() . ' for vanished messages sync');
+ $logger->debug("Locking mailbox {$mailbox->getId()} for vanished messages sync");
$this->mailboxMapper->lockForVanishedSync($mailbox);
}
@@ -260,24 +260,24 @@ public function sync(Account $account,
|| $mailbox->getSyncNewToken() === null
|| $mailbox->getSyncChangedToken() === null
|| $mailbox->getSyncVanishedToken() === null) {
- $logger->debug('Running initial sync for ' . $mailbox->getId());
+ $logger->debug("Running initial sync for {$mailbox->getId()}");
$this->runInitialSync($client, $account, $mailbox, $logger);
} else {
try {
- $logger->debug('Running partial sync for ' . $mailbox->getId() . ' with criteria ' . $criteria);
+ $logger->debug("Running partial sync for {$mailbox->getId()} with criteria $criteria");
// Only rebuild threads if there were new or vanished messages
$rebuildThreads = $this->runPartialSync($client, $account, $mailbox, $logger, $hasQresync, $criteria, $knownUids);
} catch (UidValidityChangedException $e) {
- $logger->warning('Mailbox UID validity changed. Wiping cache and performing full sync for ' . $mailbox->getId());
+ $logger->warning("Mailbox UID validity changed. Wiping cache and performing full sync for {$mailbox->getId()}");
$this->resetCache($account, $mailbox);
- $logger->debug('Running initial sync for ' . $mailbox->getId() . ' after cache reset');
+ $logger->debug("Running initial sync for {$mailbox->getId()} after cache reset");
$this->runInitialSync($client, $account, $mailbox, $logger);
} catch (MailboxDoesNotSupportModSequencesException $e) {
- $logger->warning('Mailbox does not support mod-sequences error occured. Wiping cache and performing full sync for ' . $mailbox->getId(), [
+ $logger->warning("Mailbox does not support mod-sequences error occured. Wiping cache and performing full sync for {$mailbox->getId()}", [
'exception' => $e,
]);
$this->resetCache($account, $mailbox);
- $logger->debug('Running initial sync for ' . $mailbox->getId() . ' after cache reset - no mod-sequences error');
+ $logger->debug("Running initial sync for {$mailbox->getId()} after cache reset - no mod-sequences error");
$this->runInitialSync($client, $account, $mailbox, $logger);
}
}
@@ -285,7 +285,7 @@ public function sync(Account $account,
// Just rethrow, don't wrap into another exception
throw $e;
} catch (Throwable $e) {
- throw new ServiceException('Sync failed for ' . $account->getId() . ':' . $mailbox->getName() . ': ' . $e->getMessage(), 0, $e);
+ throw new ServiceException("Sync failed for {$account->getId()}:{$mailbox->getName()}: {$e->getMessage()}", 0, $e);
} finally {
$this->unlockMailbox($force, $criteria, $logger, $mailbox);
}
@@ -306,17 +306,17 @@ public function sync(Account $account,
private function unlockMailbox(bool $force, int $criteria, LoggerInterface $logger, Mailbox $mailbox): void {
if (($force || ($criteria & Horde_Imap_Client::SYNC_VANISHEDUIDS))
&& $mailbox->getSyncVanishedLock() !== null) {
- $logger->debug('Unlocking mailbox ' . $mailbox->getId() . ' from vanished messages sync');
+ $logger->debug("Unlocking mailbox {$mailbox->getId()} from vanished messages sync");
$this->mailboxMapper->unlockFromVanishedSync($mailbox);
}
if (($force || ($criteria & Horde_Imap_Client::SYNC_FLAGSUIDS))
&& $mailbox->getSyncChangedLock() !== null) {
- $logger->debug('Unlocking mailbox ' . $mailbox->getId() . ' from changed messages sync');
+ $logger->debug("Unlocking mailbox {$mailbox->getId()} from changed messages sync");
$this->mailboxMapper->unlockFromChangedSync($mailbox);
}
if (($force || ($criteria & Horde_Imap_Client::SYNC_NEWMSGSUIDS))
&& $mailbox->getSyncNewLock() !== null) {
- $logger->debug('Unlocking mailbox ' . $mailbox->getId() . ' from new messages sync');
+ $logger->debug("Unlocking mailbox {$mailbox->getId()} from new messages sync");
$this->mailboxMapper->unlockFromNewSync($mailbox);
}
}
@@ -331,7 +331,7 @@ private function runInitialSync(
Mailbox $mailbox,
LoggerInterface $logger): void {
$perf = $this->performanceLogger->startWithLogger(
- 'Initial sync ' . $account->getId() . ':' . $mailbox->getName(),
+ "Initial sync {$account->getId()}:{$mailbox->getName()}",
$logger
);
@@ -400,7 +400,7 @@ private function runPartialSync(
?array $knownUids = null): bool {
$newOrVanished = false;
$perf = $this->performanceLogger->startWithLogger(
- 'partial sync ' . $account->getId() . ':' . $mailbox->getName(),
+ "partial sync {$account->getId()}:{$mailbox->getName()}",
$logger
);
@@ -553,7 +553,7 @@ public function repairSync(
$this->mailboxMapper->lockForVanishedSync($mailbox);
$perf = $this->performanceLogger->startWithLogger(
- 'Repair sync for ' . $account->getId() . ':' . $mailbox->getName(),
+ "Repair sync for {$account->getId()}:{$mailbox->getName()}",
$logger,
);
diff --git a/lib/SetupChecks/MailConnectionPerformance.php b/lib/SetupChecks/MailConnectionPerformance.php
index 09591a2704..ec764e1216 100644
--- a/lib/SetupChecks/MailConnectionPerformance.php
+++ b/lib/SetupChecks/MailConnectionPerformance.php
@@ -79,7 +79,7 @@ public function run(): SetupResult {
$tests[$host][$accountId] = ['start' => $tStart, 'login' => $tLogin, 'operation' => $tOperation];
} catch (Throwable $e) {
- $this->logger->warning('Error occurred while performing system check on mail account: ' . $account->getId());
+ $this->logger->warning("Error occurred while performing system check on mail account: {$account->getId()}");
} finally {
$client->close();
}
@@ -88,15 +88,15 @@ public function run(): SetupResult {
// calculate performance
$performance = [];
foreach ($tests as $host => $test) {
- $tLogin = 0;
- $tOperation = 0;
+ $tLogin = 0.0;
+ $tOperation = 0.0;
foreach ($test as $entry) {
[$start, $login, $operation] = array_values($entry);
$tLogin += ($login - $start);
$tOperation += ($operation - $login);
}
- $performance[$host]['login'] = $tLogin / count($tests[$host]);
- $performance[$host]['operation'] = $tOperation / count($tests[$host]);
+ $performance[$host]['login'] = $tLogin / (float)count($tests[$host]);
+ $performance[$host]['operation'] = $tOperation / (float)count($tests[$host]);
}
// display performance test outcome
foreach ($performance as $host => $entry) {
diff --git a/lib/Sieve/SieveClientFactory.php b/lib/Sieve/SieveClientFactory.php
index fb9264ae6b..fbe6d340d1 100644
--- a/lib/Sieve/SieveClientFactory.php
+++ b/lib/Sieve/SieveClientFactory.php
@@ -39,7 +39,7 @@ public function getClient(Account $account): ManageSieve {
}
if ($account->getMailAccount()->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) {
- $logFile = $this->config->getSystemValue('datadirectory') . '/mail-' . $account->getUserId() . '-' . $account->getId() . '-sieve.log';
+ $logFile = $this->config->getSystemValue('datadirectory') . "/mail-{$account->getUserId()}-{$account->getId()}-sieve.log";
} else {
$logFile = null;
}
diff --git a/lib/Support/PerformanceLoggerTask.php b/lib/Support/PerformanceLoggerTask.php
index 4b78582550..db676a91b4 100644
--- a/lib/Support/PerformanceLoggerTask.php
+++ b/lib/Support/PerformanceLoggerTask.php
@@ -52,8 +52,8 @@ public function step(string $description): void {
$this->logger->debug(
sprintf(
$message . ' %d/%dMB memory used',
- round(memory_get_usage() / 1024 / 1024),
- round(memory_get_peak_usage() / 1024 / 1024)
+ round(memory_get_usage() / 1024.0 / 1024.0),
+ round(memory_get_peak_usage() / 1024.0 / 1024.0)
)
);
} else {
diff --git a/lib/functions.php b/lib/functions.php
index 156a01eac9..34bbfb1efc 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -28,7 +28,7 @@ function chunk_uid_sequence(array $uids, int $bytes): array {
while ($uids !== []) {
$take = count($uids);
while (strlen((new Horde_Imap_Client_Ids(array_slice($uids, 0, $take)))->tostring) >= $bytes) {
- $take = (int)($take * 0.75);
+ $take = (int)((float)$take * 0.75);
}
$chunks[] = new Horde_Imap_Client_Ids(
array_splice($uids, 0, max($take, 1))