recurly-client-php icon indicating copy to clipboard operation
recurly-client-php copied to clipboard

Add Enum constants to resource classes

Open willselby opened this issue 4 years ago • 2 comments

Would it be possible to have the relevant enum values added as constants to the resource classes please?

Similar to what Stripe has; https://github.com/stripe/stripe-php/blob/0aa6a385e66ffe7e095372737d8afe491a94e015/lib/Invoice.php#L130

This saves us having to do string comparisons when we want to check the value of a property. e.g. if ($invoice->state === 'paid') becomes if ($invoice->state === \Recurly\Resources\Invoice::STATE_PAID)

  • if the value is ever changed we don't need to update string comparisons in multiple places.
  • IDE can flag that the constant doesn't exist if one is removed or mis-typed.

I'd be happy to open a PR, but your contribution guidelines clearly state that you won't accept any PR's that modify resource files.

Thank you.

willselby avatar Jul 09 '20 15:07 willselby

@willselby We 100% agree with your reasoning for enum support. We should have enums in these places rather than strings.

I'd be happy to open a PR, but your contribution guidelines clearly state that you won't accept any PR's that modify resource files.

That's correct, that's the bad news. The good news is that we are already working on adding enum support into our code generator and we have it working for at least one other language. The same process which generates the resources from the OpenAPI spec will also generate, maintain, and document the enums for us. We've been holding off on implementing it because it's a breaking change for some languages, but we're going to be rolling it this quarter.

I'll leave this ticket open for now as a point of discussion. As soon as the code is ready in a branch, we'll come back here to ask for feedback. I'll try to prioritize getting PHP ready over the other languages since you've asked about it.

bhelx avatar Jul 09 '20 16:07 bhelx

That's great, thanks a lot!

willselby avatar Jul 09 '20 16:07 willselby