Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2021-09-29 10:47:37 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-09-29 10:53:56 +0300
commitaa43aa5c0eb5cecbc638d2c4b1d0fef2b07b8306 (patch)
treef59393cd75d5fe8df5f78d5d0863aeb55f70b013 /lib
parentf429b095f99420d7f88360fe205dbf31a7335e07 (diff)
Make the sync response generic so it can hold two types of messages
We use the same container class for two purposes, once for the IMAPMessage class, then for Message. Psalm rightfully complains that we can't make assumptions of the returned polymorphic types, so it makes sense to just type it as a generic class and let Psalm derive the specialized type based on the constructor usage. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/IMAP/Sync/Response.php31
1 files changed, 12 insertions, 19 deletions
diff --git a/lib/IMAP/Sync/Response.php b/lib/IMAP/Sync/Response.php
index 820ef7baf..a1e47675b 100644
--- a/lib/IMAP/Sync/Response.php
+++ b/lib/IMAP/Sync/Response.php
@@ -24,16 +24,17 @@ declare(strict_types=1);
namespace OCA\Mail\IMAP\Sync;
use JsonSerializable;
-use OCA\Mail\Db\Message;
use OCA\Mail\IMAP\MailboxStats;
-use OCA\Mail\Model\IMAPMessage;
+/**
+ * @psalm-template T
+ */
class Response implements JsonSerializable {
- /** @var IMAPMessage[]|Message[] */
+ /** @var T[] */
private $newMessages;
- /** @var IMAPMessage[]|Message[] */
+ /** @var T[] */
private $changedMessages;
/** @var int[] */
@@ -43,14 +44,14 @@ class Response implements JsonSerializable {
private $stats;
/**
- * @param IMAPMessage[]|Message[] $newMessages
- * @param IMAPMessage[]|Message[] $changedMessages
+ * @param T[] $newMessages
+ * @param T[] $changedMessages
* @param int[] $vanishedMessageUids
* @param MailboxStats|null $stats
*/
- public function __construct(array $newMessages = [],
- array $changedMessages = [],
- array $vanishedMessageUids = [],
+ public function __construct(array $newMessages,
+ array $changedMessages,
+ array $vanishedMessageUids,
MailboxStats $stats = null) {
$this->newMessages = $newMessages;
$this->changedMessages = $changedMessages;
@@ -59,14 +60,14 @@ class Response implements JsonSerializable {
}
/**
- * @return IMAPMessage[]|Message[]
+ * @return T[]
*/
public function getNewMessages(): array {
return $this->newMessages;
}
/**
- * @return IMAPMessage[]|Message[]
+ * @return T[]
*/
public function getChangedMessages(): array {
return $this->changedMessages;
@@ -94,12 +95,4 @@ class Response implements JsonSerializable {
'stats' => $this->stats,
];
}
-
- public function merge(Response $other): self {
- return new self(
- array_merge($this->getNewMessages(), $other->getNewMessages()),
- array_merge($this->getChangedMessages(), $other->getChangedMessages()),
- array_merge($this->getVanishedMessageUids(), $other->getVanishedMessageUids())
- );
- }
}