chore(php): Refactor empty array check

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2023-05-10 18:21:52 +02:00
Родитель 457c36f0fc
Коммит 82a1233c94
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CC42AC2A7F0E56D8
29 изменённых файлов: 59 добавлений и 59 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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('<error>No accounts exist</error>');
return 1;
}

Просмотреть файл

@ -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();

Просмотреть файл

@ -76,7 +76,7 @@ class LocalMessageMapper extends QBMapper {
}
$rows->closeCursor();
if (empty($ids)) {
if ($ids === []) {
return [];
}

Просмотреть файл

@ -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 [];
}

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -64,7 +64,7 @@ class ProvisioningMiddleware extends Middleware {
return;
}
$configs = $this->provisioningManager->getConfigs();
if (empty($configs)) {
if ($configs === []) {
return;
}
try {

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -76,7 +76,7 @@ class PreviewEnhancer {
return array_merge($carry, [$message->getUid()]);
}, []);
if (empty($needAnalyze)) {
if ($needAnalyze === []) {
// Nothing to enhance
return $messages;
}

Просмотреть файл

@ -140,7 +140,7 @@ class Container implements JsonSerializable {
}
public function hasChildren(): bool {
return !empty($this->children);
return $this->children !== [];
}
/**

Просмотреть файл

@ -74,7 +74,7 @@ class FlagRepliedMessageListener implements IEventListener {
}
$messages = $this->dbMessageMapper->findByMessageId($event->getAccount(), $event->getRepliedToMessageId());
if (empty($messages)) {
if ($messages === []) {
return;
}

Просмотреть файл

@ -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)));

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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];

Просмотреть файл

@ -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(

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);