Skip to content

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

Merged
taylorotwell merged 4 commits into
laravel:9.xfrom
WendellAdriel:increment-custom-cast-issue
Jan 2, 2023
Merged

[9.x] fixed issue on which class to check increment and decrement methods for custom cast#45444
taylorotwell merged 4 commits into
laravel:9.xfrom
WendellAdriel:increment-custom-cast-issue

Conversation

@WendellAdriel

Copy link
Copy Markdown
Member

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

Sjord commented Dec 29, 2022

Copy link
Copy Markdown
Contributor

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

@WendellAdriel

Copy link
Copy Markdown
Member 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
Copy Markdown
Member

I think a test would be good here.


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

Copy link
Copy Markdown

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
Copy Markdown
Member Author

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

@WendellAdriel

Copy link
Copy Markdown
Member 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