Skip to content
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

Adds support for fixing missing throws doc block #7994

Merged
merged 4 commits into from Jul 12, 2022
Merged

Conversation

aszenz
Copy link
Contributor

@aszenz aszenz commented May 21, 2022

Fixes #7918

@orklah orklah added the release:feature The PR will be included in 'Features' section of the release notes label May 21, 2022
@orklah
Copy link
Collaborator

orklah commented May 21, 2022

Cool! That looks nice!

If you target 4.x, you must keep compatibility with PHP 7.1 though. Can you check this and the other CI failure?

Could you also add a test case with two different exceptions, to check the docblock rendering?

'<?php
/**
* @throws InvalidArgumentException|DomainException
* @throws Exception
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 preserve the existing throws annotation and add a new one based on inference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the fix will always add a new throws annotation which can have Exception1|Exception2 syntax, but not modify existing one

@@ -719,6 +725,8 @@ public function analyze(
}

if (!$is_expected) {
assert(class_exists($possibly_thrown_exception));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should i keep this assert or remove it, it makes sense for throws keyword to only contain classes which exist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ideally this check would not be needed, but that means modifying the return type for the function getUncaughtThrows which would be a bigger change

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please drop it. It's risky because classes could be stubbed or inserted through a Plugin so you can't guarantee they'll exists for Psalm to autoload

['MissingThrowsDocblock'],
true,
],
'doesNotAddDuplicateThrows' => [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This validates that the fix only adds exceptions which are not listed in the current throws doc block

@orklah
Copy link
Collaborator

orklah commented May 23, 2022

Seems fine to me, if you mark this as ready, I'm up to merge it :)

@aszenz aszenz marked this pull request as ready for review May 23, 2022 19:07
@aszenz
Copy link
Contributor Author

aszenz commented Jul 12, 2022

@orklah Can this be merged or is it something to do still

@orklah
Copy link
Collaborator

orklah commented Jul 12, 2022

Sorry :( I didn't get a notification on the status change! Thanks!

@orklah orklah merged commit 416b597 into vimeo:4.x Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature The PR will be included in 'Features' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for auto fixing missing throws doc block errors
2 participants