-
-
Notifications
You must be signed in to change notification settings - Fork 22
Implement PHPStan up to level 2 #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| parameters: | ||
| level: 1 | ||
| level: 2 | ||
| ignoreErrors: | ||
| - | ||
| identifier: new.static | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
|
|
||
|
|
@@ -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) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 [ | ||
|
|
||
There was a problem hiding this comment.
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