Skip to content

Commit

Permalink
Type-hint appropriate arguments
Browse files Browse the repository at this point in the history
Some methods accepting `$request` and `$response` as arguments did not have the appropriate type hints, although the dockblock tags were suggesting these classes.

This makes user mistakes hard to debug. For example:

I did a mistake in my `Exceptions\Handler.php` of returning a `View` instead of a `Response` instance.

```
public function render(Request $request, Exception $e) {
    if ($e instanceof NotFoundHttpException) {
        return view('my.custom.404');
    }
}
```

The output was `exception 'BadMethodCallException' with message 'Method [isRedirection] does not exist on view.'`.
`LaravelDebugbar` is calling `isRedirection()` on a `$response` argument, but there has no check if that argument was indeed a `Response` instance.

By typehinting those arguments we can prevent this kind of errors and make the package less error-prone.
  • Loading branch information
sebdesign committed Oct 24, 2015
1 parent 23672cb commit 3ff50bd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public function getJavascriptRenderer($baseUrl = null, $basePath = null)
* @param \Symfony\Component\HttpFoundation\Response $response
* @return \Symfony\Component\HttpFoundation\Response
*/
public function modifyResponse($request, $response)
public function modifyResponse(Request $request, Response $response)
{
$app = $this->app;
if ($app->runningInConsole() || !$this->isEnabled() || $this->isDebugbarRequest()) {
Expand Down Expand Up @@ -593,7 +593,7 @@ protected function isDebugbarRequest()
* @param \Symfony\Component\HttpFoundation\Request $request
* @return bool
*/
protected function isJsonRequest($request)
protected function isJsonRequest(Request $request)
{
// If XmlHttpRequest, return true
if ($request->isXmlHttpRequest()) {
Expand Down Expand Up @@ -841,7 +841,7 @@ protected function selectStorage(DebugBar $debugbar)
}
}

protected function addClockworkHeaders($response)
protected function addClockworkHeaders(Response $response)
{
$prefix = $this->app['config']->get('debugbar.route_prefix');
$response->headers->set('X-Clockwork-Id', $this->getCurrentRequestId(), true);
Expand Down

0 comments on commit 3ff50bd

Please sign in to comment.