Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/BackgroundJob/ContextChat/SubmitContentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected function run($argument): void {
}
}

if (count($items) > 0) {
if ($items !== []) {
$this->contentManager->submitContent($this->contextChatProvider->getAppId(), $items);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/BackgroundJob/FollowUpClassifierJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function run($argument): void {
$messages,
static fn (Message $message) => $message->getMailboxId() === $mailboxId,
);
if (count($messages) === 0) {
if ($messages === []) {
return;
}

Expand All @@ -80,7 +80,7 @@ public function run($argument): void {
);
return;
}
if (count($newerMessages) > 0) {
if ($newerMessages !== []) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/BackgroundJob/TrashRetentionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private function cleanTrash(Account $account, int $retentionSeconds): void {
$now - $retentionSeconds,
);

if (count($messages) === 0) {
if ($messages === []) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ContextChat/ContextChatProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function handle(Event $event): void {
$messageIds = array_map(static fn (Message $m): int => $m->getId(), $event->getMessages());

// Ensure that there are messages to sync
if (count($messageIds) === 0) {
if ($messageIds === []) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Db/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ public function findIdsGloballyByQuery(IUser $user, SearchQuery $query, ?int $li

if ($query instanceof GlobalSearchQuery) {
$excludeMailboxIds = $query->getExcludeMailboxIds();
if (count($excludeMailboxIds) > 0) {
if ($excludeMailboxIds !== []) {
$selectMailboxIds->andWhere(
$qb->expr()->notIn('mb.id', $qb->createNamedParameter($excludeMailboxIds, IQueryBuilder::PARAM_INT_ARRAY))
);
Expand Down
2 changes: 1 addition & 1 deletion lib/IMAP/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function find(Horde_Imap_Client_Base $client,
bool $loadBody = false): IMAPMessage {
$result = $this->findByIds($client, $mailbox, new Horde_Imap_Client_Ids([$id]), $userId, $loadBody, true);

if (count($result) === 0) {
if ($result === []) {
throw new DoesNotExistException('Message does not exist');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/Version0110Date20180825201241.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function setEntityClass(string $entityClass): void {
$output->startProgress($nrOfAddresses);

$chunk = $collectedAdressesMapper->getChunk();
while (\count($chunk) > 0) {
while ($chunk !== []) {
foreach ($chunk as $address) {
/* @var $address CollectedAddress */
$maxId = $address->getId();
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/Version1105Date20210922104324.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
$accountIds = array_map(static fn ($row) => (int)$row['id'], $result->fetchAll());
$result->closeCursor();

if (count($accountIds) === 0) {
if ($accountIds === []) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Provider/MailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function label(): string {
*/
#[\Override]
public function hasServices(string $userId): bool {
return (count($this->listServices($userId)) > 0);
return ($this->listServices($userId) !== []);
}

/**
Expand Down Expand Up @@ -132,7 +132,7 @@ public function findServiceByAddress(string $userId, string $address): ?IService
// retrieve service details from data store
$accounts = $this->accountService->findByUserIdAndAddress($userId, $address);
// evaluate if service details where found
if (count($accounts) > 0) {
if ($accounts !== []) {
// return mail service object
return $this->serviceFromAccount($userId, $accounts[0]);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Search/FilteringProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
}
}

if (count($filters) === 0) {
if ($filters === []) {
return SearchResult::complete(
$this->getName(),
[]
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/DataUri/DataUriParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function parse(string $dataUri): DataUri {
$parameters = ['charset' => 'US-ASCII'];
$base64 = false;

if (count($items) > 0) {
if ($items !== []) {
$mediaType = array_shift($items);
foreach ($items as $item) {
if ($item === 'base64') {
Expand Down
6 changes: 3 additions & 3 deletions lib/Service/MailFilter/FilterBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function buildSieveScript(array $filters, string $untouchedScript): strin
}
}

if (count($tests) === 0) {
if ($tests === []) {
// skip filter without tests
$commands[] = '# No valid tests found';
continue;
Expand Down Expand Up @@ -115,7 +115,7 @@ public function buildSieveScript(array $filters, string $untouchedScript): strin
$lines = [];

$extensions = array_unique($extensions);
if (count($extensions) > 0) {
if ($extensions !== []) {
$lines[] = self::SEPARATOR;
$lines[] = 'require ' . SieveUtils::stringList($extensions) . ';';
$lines[] = self::SEPARATOR;
Expand All @@ -131,7 +131,7 @@ public function buildSieveScript(array $filters, string $untouchedScript): strin
}
$lines[] = $untouchedScript;

if (count($filters) > 0) {
if ($filters !== []) {
$lines[] = self::SEPARATOR;
$lines[] = self::DATA_MARKER . json_encode($this->sanitizeDefinition($filters), JSON_THROW_ON_ERROR);
array_push($lines, ...$commands);
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/MimeMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function build(?string $contentPlain, ?string $contentHtml, array $attach

if ($isPgpEncrypted === true && isset($contentPlain)) {
$basePart = $this->buildPgpPart($contentPlain);
} elseif (count($attachments) > 0) {
} elseif ($attachments !== []) {
/*
* Messages with non embedded attachments need to be wrap in a multipart/mixed part
*/
Expand Down Expand Up @@ -145,7 +145,7 @@ private function buildMessagePart(?string $contentPlain, ?string $contentHtml):
$messagePart = new Horde_Mime_Part();
}

if (isset($embeddedParts) && count($embeddedParts) > 0) {
if (isset($embeddedParts) && $embeddedParts !== []) {
/*
* Text parts with embedded content (e.g. inline images, etc) need be wrapped in multipart/related part
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/PhishingDetection/LinkCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function run(string $htmlMessage) : PhishingDetectionResult {
}
}
}
if (count($results) > 0) {
if ($results !== []) {
return new PhishingDetectionResult(PhishingDetectionResult::LINK_CHECK, true, $this->l10n->t('Some addresses in this message are not matching the link text'), $results);
}
return new PhishingDetectionResult(PhishingDetectionResult::LINK_CHECK, false);
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/Provisioning/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function provision(): int {
$counter = 0;

$configs = $this->getConfigs();
if (count($configs) === 0) {
if ($configs === []) {
return $counter;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/SnoozeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private function wakeMessagesByAccount(Account $account): void {
$now,
);

if (count($messages) === 0) {
if ($messages === []) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Nextcloud\Rector\Set\NextcloudSets;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector;
Expand All @@ -32,4 +33,5 @@
)
->withRules([
AddTestsVoidReturnTypeWhereNoReturnRector::class,
CountArrayToEmptyArrayComparisonRector::class,
]);
2 changes: 1 addition & 1 deletion tests/Unit/Db/ActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use OCA\Mail\Db\Actions;
use PHPUnit\Framework\TestCase;

class ActionsTest extends TestCase {
final class ActionsTest extends TestCase {
private Actions $entity;

protected function setUp(): void {
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Db/MessageSnoozeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use OCA\Mail\Db\MessageSnooze;
use PHPUnit\Framework\TestCase;

class MessageSnoozeTest extends TestCase {
final class MessageSnoozeTest extends TestCase {
private MessageSnooze $entity;

protected function setUp(): void {
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Db/TextBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use OCA\Mail\Db\TextBlock;
use PHPUnit\Framework\TestCase;

class TextBlockTest extends TestCase {
final class TextBlockTest extends TestCase {
private TextBlock $entity;

protected function setUp(): void {
Expand Down Expand Up @@ -104,8 +104,8 @@ public function testSetJsonSerializeWithSpecialCharacters(): void {

$this->assertSame('user+tag@domain.com', $json['owner']);
$this->assertSame('Test "quoted" & special chars', $json['title']);
$this->assertStringContainsString('<html>', $json['content']);
$this->assertStringContainsString('🎉', $json['preview']);
$this->assertStringContainsString('<html>', (string)$json['content']);
$this->assertStringContainsString('🎉', (string)$json['preview']);
Comment on lines +107 to +108
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting $json['content'] and $json['preview'] to string weakens the type check this test is implicitly making (it will coerce non-strings rather than failing with a clear type mismatch). Prefer asserting these entries are strings (or using assertSame with expected strings) instead of casting.

Suggested change
$this->assertStringContainsString('<html>', (string)$json['content']);
$this->assertStringContainsString('🎉', (string)$json['preview']);
$this->assertIsString($json['content']);
$this->assertStringContainsString('<html>', $json['content']);
$this->assertIsString($json['preview']);
$this->assertStringContainsString('🎉', $json['preview']);

Copilot uses AI. Check for mistakes.
}

public function testMultipleSetCallsOverwriteValue(): void {
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Events/BeforeImapClientCreatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class BeforeImapClientCreatedTest extends TestCase {
public function testConstructorAndGetter(): void {
$account = $this->createMock(Account::class);
$account = $this->createStub(Account::class);

$event = new BeforeImapClientCreated($account);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Events/BeforeMessageDeletedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class BeforeMessageDeletedEventTest extends TestCase {
public function testConstructorAndGetters(): void {
$account = $this->createMock(Account::class);
$account = $this->createStub(Account::class);
$folderId = 'INBOX';
$messageId = 123;

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Events/DraftMessageCreatedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

class DraftMessageCreatedEventTest extends TestCase {
public function testConstructorAndGetters(): void {
$account = $this->createMock(Account::class);
$draft = $this->createMock(Message::class);
$account = $this->createStub(Account::class);
$draft = $this->createStub(Message::class);

$event = new DraftMessageCreatedEvent($account, $draft);

Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/Events/DraftSavedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

class DraftSavedEventTest extends TestCase {
public function testConstructorWithAllParams(): void {
$account = $this->createMock(Account::class);
$newMessageData = $this->createMock(NewMessageData::class);
$draft = $this->createMock(Message::class);
$account = $this->createStub(Account::class);
$newMessageData = $this->createStub(NewMessageData::class);
$draft = $this->createStub(Message::class);

$event = new DraftSavedEvent($account, $newMessageData, $draft);

Expand All @@ -29,7 +29,7 @@ public function testConstructorWithAllParams(): void {
}

public function testConstructorWithoutOptionalParams(): void {
$account = $this->createMock(Account::class);
$account = $this->createStub(Account::class);

$event = new DraftSavedEvent($account);

Expand All @@ -39,8 +39,8 @@ public function testConstructorWithoutOptionalParams(): void {
}

public function testConstructorWithPartialParams(): void {
$account = $this->createMock(Account::class);
$newMessageData = $this->createMock(NewMessageData::class);
$account = $this->createStub(Account::class);
$newMessageData = $this->createStub(NewMessageData::class);

$event = new DraftSavedEvent($account, $newMessageData);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Events/MailboxesSynchronizedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class MailboxesSynchronizedEventTest extends TestCase {
public function testConstructorAndGetter(): void {
$account = $this->createMock(Account::class);
$account = $this->createStub(Account::class);

$event = new MailboxesSynchronizedEvent($account);

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Events/MessageDeletedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

class MessageDeletedEventTest extends TestCase {
public function testConstructorAndGetters(): void {
$account = $this->createMock(Account::class);
$mailbox = $this->createMock(Mailbox::class);
$account = $this->createStub(Account::class);
$mailbox = $this->createStub(Mailbox::class);
$messageId = 42;

$event = new MessageDeletedEvent($account, $mailbox, $messageId);
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Events/MessageFlaggedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

class MessageFlaggedEventTest extends TestCase {
public function testConstructorAndGetters(): void {
$account = $this->createMock(Account::class);
$mailbox = $this->createMock(Mailbox::class);
$account = $this->createStub(Account::class);
$mailbox = $this->createStub(Mailbox::class);
$uid = 12345;
$flag = 'Seen';
$set = true;
Expand All @@ -32,8 +32,8 @@ public function testConstructorAndGetters(): void {
}

public function testFlagUnset(): void {
$account = $this->createMock(Account::class);
$mailbox = $this->createMock(Mailbox::class);
$account = $this->createStub(Account::class);
$mailbox = $this->createStub(Mailbox::class);
$uid = 99999;
$flag = 'Flagged';
$set = false;
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Events/MessageSentEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

class MessageSentEventTest extends TestCase {
public function testConstructorAndGetters(): void {
$account = $this->createMock(Account::class);
$localMessage = $this->createMock(LocalMessage::class);
$account = $this->createStub(Account::class);
$localMessage = $this->createStub(LocalMessage::class);

$event = new MessageSentEvent($account, $localMessage);

Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Events/NewMessagesSynchronizedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

class NewMessagesSynchronizedTest extends TestCase {
public function testConstructorAndGetters(): void {
$account = $this->createMock(Account::class);
$mailbox = $this->createMock(Mailbox::class);
$account = $this->createStub(Account::class);
$mailbox = $this->createStub(Mailbox::class);
$messages = [
$this->createMock(Message::class),
$this->createMock(Message::class),
Expand All @@ -33,8 +33,8 @@ public function testConstructorAndGetters(): void {
}

public function testConstructorWithEmptyMessages(): void {
$account = $this->createMock(Account::class);
$mailbox = $this->createMock(Mailbox::class);
$account = $this->createStub(Account::class);
$mailbox = $this->createStub(Mailbox::class);
$messages = [];

$event = new NewMessagesSynchronized($account, $mailbox, $messages);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Events/OutboxMessageCreatedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

class OutboxMessageCreatedEventTest extends TestCase {
public function testConstructorAndGetters(): void {
$account = $this->createMock(Account::class);
$message = $this->createMock(Message::class);
$account = $this->createStub(Account::class);
$message = $this->createStub(Message::class);

$event = new OutboxMessageCreatedEvent($account, $message);

Expand Down
Loading
Loading