Skip to content

phpdocs for exceptions #605

Description

@nickdnk

Hello guys

As I'm sure most of you maintainers are aware of, I'm a big fan of phpdocs and use it extensively in my code. I am well aware that annotation changes nothing at runtime, but I find it very helpful in determining if I am missing a return type, not handling an exception, passing a wrong type and so on when I'm coding and reviewing my code.

Now, after you made the change to use traits (I think it was major version 5?), the phpdocs for thrown exceptions are all out of whack because of the shared methods used across (as far as I can tell) most requests.

For me, this results in a lot of this:

} /** @noinspection PhpRedundantCatchClauseInspection */ catch (\Stripe\Error\Base $e) {

    // I have to include above notation to avoid warnings.

}

And if I don't include this comment, PHPStorm gives me a "redundant catch phrase" error, which, if I erroneously should accept this suggestion, would result in a working catch block being removed entirely. Not so great.

So, I tried to "start from the bottom" (of traits) to include all exceptions everywhere they are thrown. This of course results in all requests throwing almost all exceptions - which is simply incorrect; such as retrieving a customer then claims it can throw \Stripe\Error\Card. Not a good solution.

Would it be possible to somehow at the very least have InvalidRequest, Card, and Base added in cases where these errors can be thrown? So that we have to handle (or silence) Base, which I'm under the impression any endpoint can throw, and which would of course also catch any other unexpected exception (RateLimiting, Authentication etc.). If so, how could we do this? I would be happy to put in the work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions