Skip to content

[9.x] fixed issue on which class to check increment and decrement methods for custom cast #45444

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

Merged
merged 4 commits into from
Jan 2, 2023

Conversation

WendellAdriel
Copy link
Contributor

This fix is related to the issue mentioned on #45418
The code was checking if the increment/decrement methods were available on one class but then using another class to actually call the methods. This fix is for the code to check the same class that will be called the methods.

@Sjord
Copy link
Contributor

Sjord commented Dec 29, 2022

Wouldn't it be better to just call the existing resolveCasterClass method?

@WendellAdriel
Copy link
Contributor Author

I see your point @Sjord

But the resolveCasterClass will resolve the class while in the code I wrote it's going to only check if the castUsing is present and get the class from it without creating an instance of the class.

I'm fine with both solutions tho. I'll just wait for someone to review it and if needed I can update it.
Thanks for the help 😉

@taylorotwell
Copy link
Member

I think a test would be good here.


$castType = $this->parseCasterClass($this->getCasts()[$key]);
if (method_exists($castType, 'castUsing')) {
$castType = $castType::castUsing([]);

Choose a reason for hiding this comment

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

Wouldn't calling the "castUsing" method with an empty array disregards any given cast parameters?

@WendellAdriel
Copy link
Contributor Author

@taylorotwell I'll work on the test
@sumihiran I'm going to check your observation

@WendellAdriel
Copy link
Contributor Author

@taylorotwell I made some changes:

@WendellAdriel WendellAdriel marked this pull request as ready for review December 30, 2022 11:55
@taylorotwell taylorotwell merged commit 19ac2b4 into laravel:9.x Jan 2, 2023
@WendellAdriel WendellAdriel deleted the increment-custom-cast-issue branch January 2, 2023 15:35
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.

4 participants