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

Use \Stripe\<class>::class constant instead of strings #643

Merged
merged 1 commit into from
May 21, 2019
Merged

Use \Stripe\<class>::class constant instead of strings #643

merged 1 commit into from
May 21, 2019

Conversation

nickdnk
Copy link
Contributor

@nickdnk nickdnk commented Apr 26, 2019

I figured since we've dropped 5.5 in v7 we might as well do this. Unless of course there's a reason not to that I'm not aware of.

@nickdnk nickdnk changed the title Use constants in object to classmap Use constants in object-to-class map Apr 26, 2019
@nickdnk
Copy link
Contributor Author

nickdnk commented Apr 26, 2019

Visually we could go with:

\Stripe\Account::OBJECT_NAME              => \Stripe\Account::class,
\Stripe\AccountLink::OBJECT_NAME          => \Stripe\AccountLink::class,
\Stripe\AlipayAccount::OBJECT_NAME        => \Stripe\AlipayAccount::class,
\Stripe\ApplePayDomain::OBJECT_NAME       => \Stripe\ApplePayDomain::class,
\Stripe\ApplicationFee::OBJECT_NAME       => \Stripe\ApplicationFee::class,
\Stripe\Balance::OBJECT_NAME              => \Stripe\Balance::class,

Like all other constant lists, if you prefer. Not that it matters, but if we're changing this anyway.

EDIT: I did this. Looks cleaner as brandur said.

@brandur-stripe
Copy link
Contributor

Looks way cleaner to me — thanks for the follow up @nickdnk!

I'll leave merge decision up to Olivier.

ptal @ob-stripe

@ob-stripe
Copy link
Contributor

Nice! Yeah, this seems like a strict improvement.

@nickdnk There are a few other places where we use strings for class names, mind updating these too? If not I can take as a followup.

@nickdnk
Copy link
Contributor Author

nickdnk commented Apr 26, 2019

@ob-stripe Could you point me in the direction of those? I can't really find anything of this kind elsewhere.

@nickdnk
Copy link
Contributor Author

nickdnk commented Apr 26, 2019

I just alphabetised the list based on the constant names instead of the OBJECT_NAME value, now that there are no strings in the list.

@ob-stripe
Copy link
Contributor

@nickdnk In the library itself, I think the only other place where we use strings for class names is in the class_alias() call in lib/FileUpload.php.

There are a lot more class name strings in tests though, mostly in assertInstanceOf() calls. Can you take fixing those as well? If not I can take. Hopefully it's just a few search and replaces!

@nickdnk
Copy link
Contributor Author

nickdnk commented Apr 30, 2019

I updated the constants I could find in tests, but I cannot find lib/FileUpload.php?

@ob-stripe
Copy link
Contributor

@nickdnk Here:

class_alias('Stripe\\File', 'Stripe\\FileUpload');

@nickdnk
Copy link
Contributor Author

nickdnk commented Apr 30, 2019

@ob-stripe
This file doesn't exist on this branch. lib/File exists but doesn't use class_alias.

@ob-stripe
Copy link
Contributor

@nickdnk 🤦‍♂ Sorry, I forgot I removed it for the next major version. Don't mind me. Thanks for updating everything else!

@nickdnk
Copy link
Contributor Author

nickdnk commented Apr 30, 2019

@ob-stripe No problem.

Let me know when you're satisfied and I'll squash to one commit and reword it.

@nickdnk nickdnk changed the title Use constants in object-to-class map Use \Stripe\<class>::class constant instead of strings Apr 30, 2019
@nickdnk
Copy link
Contributor Author

nickdnk commented May 21, 2019

Squashed to single commit.

Copy link
Contributor

@ob-stripe ob-stripe left a comment

Choose a reason for hiding this comment

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

Thanks Nick!

@ob-stripe ob-stripe self-assigned this May 21, 2019
@ob-stripe ob-stripe merged commit 26144f1 into stripe:integration-v7 May 21, 2019
@ob-stripe ob-stripe mentioned this pull request May 21, 2019
26 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants