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: 1
level: 2
ignoreErrors:
-
identifier: new.static
Expand Down
2 changes: 1 addition & 1 deletion src/Collections/PaginatedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* @template TKey of array-key
*
* @template-covariant TValue
* @template TValue
*
* @template-extends Collection<TKey, TValue>
*/
Expand Down
6 changes: 4 additions & 2 deletions src/HasParsedMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Carbon\CarbonInterface;
use DirectoryTree\ImapEngine\Exceptions\RuntimeException;
use GuzzleHttp\Psr7\Utils;
use ZBateson\MailMimeParser\Header\DateHeader;
use ZBateson\MailMimeParser\Header\HeaderConsts;
use ZBateson\MailMimeParser\Header\IHeader;
use ZBateson\MailMimeParser\Header\IHeaderPart;
Expand All @@ -27,8 +28,9 @@ trait HasParsedMessage
*/
public function date(): ?CarbonInterface
{
if ($date = $this->header(HeaderConsts::DATE)?->getDateTime()) {
return Carbon::instance($date);
$dateHeader = $this->header(HeaderConsts::DATE);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I mean. That's my prefered approach. Runtime checking for the right instance

if ($dateHeader instanceof DateHeader) {
return Carbon::instance($dateHeader->getDateTime());
}

return null;
Expand Down
5 changes: 4 additions & 1 deletion src/Idle.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Carbon\CarbonInterface;
use Closure;
use DirectoryTree\ImapEngine\Connection\Responses\UntaggedResponse;
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
use DirectoryTree\ImapEngine\Exceptions\Exception;
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionClosedException;
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionTimedOutException;
Expand Down Expand Up @@ -59,7 +60,9 @@ protected function listen(callable $callback, CarbonInterface $ttl): void
continue;
}

if ($response->tokenAt(2)?->is('EXISTS')) {
$possibleExistsToken = $response->tokenAt(2);

if ($possibleExistsToken instanceof Atom && $possibleExistsToken->is('EXISTS')) {
$msgn = (int) $response->tokenAt(1)->value;

$callback($msgn);
Expand Down
9 changes: 8 additions & 1 deletion src/MessageQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
use DirectoryTree\ImapEngine\Collections\ResponseCollection;
use DirectoryTree\ImapEngine\Connection\ConnectionInterface;
use DirectoryTree\ImapEngine\Connection\ImapQueryBuilder;
use DirectoryTree\ImapEngine\Connection\Responses\Data\ListData;
use DirectoryTree\ImapEngine\Connection\Responses\UntaggedResponse;
use DirectoryTree\ImapEngine\Connection\Tokens\Token;
use DirectoryTree\ImapEngine\Enums\ImapFetchIdentifier;
use DirectoryTree\ImapEngine\Enums\ImapFlag;
use DirectoryTree\ImapEngine\Exceptions\ImapCommandException;
use DirectoryTree\ImapEngine\Exceptions\RuntimeException;
use DirectoryTree\ImapEngine\Pagination\LengthAwarePaginator;
use DirectoryTree\ImapEngine\Support\Str;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -189,7 +191,8 @@ public function findOrFail(int $id, ImapFetchIdentifier $identifier = ImapFetchI
public function find(int $id, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): ?MessageInterface
{
/** @var UntaggedResponse $response */
if (! $response = $this->id($id, $identifier)->first()) {
$response = $this->id($id, $identifier)->first();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And that's your approach. I changed it to have $response directly at the DocTag. It's easier to understand this way... and PHPStan understands it this way

if (! $response) {
return null;
}

Expand Down Expand Up @@ -294,6 +297,10 @@ protected function fetch(Collection $messages): array
return $this->connection()->fetch($fetch, $uids->all())->mapWithKeys(function (UntaggedResponse $response) {
$data = $response->tokenAt(3);

if (!$data instanceof ListData) {
Copy link
Contributor Author

@CReimer CReimer Sep 27, 2025

Choose a reason for hiding this comment

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

I'm not sure as of right now how you approach exceptions. This is more or less a third approach. For the same problem. -> method returns parent, but specific child is expected

Copy link
Member

Choose a reason for hiding this comment

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

Yea I think this is a good approach -- best to throw an exception here like you've implemented 👍

throw new RuntimeException("Invalid data type at index 3");
}

$uid = $data->lookup('UID')->value;

return [
Expand Down
2 changes: 1 addition & 1 deletion src/Pagination/LengthAwarePaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @template TKey of array-key
*
* @template-covariant TValue
* @template TValue
*
* @template-implements Arrayable<TKey, TValue>
*/
Expand Down