-
Notifications
You must be signed in to change notification settings - Fork 850
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
Use traits for API operations methods #411
Conversation
lib/Account.php
Outdated
use ApiOperations\Create; | ||
use ApiOperations\Update; | ||
use ApiOperations\Delete; | ||
use ApiOperations\All; |
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.
Minor, but maybbeeee consider alphabetizing this lists just so that we have stable sorting if new traits are added down the line.
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.
Yeah, good point. Done :)
+1 million. This is awesome! Maybe the one large-ish thing I noticed: when you pull in one of the new traits, it assumes the existence presence of a method on its new host like (And to be fair, I think the same thing is happening in languages like Ruby already.) I don't think this will be that much of a problem in practice, and I'm having trouble coming up with specific recommendations. We could try moving You could check for the presence of methods you're about to use like Anyway, probably not a big deal, but wanted to bring it up for a little discussion. |
472fac9
to
e8754e1
Compare
e8754e1
to
2ecba66
Compare
Yeah, this is something that crossed my mind as well. Unfortunately PHP does not have a syntax to ensure that a trait is only applied to instances of a certain class, so the only way to enforce this would be to check at runtime. I will add some PHPDoc to each trait to explicitly flag that these traits can and should only be applied to classes that derive from |
2ecba66
to
3616c43
Compare
Cool. Sounds reasonable. Thanks for taking a look! |
3616c43
to
2a5d478
Compare
Use traits for API operations methods
r? @brandur-stripe
cc @stripe/api-libraries
Traits are a feature available in PHP 5.4+. Now that we're dropping support for PHP <5.4, we can start using traits to factorize code.
This PR adds traits for common API operations methods (CRUD + list).