Description
👋 Hello PHP community, we are looking for community feedback on improvement we are working on.
We are extending type hints that exist in Stripe-PHP SDK. New type hints will be compatible with PHPStan. Type hint improvements we are planning to implement so far:
Create/Update/Retrieve/Delete/All/Search parameters
Existing parameters array in Stripe functions do not specify the keys of the array.
* @param null|array $params
After the changes, you will be able to know the keys that you can pass without switching out of your IDE.
* @param null|array{customer:string, components: array} $params
You will see hints in IDE(PHPStorm used in screenshot below) when writing array parameters for the Stripe API methods.
Class properties
We will change the type of class properties from StripeObject
to something more specific.
For example: Invoice settings is defined as a StripeObject in Customer resource.
Line 25 in bae10cd
After adding phpstan types in PHP docs, you will be able to call custom_fields
and rendering_options
on customer->invoice_settings
without PHPStan complaining.
// New
/**
* @phpstan-type CustomerInvoiceSettingsCustomField object{name: string, value: string}&StripeObject
* @phpstan-type CustomerInvoiceSettingsRenderingOptions object{amount_tax_display?: string, template?: string}&StripeObject
* @phpstan-type CustomerInvoiceSettings object{custom_fields: array<CustomerInvoiceSettingsCustomField>, rendering_options: CustomerInvoiceSettingsRenderingOptions}&StripeObject
*
* @property null|CustomerInvoiceSettings $invoice_settings
*/
Conclusion
Existing users shouldn't be affected by our addition of types in PHPDocs. These additions will improve development experience for you.
If you have more ideas about what you would like to see in our PHP SDK regarding types and type hinting, please add your suggestions in this thread.
Activity