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

[10.x] When should return the callback value rather than the conditionable object #44724

Closed
wants to merge 3 commits into from
Closed

[10.x] When should return the callback value rather than the conditionable object #44724

wants to merge 3 commits into from

Conversation

eduance
Copy link
Contributor

@eduance eduance commented Oct 25, 2022

This PR addresses the issue in #44712

When using the when() on the Collection instance, it used the null-coalescing operator to return the conditionable concern rather than simply returning the callback.

This caused multiple issues, for example;

        $collection = collect([
            ['name' => 'John'],
            ['name' => 'Paul'],
        ]);

        $value = $collection->when(true, fn ($collection) => $collection->firstWhere('name', 'Taylor'); ); 

This causes the value to be null, leaving the null-coalescing operator to return the $this; which was not really the expected behavior. You would want the value to just return whatever the method returns you instead.

This could be a really nice upgrade for 10.x so the when method doesn't all of a sudden take over the responsibility of returning the correct value.

eduance and others added 3 commits July 18, 2022 12:44
…ncy with similar methods like updateQuietly, saveQuietly.
…decrementquietly-public

Make incrementQuietly and decrementQuietly public to enforce consiste…
…but rather instead use initial value to enforce consistency
@eduance eduance closed this Oct 25, 2022
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.

1 participant