Skip to content

Conversation

garsaud
Copy link
Contributor

@garsaud garsaud commented Oct 18, 2022

I added a few more classes with constant values, so instead of writing this :

$draftCardRegistration = new CardRegistration();
$draftCardRegistration->Currency = CurrencyIso::EUR; // ← constant already existed for this one
$draftCardRegistration->CardType = 'CB_VISA_MASTERCARD'; // ← but not for that one

we can use the dedicated constants :

$cardRegistration = new CardRegistration();
$cardRegistration->Currency = CurrencyIso::EUR;
$cardRegistration->CardType = CardType::CbVisaMastercard;

This will avoid keeping hardcoded values in the logic, avoid risks of typographical error, and improve clarity by showing the possible values for a parameter.

I used the official documentation, which often gives types and possible values, although those types didn’t exist yet in the SDK:

Official documentation showing ‘CardType’ and ‘CurrencyIso’, which don’t accually exist yet

@garsaud garsaud force-pushed the improved-clarity-with-constants branch 2 times, most recently from 8e1158f to 03dda3c Compare October 18, 2022 14:35
@garsaud garsaud force-pushed the improved-clarity-with-constants branch 2 times, most recently from a90eb84 to fe707e0 Compare October 26, 2022 11:00
@garsaud
Copy link
Contributor Author

garsaud commented Nov 24, 2022

@iulian03 Hi! Is it possible to merge this PR?

@psociety
Copy link

psociety commented Apr 5, 2023

@iulian03 ping

* CardType { CB_VISA_MASTERCARD, AMEX }
* CardType
* @var string
* @see \MangoPay\CardType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @see \MangoPay\CardType
* @see \MangoPay\CardType
* @phpstan-var \MangoPay\CardType::*

This will allow tools like phpstan to warn the dev when not using the enum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants