Skip to content
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

Added constant classes to improve clarity, avoid typos and be informed of possible values #573

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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

* @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