diff --git a/lib/AddressList.php b/lib/AddressList.php index 9f7b245a8..804e5377a 100644 --- a/lib/AddressList.php +++ b/lib/AddressList.php @@ -88,7 +88,7 @@ class AddressList implements Countable, JsonSerializable { * @return Address|null */ public function first() { - if (empty($this->addresses)) { + if ($this->addresses === []) { return null; } @@ -135,7 +135,7 @@ class AddressList implements Countable, JsonSerializable { // Check whether our array contains the other address return $our->equals($address); }); - if (empty($same)) { + if ($same === []) { // No dup found, hence the address is new and we // have to add it $addresses[] = $address; diff --git a/lib/Cache/Cache.php b/lib/Cache/Cache.php index cad44593a..31384dc14 100644 --- a/lib/Cache/Cache.php +++ b/lib/Cache/Cache.php @@ -158,7 +158,7 @@ class Cache extends Horde_Imap_Client_Cache_Backend { return $ret; } - if (!empty($fields)) { + if ($fields !== []) { $fields = array_flip($fields); } $ptr = &$this->_data[$mailbox]; @@ -171,7 +171,7 @@ class Cache extends Horde_Imap_Client_Cache_Backend { } } - $ret[$val] = (empty($fields) || empty($ptr[$val])) + $ret[$val] = ($fields === [] || empty($ptr[$val])) ? $ptr[$val] : array_intersect_key($ptr[$val], $fields); } @@ -234,7 +234,7 @@ class Cache extends Horde_Imap_Client_Cache_Backend { public function getMetaData($mailbox, $uidvalid, $entries) { $this->_loadSliceMap($mailbox, $uidvalid); - return empty($entries) + return $entries === [] ? $this->_slicemap[$mailbox]['d'] : array_intersect_key($this->_slicemap[$mailbox]['d'], array_flip($entries)); } @@ -268,7 +268,7 @@ class Cache extends Horde_Imap_Client_Cache_Backend { ); } - if (empty($deleted)) { + if ($deleted === []) { return; } diff --git a/lib/Command/AddMissingTags.php b/lib/Command/AddMissingTags.php index 3cebc1437..b5518c7fc 100644 --- a/lib/Command/AddMissingTags.php +++ b/lib/Command/AddMissingTags.php @@ -65,7 +65,7 @@ class AddMissingTags extends Command { if ($accountId === 0) { $accounts = $this->mapper->getAllAccounts(); $output->writeln(sprintf('%d accounts to check found', count($accounts))); - if (empty($accounts)) { + if ($accounts === []) { $output->writeLn('No accounts exist'); return 1; } diff --git a/lib/Db/LocalAttachmentMapper.php b/lib/Db/LocalAttachmentMapper.php index a740ba6d8..61ca176c6 100644 --- a/lib/Db/LocalAttachmentMapper.php +++ b/lib/Db/LocalAttachmentMapper.php @@ -60,7 +60,7 @@ class LocalAttachmentMapper extends QBMapper { * @return LocalAttachment[] */ public function findByLocalMessageIds(array $localMessageIds): array { - if (empty($localMessageIds)) { + if ($localMessageIds === []) { return []; } $qb = $this->db->getQueryBuilder(); diff --git a/lib/Db/LocalMessageMapper.php b/lib/Db/LocalMessageMapper.php index eeeb28a45..09e590788 100644 --- a/lib/Db/LocalMessageMapper.php +++ b/lib/Db/LocalMessageMapper.php @@ -76,7 +76,7 @@ class LocalMessageMapper extends QBMapper { } $rows->closeCursor(); - if (empty($ids)) { + if ($ids === []) { return []; } diff --git a/lib/Db/MessageMapper.php b/lib/Db/MessageMapper.php index 0642c5f9f..d13edfaa7 100644 --- a/lib/Db/MessageMapper.php +++ b/lib/Db/MessageMapper.php @@ -137,7 +137,7 @@ class MessageMapper extends QBMapper { ); $results = $this->findRelatedData($this->findEntities($query), $userId); - if (empty($results)) { + if ($results === []) { throw new DoesNotExistException("Message $id does not exist"); } return $results[0]; @@ -170,7 +170,7 @@ class MessageMapper extends QBMapper { * @return int[] */ public function findUidsForIds(Mailbox $mailbox, array $ids) { - if (empty($ids)) { + if ($ids === []) { // Shortcut for empty sets return []; } @@ -447,7 +447,7 @@ class MessageMapper extends QBMapper { $imapTags = $message->getTags(); $dbTags = $tags[$message->getMessageId()] ?? []; - if (empty($imapTags) && empty($dbTags)) { + if ($imapTags === [] && $dbTags === []) { // neither old nor new tags return; } @@ -460,7 +460,7 @@ class MessageMapper extends QBMapper { } $perf->step("Tagged messages"); - if (empty($dbTags)) { + if ($dbTags === []) { // we have nothing to possibly remove return; } @@ -1052,7 +1052,7 @@ class MessageMapper extends QBMapper { * @return Message[] */ public function findByMailboxAndIds(Mailbox $mailbox, string $userId, array $ids): array { - if (empty($ids)) { + if ($ids === []) { return []; } @@ -1080,7 +1080,7 @@ class MessageMapper extends QBMapper { * @return Message[] */ public function findByIds(string $userId, array $ids): array { - if (empty($ids)) { + if ($ids === []) { return []; } diff --git a/lib/Db/RecipientMapper.php b/lib/Db/RecipientMapper.php index 9bde63ecd..d6372de6c 100644 --- a/lib/Db/RecipientMapper.php +++ b/lib/Db/RecipientMapper.php @@ -57,7 +57,7 @@ class RecipientMapper extends QBMapper { * @return Recipient[] */ public function findByLocalMessageIds(array $localMessageIds): array { - if (empty($localMessageIds)) { + if ($localMessageIds === []) { return []; } $qb = $this->db->getQueryBuilder(); @@ -105,7 +105,7 @@ class RecipientMapper extends QBMapper { return; } - if (empty($oldRecipients)) { + if ($oldRecipients === []) { // No need for a diff, save and return $this->saveRecipients($localMessageId, $to); $this->saveRecipients($localMessageId, $cc); @@ -128,7 +128,7 @@ class RecipientMapper extends QBMapper { $newTo = array_udiff($to, $oldTo, static function (Recipient $a, Recipient $b) { return strcmp($a->getEmail(), $b->getEmail()); }); - if (!empty($newTo)) { + if ($newTo !== []) { $this->saveRecipients($localMessageId, $newTo); } @@ -143,7 +143,7 @@ class RecipientMapper extends QBMapper { $newCC = array_udiff($cc, $oldCc, static function (Recipient $a, Recipient $b) { return strcmp($a->getEmail(), $b->getEmail()); }); - if (!empty($newCC)) { + if ($newCC !== []) { $this->saveRecipients($localMessageId, $newCC); } @@ -158,7 +158,7 @@ class RecipientMapper extends QBMapper { $newBcc = array_udiff($bcc, $oldBcc, static function (Recipient $a, Recipient $b) { return strcmp($a->getEmail(), $b->getEmail()); }); - if (!empty($newBcc)) { + if ($newBcc !== []) { $this->saveRecipients($localMessageId, $newBcc); } diff --git a/lib/Db/TrustedSenderMapper.php b/lib/Db/TrustedSenderMapper.php index 59ad7aedd..ddedaa421 100644 --- a/lib/Db/TrustedSenderMapper.php +++ b/lib/Db/TrustedSenderMapper.php @@ -60,7 +60,7 @@ class TrustedSenderMapper extends QBMapper { /** @var TrustedSender[] $rows */ $rows = $this->findEntities($select); - return !empty($rows); + return $rows !== []; } public function create(string $uid, string $email, string $type): void { diff --git a/lib/Http/Middleware/ErrorMiddleware.php b/lib/Http/Middleware/ErrorMiddleware.php index 051a17cc3..f26b39542 100644 --- a/lib/Http/Middleware/ErrorMiddleware.php +++ b/lib/Http/Middleware/ErrorMiddleware.php @@ -71,7 +71,7 @@ class ErrorMiddleware extends Middleware { public function afterException($controller, $methodName, Exception $exception) { $reflectionMethod = new ReflectionMethod($controller, $methodName); $attributes = $reflectionMethod->getAttributes(TrapError::class); - if (empty($attributes)) { + if ($attributes === []) { return parent::afterException($controller, $methodName, $exception); } diff --git a/lib/Http/Middleware/ProvisioningMiddleware.php b/lib/Http/Middleware/ProvisioningMiddleware.php index 39b9a3e0c..d8232d7d8 100644 --- a/lib/Http/Middleware/ProvisioningMiddleware.php +++ b/lib/Http/Middleware/ProvisioningMiddleware.php @@ -64,7 +64,7 @@ class ProvisioningMiddleware extends Middleware { return; } $configs = $this->provisioningManager->getConfigs(); - if (empty($configs)) { + if ($configs === []) { return; } try { diff --git a/lib/IMAP/MessageMapper.php b/lib/IMAP/MessageMapper.php index a188ec8b8..e9a9da77f 100644 --- a/lib/IMAP/MessageMapper.php +++ b/lib/IMAP/MessageMapper.php @@ -289,7 +289,7 @@ class MessageMapper { return $fetchResult->exists(Horde_Imap_Client::FETCH_ENVELOPE); })); - if (empty($fetchResults)) { + if ($fetchResults === []) { $this->logger->debug("findByIds in $mailbox got " . count($ids) . " UIDs but found none"); } else { $minFetched = $fetchResults[0]->getUid(); @@ -813,7 +813,7 @@ class MessageMapper { continue; } - if (!empty($attachmentIds) && !in_array($part->getMimeId(), $attachmentIds, true)) { + if ($attachmentIds !== [] && !in_array($part->getMimeId(), $attachmentIds, true)) { // We are looking for specific parts only and this is not one of them continue; } diff --git a/lib/IMAP/PreviewEnhancer.php b/lib/IMAP/PreviewEnhancer.php index 86e352086..b38868e40 100644 --- a/lib/IMAP/PreviewEnhancer.php +++ b/lib/IMAP/PreviewEnhancer.php @@ -76,7 +76,7 @@ class PreviewEnhancer { return array_merge($carry, [$message->getUid()]); }, []); - if (empty($needAnalyze)) { + if ($needAnalyze === []) { // Nothing to enhance return $messages; } diff --git a/lib/IMAP/Threading/Container.php b/lib/IMAP/Threading/Container.php index ce37fa283..7615b7cd1 100644 --- a/lib/IMAP/Threading/Container.php +++ b/lib/IMAP/Threading/Container.php @@ -140,7 +140,7 @@ class Container implements JsonSerializable { } public function hasChildren(): bool { - return !empty($this->children); + return $this->children !== []; } /** diff --git a/lib/Listener/FlagRepliedMessageListener.php b/lib/Listener/FlagRepliedMessageListener.php index ba2e52a1c..4031a69ee 100644 --- a/lib/Listener/FlagRepliedMessageListener.php +++ b/lib/Listener/FlagRepliedMessageListener.php @@ -74,7 +74,7 @@ class FlagRepliedMessageListener implements IEventListener { } $messages = $this->dbMessageMapper->findByMessageId($event->getAccount(), $event->getRepliedToMessageId()); - if (empty($messages)) { + if ($messages === []) { return; } diff --git a/lib/Migration/AddMissingMessageIds.php b/lib/Migration/AddMissingMessageIds.php index beb893540..e34d3936c 100644 --- a/lib/Migration/AddMissingMessageIds.php +++ b/lib/Migration/AddMissingMessageIds.php @@ -68,7 +68,7 @@ class AddMissingMessageIds implements IRepairStep { } $toFix = $this->mapper->findWithEmptyMessageId(); - if (empty($toFix)) { + if ($toFix === []) { return; } $output->info(sprintf('%d messages need an update', count($toFix))); diff --git a/lib/Migration/MigrateImportantFromImapAndDb.php b/lib/Migration/MigrateImportantFromImapAndDb.php index 7b2ad7e26..a0267c7db 100644 --- a/lib/Migration/MigrateImportantFromImapAndDb.php +++ b/lib/Migration/MigrateImportantFromImapAndDb.php @@ -68,7 +68,7 @@ class MigrateImportantFromImapAndDb { throw new ServiceException("Could not fetch UIDs of important messages: " . $e->getMessage(), 0, $e); } // add $label1 for all that are tagged on IMAP - if (!empty($uids)) { + if ($uids !== []) { try { $this->messageMapper->addFlag($client, $mailbox, $uids, Tag::LABEL_IMPORTANT); } catch (Horde_Imap_Client_Exception $e) { @@ -81,7 +81,7 @@ class MigrateImportantFromImapAndDb { public function migrateImportantFromDb(Horde_Imap_Client_Socket $client, Account $account, Mailbox $mailbox): void { $uids = $this->mailboxMapper->findFlaggedImportantUids($mailbox->getId()); // store our data on imap - if (!empty($uids)) { + if ($uids !== []) { try { $this->messageMapper->addFlag($client, $mailbox, $uids, Tag::LABEL_IMPORTANT); } catch (Horde_Imap_Client_Exception $e) { diff --git a/lib/Model/IMAPMessage.php b/lib/Model/IMAPMessage.php index da6110c85..28a8b5068 100644 --- a/lib/Model/IMAPMessage.php +++ b/lib/Model/IMAPMessage.php @@ -502,7 +502,7 @@ class IMAPMessage implements IMessage, JsonSerializable { $msg->setFlagImportant(in_array('$important', $flags, true) || in_array('$labelimportant', $flags, true) || in_array(Tag::LABEL_IMPORTANT, $flags, true)); $msg->setFlagAttachments(false); $msg->setFlagMdnsent(in_array(Horde_Imap_Client::FLAG_MDNSENT, $flags, true)); - if (!empty($this->scheduling)) { + if ($this->scheduling !== []) { $msg->setImipMessage(true); } @@ -525,7 +525,7 @@ class IMAPMessage implements IMessage, JsonSerializable { return in_array($flag, $allowed, true) === false; }); - if (empty($tags) === true) { + if (($tags === []) === true) { return $msg; } // cast all leftover $flags to be used as tags diff --git a/lib/Service/Attachment/AttachmentService.php b/lib/Service/Attachment/AttachmentService.php index a4a5c64d2..50a66263f 100644 --- a/lib/Service/Attachment/AttachmentService.php +++ b/lib/Service/Attachment/AttachmentService.php @@ -188,7 +188,7 @@ class AttachmentService implements IAttachmentService { * @return LocalAttachment[] */ public function saveLocalMessageAttachments(string $userId, int $messageId, array $attachmentIds): array { - if (empty($attachmentIds)) { + if ($attachmentIds === []) { return []; } $this->mapper->saveLocalMessageAttachments($userId, $messageId, $attachmentIds); @@ -200,7 +200,7 @@ class AttachmentService implements IAttachmentService { */ public function updateLocalMessageAttachments(string $userId, LocalMessage $message, array $newAttachmentIds): array { // no attachments any more. Delete any old ones and we're done - if (empty($newAttachmentIds)) { + if ($newAttachmentIds === []) { $this->deleteLocalMessageAttachments($userId, $message->getId()); return []; } @@ -216,12 +216,12 @@ class AttachmentService implements IAttachmentService { }, $message->getAttachments()); $add = array_diff($newAttachmentIds, $oldAttachmentIds); - if (!empty($add)) { + if ($add !== []) { $this->mapper->saveLocalMessageAttachments($userId, $message->getId(), $add); } $delete = array_diff($oldAttachmentIds, $newAttachmentIds); - if (!empty($delete)) { + if ($delete !== []) { $this->deleteLocalMessageAttachmentsById($userId, $message->getId(), $delete); } @@ -236,7 +236,7 @@ class AttachmentService implements IAttachmentService { public function handleAttachments(Account $account, array $attachments, \Horde_Imap_Client_Socket $client): array { $attachmentIds = []; - if (empty($attachments)) { + if ($attachments === []) { return $attachmentIds; } @@ -325,7 +325,7 @@ class AttachmentService implements IAttachmentService { ] ); - if (empty($attachments)) { + if ($attachments === []) { return null; } diff --git a/lib/Service/Classification/ImportanceClassifier.php b/lib/Service/Classification/ImportanceClassifier.php index 135f3c51f..21ac72503 100644 --- a/lib/Service/Classification/ImportanceClassifier.php +++ b/lib/Service/Classification/ImportanceClassifier.php @@ -195,7 +195,7 @@ class ImportanceClassifier { $validationSet = array_slice($dataSet, 0, $validationThreshold); $trainingSet = array_slice($dataSet, $validationThreshold); $logger->debug('data set split into ' . count($trainingSet) . ' training and ' . count($validationSet) . ' validation sets with ' . count($trainingSet[0]['features'] ?? []) . ' dimensions'); - if (empty($validationSet) || empty($trainingSet)) { + if ($validationSet === [] || $trainingSet === []) { $logger->info('not enough messages to train a classifier'); $perf->end(); return; diff --git a/lib/Service/DraftsService.php b/lib/Service/DraftsService.php index c2d4fcca4..38cc3bc72 100644 --- a/lib/Service/DraftsService.php +++ b/lib/Service/DraftsService.php @@ -115,13 +115,13 @@ class DraftsService { // if this message has a "sent at" datestamp and the type is set as Type Outbox // check for a valid recipient - if ($message->getType() === LocalMessage::TYPE_OUTGOING && empty($toRecipients)) { + if ($message->getType() === LocalMessage::TYPE_OUTGOING && $toRecipients === []) { throw new ClientException('Cannot convert message to outbox message without at least one recipient'); } $message = $this->mapper->saveWithRecipients($message, $toRecipients, $ccRecipients, $bccRecipients); - if (empty($attachments)) { + if ($attachments === []) { $message->setAttachments($attachments); return $message; } @@ -153,13 +153,13 @@ class DraftsService { // if this message has a "sent at" datestamp and the type is set as Type Outbox // check for a valid recipient - if ($message->getType() === LocalMessage::TYPE_OUTGOING && empty($toRecipients)) { + if ($message->getType() === LocalMessage::TYPE_OUTGOING && $toRecipients === []) { throw new ClientException('Cannot convert message to outbox message without at least one recipient'); } $message = $this->mapper->updateWithRecipients($message, $toRecipients, $ccRecipients, $bccRecipients); - if (empty($attachments)) { + if ($attachments === []) { $message->setAttachments($this->attachmentService->updateLocalMessageAttachments($account->getUserId(), $message, [])); return $message; } @@ -216,7 +216,7 @@ class DraftsService { */ public function flush() { $messages = $this->mapper->findDueDrafts($this->time->getTime()); - if (empty($messages)) { + if ($messages === []) { return; } diff --git a/lib/Service/GroupsIntegration.php b/lib/Service/GroupsIntegration.php index 555c566c1..4c8cd7486 100644 --- a/lib/Service/GroupsIntegration.php +++ b/lib/Service/GroupsIntegration.php @@ -104,7 +104,7 @@ class GroupsIntegration { $members = array_filter($service->getUsers($groupId), static function (array $member) { return !empty($member['email']); }); - if (empty($members)) { + if ($members === []) { throw new ServiceException($groupId . " ({$service->getNamespace()}) has no members with email addresses"); } return array_map(static function (array $member) use ($recipient) { diff --git a/lib/Service/IMipService.php b/lib/Service/IMipService.php index 34b20ab58..09393a186 100644 --- a/lib/Service/IMipService.php +++ b/lib/Service/IMipService.php @@ -63,7 +63,7 @@ class IMipService { public function process(): void { $messages = $this->messageMapper->findIMipMessagesAscending(); - if (empty($messages)) { + if ($messages === []) { $this->logger->info('No iMIP messages to process.'); return; } @@ -106,7 +106,7 @@ class IMipService { return $message->getMailboxId() === $mailbox->getId(); }); - if (empty($filteredMessages)) { + if ($filteredMessages === []) { continue; } diff --git a/lib/Service/MailManager.php b/lib/Service/MailManager.php index 30d84175b..3fd4c2569 100644 --- a/lib/Service/MailManager.php +++ b/lib/Service/MailManager.php @@ -564,7 +564,7 @@ class MailManager implements IMailManager { ]; }, array_merge(...array_values($quotas))); - if (empty($storageQuotas)) { + if ($storageQuotas === []) { // Nothing left to do, and array_merge doesn't like to be called with zero arguments. return null; } diff --git a/lib/Service/OutboxService.php b/lib/Service/OutboxService.php index 5b22d2496..d3a84bf79 100644 --- a/lib/Service/OutboxService.php +++ b/lib/Service/OutboxService.php @@ -165,7 +165,7 @@ class OutboxService { $bccRecipients = self::convertToRecipient($bcc, Recipient::TYPE_BCC); $message = $this->mapper->saveWithRecipients($message, $toRecipients, $ccRecipients, $bccRecipients); - if (empty($attachments)) { + if ($attachments === []) { $message->setAttachments($attachments); return $message; } @@ -196,7 +196,7 @@ class OutboxService { $bccRecipients = self::convertToRecipient($bcc, Recipient::TYPE_BCC); $message = $this->mapper->updateWithRecipients($message, $toRecipients, $ccRecipients, $bccRecipients); - if (empty($attachments)) { + if ($attachments === []) { $message->setAttachments($this->attachmentService->updateLocalMessageAttachments($account->getUserId(), $message, [])); return $message; } @@ -232,7 +232,7 @@ class OutboxService { $this->timeFactory->getTime() ); - if (empty($messages)) { + if ($messages === []) { return; } diff --git a/lib/Service/PreprocessingService.php b/lib/Service/PreprocessingService.php index d227b8624..8301f7c3a 100644 --- a/lib/Service/PreprocessingService.php +++ b/lib/Service/PreprocessingService.php @@ -54,7 +54,7 @@ class PreprocessingService { public function process(int $limitTimestamp, Account $account): void { $mailboxes = $this->mailboxMapper->findAll($account); - if (empty($mailboxes)) { + if ($mailboxes === []) { $this->logger->debug('No mailboxes found.'); return; } @@ -64,7 +64,7 @@ class PreprocessingService { $messages = $this->messageMapper->getUnanalyzed($limitTimestamp, $mailboxIds); - if (empty($messages)) { + if ($messages === []) { $this->logger->debug('No structure data to analyse.'); return; } @@ -74,7 +74,7 @@ class PreprocessingService { return $message->getMailboxId() === $mailbox->getId(); }); - if (empty($filteredMessages)) { + if ($filteredMessages === []) { continue; } diff --git a/lib/Service/Search/MailSearch.php b/lib/Service/Search/MailSearch.php index 5e8d16907..b3a8f1bc8 100644 --- a/lib/Service/Search/MailSearch.php +++ b/lib/Service/Search/MailSearch.php @@ -83,7 +83,7 @@ class MailSearch implements IMailSearch { $mailbox, [$message] ); - if (empty($processed)) { + if ($processed === []) { throw new DoesNotExistException("Message does not exist"); } return $processed[0]; diff --git a/lib/Service/Sync/ImapToDbSynchronizer.php b/lib/Service/Sync/ImapToDbSynchronizer.php index 4c0180d64..85bafb6c0 100644 --- a/lib/Service/Sync/ImapToDbSynchronizer.php +++ b/lib/Service/Sync/ImapToDbSynchronizer.php @@ -408,7 +408,7 @@ class ImapToDbSynchronizer { $perf->step('persist new messages'); $mailbox->setSyncNewToken($client->getSyncToken($mailbox->getName())); - $newOrVanished = !empty($newMessages); + $newOrVanished = $newMessages !== []; } if ($criteria & Horde_Imap_Client::SYNC_FLAGSUIDS) { $response = $this->synchronizer->sync( diff --git a/lib/Service/Sync/SyncService.php b/lib/Service/Sync/SyncService.php index 58c23aa0e..281170fb0 100644 --- a/lib/Service/Sync/SyncService.php +++ b/lib/Service/Sync/SyncService.php @@ -151,7 +151,7 @@ class SyncService { Mailbox $mailbox, array $knownIds, ?SearchQuery $query): Response { - if (empty($knownIds)) { + if ($knownIds === []) { $newIds = $this->messageMapper->findAllIds($mailbox); } else { $newIds = $this->messageMapper->findNewIds($mailbox, $knownIds); diff --git a/lib/functions.php b/lib/functions.php index 611e69432..bcc0a38e0 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -41,7 +41,7 @@ function array_flat_map(callable $map, array $data): array { */ function chunk_uid_sequence(array $uids, int $bytes): array { $chunks = []; - while (!empty($uids)) { + while ($uids !== []) { $take = count($uids); while (strlen((new Horde_Imap_Client_Ids(array_slice($uids, 0, $take)))->tostring) >= $bytes) { $take = (int)($take * 0.75);