Unnecessary closure?
Closed this issue · 2 comments
Is the closure required here? Can't $serverRequestErrorResponseGenerator
be assigned directly to $this->serverRequestErrorResponseGenerator
?
laminas-httphandlerrunner/src/RequestHandlerRunner.php
Lines 77 to 80 in e3d1b45
This assignment is done to provide type-safety. By wrapping it in a closure, you'll know as soon as it is invoked if the $serverRequestErrorResponseGenerator
returns anything other than a ResponseInterface
— as the code consuming that callable requires that return type.
Basically, it's a way for us to guarantee type safety without requiring an interface to provide the signature.
Just a note here, I've removed that dedicated callable in v2 and added it to the __construct
psalm annotation.
When using psalm in upstream projects, this will lead to a static-code-analysis error rather than a runtime error.