Skip to content
Merged
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 phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 2
level: 3
ignoreErrors:
-
identifier: new.static
Expand Down
7 changes: 4 additions & 3 deletions src/Collections/MessageCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

namespace DirectoryTree\ImapEngine\Collections;

use DirectoryTree\ImapEngine\Message;
use DirectoryTree\ImapEngine\MessageInterface;

/**
* @template-extends PaginatedCollection<array-key, \DirectoryTree\ImapEngine\MessageInterface|\DirectoryTree\ImapEngine\Message>
* @template-extends PaginatedCollection<array-key, MessageInterface|Message>
*/
class MessageCollection extends PaginatedCollection
{
/**
* Find a message by its UID.
*
* @return \DirectoryTree\ImapEngine\Message|null
* @return MessageInterface|null
*/
public function find(int $uid): ?MessageInterface
{
Expand All @@ -24,7 +25,7 @@ public function find(int $uid): ?MessageInterface
/**
* Find a message by its UID or throw an exception.
*
* @return \DirectoryTree\ImapEngine\Message
* @return MessageInterface
*/
public function findOrFail(int $uid): MessageInterface
{
Expand Down
6 changes: 5 additions & 1 deletion src/Collections/ResponseCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
use Illuminate\Support\Collection;

/**
* @template-extends Collection<array-key, Response>
* @template TKey of array-key
*
* @template-covariant TValue
*
* @extends Collection<array-key, TValue>
*/
class ResponseCollection extends Collection
{
Expand Down
5 changes: 4 additions & 1 deletion src/Connection/ImapConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ protected function newTokenizer(StreamInterface $stream): ImapTokenizer
*/
protected function assertTaggedResponse(string $tag, ?callable $exception = null): TaggedResponse
{
return $this->assertNextResponse(
/** @var TaggedResponse $response */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a bit unhappy with this one. Everything says It is "TaggedResponse", but the method signature of assertNextResponse is too complex for PHPStan to understand it directly. This way we do a type coercion and return it afterwards. I don't see a cleaner solution for this, without significantly changing how assert*Response works.

Copy link
Member

Choose a reason for hiding this comment

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

This is totally fine with me! 👍

$response = $this->assertNextResponse(
fn (Response $response) => (
$response instanceof TaggedResponse && $response->tag()->is($tag)
),
Expand All @@ -712,6 +713,8 @@ protected function assertTaggedResponse(string $tag, ?callable $exception = null
ImapCommandException::make($this->result->command(), $response)
),
);

return $response;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/HasParsedMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
use ZBateson\MailMimeParser\Header\Part\AddressPart;
use ZBateson\MailMimeParser\Header\Part\ContainerPart;
use ZBateson\MailMimeParser\Header\Part\NameValuePart;
use ZBateson\MailMimeParser\Message as MailMimeMessage;
use ZBateson\MailMimeParser\IMessage;
use ZBateson\MailMimeParser\Message\IMessagePart;

trait HasParsedMessage
{
/**
* The parsed message.
*/
protected ?MailMimeMessage $parsed = null;
protected ?IMessage $parsed = null;

/**
* Get the message date and time.
Expand Down Expand Up @@ -224,7 +224,7 @@ public function header(string $name, int $offset = 0): ?IHeader
/**
* Parse the message into a MailMimeMessage instance.
*/
public function parse(): MailMimeMessage
public function parse(): IMessage
{
if ($this->isEmpty()) {
throw new RuntimeException('Cannot parse an empty message');
Expand Down
3 changes: 2 additions & 1 deletion src/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Carbon\CarbonInterface;
use Stringable;
use ZBateson\MailMimeParser\Header\IHeader;
use ZBateson\MailMimeParser\IMessage;
use ZBateson\MailMimeParser\Message as MailMimeMessage;

interface MessageInterface extends FlaggableInterface, Stringable
Expand Down Expand Up @@ -117,7 +118,7 @@ public function header(string $name, int $offset = 0): ?IHeader;
/**
* Parse the message into a MailMimeMessage instance.
*/
public function parse(): MailMimeMessage;
public function parse(): IMessage;

/**
* Determine if the message is the same as another message.
Expand Down
3 changes: 2 additions & 1 deletion src/MessageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace DirectoryTree\ImapEngine;

use ZBateson\MailMimeParser\IMessage;
use ZBateson\MailMimeParser\MailMimeParser;
use ZBateson\MailMimeParser\Message as MailMimeMessage;

Expand All @@ -15,7 +16,7 @@ class MessageParser
/**
* Parse the given message contents.
*/
public static function parse(string $contents): MailMimeMessage
public static function parse(string $contents): IMessage
{
return static::parser()->parse($contents, true);
}
Expand Down
10 changes: 5 additions & 5 deletions src/MessageQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function count(): int
/**
* Get the first message in the resulting collection.
*
* @return Message|null
* @return MessageInterface|null
*/
public function first(): ?MessageInterface
{
Expand All @@ -58,7 +58,7 @@ public function first(): ?MessageInterface
/**
* Get the first message in the resulting collection or throw an exception.
*
* @return Message
* @return MessageInterface
*/
public function firstOrFail(): MessageInterface
{
Expand All @@ -82,7 +82,7 @@ public function append(string $message, mixed $flags = null): int
$this->folder->path(), $message, Str::enums($flags),
);

return $response // TAG4 OK [APPENDUID <uidvalidity> <uid>] APPEND completed.
return (int) $response // TAG4 OK [APPENDUID <uidvalidity> <uid>] APPEND completed.
->tokenAt(2) // [APPENDUID <uidvalidity> <uid>]
->tokenAt(2) // <uid>
->value;
Expand Down Expand Up @@ -169,7 +169,7 @@ public function paginate(int $perPage = 5, $page = null, string $pageName = 'pag
/**
* Find a message by the given identifier type or throw an exception.
*
* @return Message
* @return MessageInterface
*/
public function findOrFail(int $id, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): MessageInterface
{
Expand All @@ -186,7 +186,7 @@ public function findOrFail(int $id, ImapFetchIdentifier $identifier = ImapFetchI
/**
* Find a message by the given identifier type.
*
* @return Message|null
* @return MessageInterface|null
*/
public function find(int $id, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): ?MessageInterface
{
Expand Down
8 changes: 4 additions & 4 deletions src/MessageQueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ public function count(): int;
/**
* Get the first message in the resulting collection.
*
* @return \DirectoryTree\ImapEngine\Message|null
* @return MessageInterface|null
*/
public function first(): ?MessageInterface;

/**
* Get the first message in the resulting collection or throw an exception.
*
* @return \DirectoryTree\ImapEngine\Message
* @return MessageInterface
*/
public function firstOrFail(): MessageInterface;

Expand Down Expand Up @@ -168,14 +168,14 @@ public function paginate(int $perPage = 5, $page = null, string $pageName = 'pag
/**
* Find a message by the given identifier type or throw an exception.
*
* @return \DirectoryTree\ImapEngine\Message
* @return MessageInterface
*/
public function findOrFail(int $id, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): MessageInterface;

/**
* Find a message by the given identifier type.
*
* @return \DirectoryTree\ImapEngine\Message|null
* @return MessageInterface|null
*/
public function find(int $id, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): ?MessageInterface;

Expand Down