Skip to content

Commit e9c71e9

Browse files
committed
Implement PHPStan up to level 4
1 parent 5c84594 commit e9c71e9

File tree

7 files changed

+23
-22
lines changed

7 files changed

+23
-22
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: 3
2+
level: 4
33
ignoreErrors:
44
-
55
identifier: new.static

src/Connection/ImapConnection.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function connect(string $host, ?int $port = null, array $options = []): v
122122

123123
/**
124124
* Get the default socket options for the given transport.
125+
* @param 'ssl'|'tls'|'starttls'|'tcp' $transport
125126
*/
126127
protected function getDefaultSocketOptions(string $transport, array $proxy = [], bool $validateCert = true): array
127128
{
@@ -571,9 +572,7 @@ public function idle(int $timeout): Generator
571572
fn (ContinuationResponse $response) => ImapCommandException::make(new ImapCommand('', 'IDLE'), $response),
572573
);
573574

574-
while ($response = $this->nextReply()) {
575-
yield $response;
576-
}
575+
yield $this->nextReply();
577576
}
578577

579578
/**
@@ -595,6 +594,7 @@ public function done(): void
595594

596595
/**
597596
* Send an IMAP command.
597+
* @param-out string $tag
598598
*/
599599
public function send(string $name, array $tokens = [], ?string &$tag = null): void
600600
{
@@ -727,15 +727,12 @@ protected function assertTaggedResponse(string $tag, ?callable $exception = null
727727
*/
728728
protected function assertNextResponse(callable $filter, callable $assertion, callable $exception): Response
729729
{
730-
while ($response = $this->nextResponse($filter)) {
731-
if ($assertion($response)) {
732-
return $response;
733-
}
734-
735-
throw $exception($response);
730+
$response = $this->nextResponse($filter);
731+
if ($assertion($response)) {
732+
return $response;
736733
}
737734

738-
throw new ImapResponseException('No matching response found');
735+
throw $exception($response);
739736
}
740737

741738
/**
@@ -752,16 +749,15 @@ protected function nextResponse(callable $filter): Response
752749
throw new LogicException('No parser instance set');
753750
}
754751

755-
while ($response = $this->nextReply()) {
756-
if (! $response instanceof Response) {
757-
continue;
758-
}
752+
$response = $this->nextReply();
753+
if (! $response instanceof Response) {
754+
throw new ImapResponseException('Unknown response type: '. $response::class);
755+
}
759756

760-
$this->result?->addResponse($response);
757+
$this->result?->addResponse($response);
761758

762-
if ($filter($response)) {
763-
return $response;
764-
}
759+
if ($filter($response)) {
760+
return $response;
765761
}
766762

767763
throw new ImapResponseException('No matching response found');
@@ -770,7 +766,7 @@ protected function nextResponse(callable $filter): Response
770766
/**
771767
* Read the next reply from the stream.
772768
*/
773-
protected function nextReply(): Data|Token|Response|null
769+
protected function nextReply(): Data|Token|Response
774770
{
775771
if (! $reply = $this->parser->next()) {
776772
$meta = $this->stream->meta();

src/Connection/ImapQueryBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ protected function parseDate(mixed $date): CarbonInterface
373373

374374
/**
375375
* Build a single expression node from a basic or nested where.
376+
* @param array{type: 'basic'|'nested', boolean: 'AND'|'OR', query: ImapQueryBuilder} $where
376377
*/
377378
protected function makeExpressionNode(array $where): array
378379
{
@@ -391,6 +392,7 @@ protected function makeExpressionNode(array $where): array
391392

392393
/**
393394
* Merge the existing expression with the next expression, respecting the boolean operator.
395+
* @param 'AND'|'OR' $boolean
394396
*/
395397
protected function mergeExpressions(string $existing, string $next, string $boolean): string
396398
{

src/FlaggableInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public function hasFlag(BackedEnum|string $flag): bool;
120120

121121
/**
122122
* Add or remove a flag from the message.
123+
* @param '+'|'-' $operation
123124
*/
124125
public function flag(BackedEnum|string $flag, string $operation, bool $expunge = false): void;
125126
}

src/MessageQuery.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ protected function fetch(Collection $messages): array
302302
return [
303303
$uid => [
304304
'flags' => $data->lookup('FLAGS')?->values() ?? [],
305-
'headers' => $data->lookup('[HEADER]')?->value ?? '',
306-
'contents' => $data->lookup('[TEXT]')?->value ?? '',
305+
'headers' => $data->lookup('[HEADER]')->value ?? '',
306+
'contents' => $data->lookup('[TEXT]')->value ?? '',
307307
],
308308
];
309309
})->all();

src/QueriesMessages.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ trait QueriesMessages
4242

4343
/**
4444
* The fetch order.
45+
* @var 'asc'|'desc' $fetchOrder
4546
*/
4647
protected string $fetchOrder = 'desc';
4748

src/Support/Str.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public static function fromImapUtf7(string $string): string
148148

149149
// Direct implementation of IMAP's modified UTF-7 decoding.
150150
return preg_replace_callback('/&([^-]*)-?/', function ($matches) {
151+
/** @var array{0: string, 1: string, 2?: string} $matches */
151152
// If it's just an ampersand.
152153
if ($matches[1] === '') {
153154
return '&';

0 commit comments

Comments
 (0)