I'm trying to make a custom console exception work and noticed the docs don't fully line up. When I tried making the renderForConsole(OutputInterface $output, Throwable $e) like the api, phpstorm gave an error: method must be compatible with ExceptionHandler->renderForConsole etc.
Is it common for these to not exactly match? Or is the OutputInterface used by Throwable? I searched that file but could not see a reference.
So the problem here is that you type-hint OutputInterface here, while the code in Laravel Framework does not do this. Because of that, they seem to be incompatible.
So the docs are correct about the type because the docblocks are implemented correctly.
/**
* Render an exception to the console.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Throwable $e
* @return void
*/
public function renderForConsole($output, Throwable $e);
So if this was type-hinted as well, you wouldn't have this issue.
Ok, so the doc block essentially visually "cleans up" the method in the () but calls the same interface?
In my particular file there are no doc blocks and they are not suggested by phpstorm for some reason.
Just trying to understand why the docs say public function renderForConsole($output, Throwable $exception); exception is fully spelled out but the api states $e or does it even matter?
Not that you would - but could it be Throwable $z and still work?
@trevorpan The thing is that the type hinting needs to match with the parent method. I believe you can change the variable names if you wish.
In this case, the parent method provided by Laravle only type-hints Throwable, so that on is required. The OutputInterface is not type-hinted, so if you add it to your method it doesn't match with the parent anymore and it fails.
If you add the type-hint, you're saying the same as the docblock but than the inheritance doesn't match anymore. It would be better if Laravel would type-hint the OutputInterface interface here as well in the end. However, that is a breaking change.
Well - for sure this new tool I picked up Larastan is causing me to look more at this level of detail. Just an excellent leveling up - still think I'll need another year or so to really get it.
As always thank you!
Where's my laravel secrets? You know I'm waiting for that to become available!!