-
Notifications
You must be signed in to change notification settings - Fork 67
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
Naively change the case of method identifiers to comply with PSR-1 #63
Naively change the case of method identifiers to comply with PSR-1 #63
Conversation
I didn't realize that PHP itself isn't consistent with the casing of magic methods ( |
I think this could be useful, but there should probably be a way to opt-in or opt-out using an attribute. I can help you with that if you want (it's basically the same as the rest of the impl attributes, see here). Let me know what you guys think. |
@davidcole1340 I'll give it a shot. Its a good idea. |
Added an attribute that allows for some limited control over casing. Only implemented camelCase and snake_case: #[php_impl]
impl Test {
#[rename("snake_case")]
pub fn get_first_name(&self) -> String {
// ...
}
#[rename("camelCase")]
pub fn get_last_name(&self) -> String {
// ...
}
} Looks like If this is acceptable, let me know and I'll put a blurb in the docs as well. |
d9699ff
to
ff2ecc8
Compare
I honestly don't like the naming. A new user will think that their method will be renamed to literally Also, I would have preferred a global attribute for that. I doubt that users will want to switch case to only a few methods. |
Honestly, I think I agree. Not sure how a global attribute would look as I don't think I've come across a library where I've used them. But as I was putting this together I was thinking just having rename be a bit more straightforward could be better: |
Yeah, rename with an identifier is good. Could also do |
I kept it with "snake_case" and "camcelCase" to keep it consistent with other rust packages (e.g. serde, async-graphql). That said, as much as I've just appealed to how others do this, they don't do it with a
|
Add an attribute to methods to control the name they're exported under and an attribute to php_impl to override automatic case conversion conventions.
Default to camel case renaming
Thanks! |
I'd be surprised if the patch will be taken in this form, but I'm willing to put the effort in to getting this in should there be interest.
Rust loves using snake_case for functions, but to comply with PSR-1, methods should be in camelCase. This patch tries to change the case of methods generated through the
php_impl
macro.As for precedence for changing the case of identifiers via macros, both juniper and async-graphql do this.