-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[11.x] revert #52510 which added a unneeded function call #52526
Conversation
As a disclaimer, I first commented on PR #52510, just checking what changed, and without checking the After revisiting it, I noticed it was unneeded. |
|
I won't tell you what you need to do, it seems you are an adult already, so you should know best how to behave in public spaces, specially in an environment where people are trying to collaborate in their spare time. But I'd advise you to read Laravel's code of conduct: https://laravel.com/docs/11.x/contributions#code-of-conduct And by the way, I've been helping to improve the framework for almost 9 years. Maybe I have learned a thing or two along the way. https://github.com/laravel/framework/pulls?q=is%3Apr+is%3Amerged+author%3Arodrigopedra You are more than welcome to hold any opinion you want, as long as you keep it respectful when sharing it publicly. |
I tend to agree with @rodrigopedra that the original PR doesn't provide anything that the original code already done. But @devajmeireles you should be able to provide a tests example showing where |
An alternative would be simplifying function transform($value, callable $callback, $default = null)
{
if (filled($value)) {
return $callback($value);
}
return value($default, $value);
} But that is technically a breaking change, as current Maybe for 12.x we could consider the |
@rodrigopedra |
@donnysim |
@crynobone yeah yeah, should've quoted what I was responding to, my bad. It's for the
|
@donnysim you are right, thanks for the heads up! |
This PR reverts PR #52510
PR #52510 introduced a call to the
value()
helper on thetransform()
helper's last return.The
value()
helper only checks if the$value
argument is a\Closure
, and if so, invokes it. Otherwise, it returns the plain$value
without any changes:framework/src/Illuminate/Collections/helpers.php
Lines 234 to 237 in 81a0b5b
The
transform()
helper already checks if the$default
value is a callable (which includes the\Closure
case), before the modified line:framework/src/Illuminate/Support/helpers.php
Lines 468 to 479 in 81a0b5b
Therefore, when execution reaches the modified line on PR #52510 we already know
$default
is not a callable, and thus, not a\Closure
.Which renders the modification unneeded, as it only adds a useless function call, and a ternary check, that will always evaluate to
false
and return the unmodified value thevalue()
helper receives.This PR:
value
Function into the$default
value oftransform
helper #52510 to remove the unneededvalue()
call.