Skip to content

Commit 267ace7

Browse files
authored
Merge pull request #112 from CReimer/phpstan-level-2
Implement PHPStan up to level 2
2 parents 2ff6ed6 + 8ef7776 commit 267ace7

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 1
2+
level: 2
33
ignoreErrors:
44
-
55
identifier: new.static

src/Collections/PaginatedCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* @template TKey of array-key
1010
*
11-
* @template-covariant TValue
11+
* @template TValue
1212
*
1313
* @template-extends Collection<TKey, TValue>
1414
*/

src/HasParsedMessage.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Carbon\CarbonInterface;
77
use DirectoryTree\ImapEngine\Exceptions\RuntimeException;
88
use GuzzleHttp\Psr7\Utils;
9+
use ZBateson\MailMimeParser\Header\DateHeader;
910
use ZBateson\MailMimeParser\Header\HeaderConsts;
1011
use ZBateson\MailMimeParser\Header\IHeader;
1112
use ZBateson\MailMimeParser\Header\IHeaderPart;
@@ -27,8 +28,9 @@ trait HasParsedMessage
2728
*/
2829
public function date(): ?CarbonInterface
2930
{
30-
if ($date = $this->header(HeaderConsts::DATE)?->getDateTime()) {
31-
return Carbon::instance($date);
31+
$dateHeader = $this->header(HeaderConsts::DATE);
32+
if ($dateHeader instanceof DateHeader) {
33+
return Carbon::instance($dateHeader->getDateTime());
3234
}
3335

3436
return null;

src/Idle.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Carbon\CarbonInterface;
77
use Closure;
88
use DirectoryTree\ImapEngine\Connection\Responses\UntaggedResponse;
9+
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
910
use DirectoryTree\ImapEngine\Exceptions\Exception;
1011
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionClosedException;
1112
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionTimedOutException;
@@ -59,7 +60,9 @@ protected function listen(callable $callback, CarbonInterface $ttl): void
5960
continue;
6061
}
6162

62-
if ($response->tokenAt(2)?->is('EXISTS')) {
63+
$possibleExistsToken = $response->tokenAt(2);
64+
65+
if ($possibleExistsToken instanceof Atom && $possibleExistsToken->is('EXISTS')) {
6366
$msgn = (int) $response->tokenAt(1)->value;
6467

6568
$callback($msgn);

src/MessageQuery.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
use DirectoryTree\ImapEngine\Collections\ResponseCollection;
77
use DirectoryTree\ImapEngine\Connection\ConnectionInterface;
88
use DirectoryTree\ImapEngine\Connection\ImapQueryBuilder;
9+
use DirectoryTree\ImapEngine\Connection\Responses\Data\ListData;
910
use DirectoryTree\ImapEngine\Connection\Responses\UntaggedResponse;
1011
use DirectoryTree\ImapEngine\Connection\Tokens\Token;
1112
use DirectoryTree\ImapEngine\Enums\ImapFetchIdentifier;
1213
use DirectoryTree\ImapEngine\Enums\ImapFlag;
1314
use DirectoryTree\ImapEngine\Exceptions\ImapCommandException;
15+
use DirectoryTree\ImapEngine\Exceptions\RuntimeException;
1416
use DirectoryTree\ImapEngine\Pagination\LengthAwarePaginator;
1517
use DirectoryTree\ImapEngine\Support\Str;
1618
use Illuminate\Support\Collection;
@@ -189,7 +191,8 @@ public function findOrFail(int $id, ImapFetchIdentifier $identifier = ImapFetchI
189191
public function find(int $id, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): ?MessageInterface
190192
{
191193
/** @var UntaggedResponse $response */
192-
if (! $response = $this->id($id, $identifier)->first()) {
194+
$response = $this->id($id, $identifier)->first();
195+
if (! $response) {
193196
return null;
194197
}
195198

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

300+
if (!$data instanceof ListData) {
301+
throw new RuntimeException("Invalid data type at index 3");
302+
}
303+
297304
$uid = $data->lookup('UID')->value;
298305

299306
return [

src/Pagination/LengthAwarePaginator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* @template TKey of array-key
1212
*
13-
* @template-covariant TValue
13+
* @template TValue
1414
*
1515
* @template-implements Arrayable<TKey, TValue>
1616
*/

0 commit comments

Comments
 (0)