Skip to content

Improve PHPDoc block parameter typing in Exceptions::dontReportWhen() #56439

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 2 commits into from
Jul 27, 2025

Conversation

shaedrich
Copy link
Contributor

Follow-up to #56435

@AhmedAlaa4611
Copy link
Contributor

I think you need also to take a look for this:

/**
* Register a callback to determine if an exception should not be reported.
*
* @param callable $dontReportWhen
* @return $this
*/
public function dontReportWhen(callable $dontReportWhen)
{
if (! $dontReportWhen instanceof Closure) {
$dontReportWhen = Closure::fromCallable($dontReportWhen);
}
$this->dontReportCallbacks[] = $dontReportWhen;
return $this;
}

@shaedrich
Copy link
Contributor Author

@AhmedAlaa4611 What exactly do you mean with this?

@AhmedAlaa4611
Copy link
Contributor

I think -but not sure- that we may need to update the corresponding one. What do you think about that?

@shaedrich
Copy link
Contributor Author

Ah, right—thanks for the hint 👍🏻

@AhmedAlaa4611
Copy link
Contributor

Sorry, other question. Should we use \Closure instead of callable?

if (! $dontReportWhen instanceof Closure) {
$dontReportWhen = Closure::fromCallable($dontReportWhen);
}

we checks if the $dontReportWhen is not an instance of the \Closure.

@shaedrich
Copy link
Contributor Author

It looks like it accepts both Closure and other types of callable. Since Closure is a sub type of callable, it doesn't have to be explicitly mentioned. Or am I missing something?

@AhmedAlaa4611
Copy link
Contributor

I'm not sure to be honest, but I think they should be the same either \Closure or callable.

@shaedrich
Copy link
Contributor Author

That would mean to revert #56435

@AhmedAlaa4611
Copy link
Contributor

That would mean to revert #56435

I made that because the $dontReportWhen is type hinted with \Closure.

Now, what we do is:

Illuminate\Foundation\Configuration\Exceptions::dontReportWhen takes the $dontReportWhen as a \Closure then passes it as a callable to the Illuminate\Foundation\Exceptions\Handler::dontReportWhen.

I think we need to refine them but not sure weather to use \Closure or callable

@shaedrich
Copy link
Contributor Author

Well, technically, \Illuminate\Foundation\Exceptions\Handler::dontReportWhen() might also be independently called from somewhere else, resulting in one code path always being a Closure and one code path always being some other callable. If that was true, having Closure type hint on \Illuminate\Foundation\Configuration\Exceptions::dontReportWhen() while having callable type-hint on \Illuminate\Foundation\Exceptions\Handler::dontReportWhen() would be consequential 🤔

@AhmedAlaa4611
Copy link
Contributor

AhmedAlaa4611 commented Jul 27, 2025

I agree with your technical nuance regarding the possibility of different call scenarios. Given that, I’m convinced the current state of this PR handles this appropriately.

Thanks

@shaedrich
Copy link
Contributor Author

Thanks a lot! :)

@taylorotwell taylorotwell merged commit 29426d4 into laravel:12.x Jul 27, 2025
60 checks passed
@shaedrich shaedrich deleted the improve-phpdoc-blocks branch July 27, 2025 20:41
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.

3 participants