1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace FondBot\Framework\Exceptions; |
||
6 | |||
7 | use Exception; |
||
8 | use Symfony\Component\HttpFoundation\Response; |
||
9 | use Symfony\Component\HttpKernel\Exception\HttpException; |
||
10 | use Illuminate\Foundation\Exceptions\Handler as BaseHandler; |
||
11 | |||
12 | class Handler extends BaseHandler |
||
13 | { |
||
14 | /** |
||
15 | * @param \Illuminate\Http\Request $request |
||
16 | * @param Exception $e |
||
17 | * @return \Illuminate\Http\Response|string|Response |
||
18 | */ |
||
19 | public function render($request, Exception $e) |
||
20 | { |
||
21 | // Catch all exceptions if route is webhook |
||
22 | if (!$e instanceof HttpException && $request->routeIs('fondbot.webhook')) { |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
23 | return 'Something went wrong.'; |
||
0 ignored issues
–
show
The expression
return 'Something went wrong.' returns the type string which is incompatible with the return type mandated by Illuminate\Contracts\Deb...eptionHandler::render() of Symfony\Component\HttpFoundation\Response .
In the issue above, the returned value is violating the contract defined by the mentioned interface. Let's take a look at an example: interface HasName {
/** @return string */
public function getName();
}
class Name {
public $name;
}
class User implements HasName {
/** @return string|Name */
public function getName() {
return new Name('foo'); // This is a violation of the ``HasName`` interface
// which only allows a string value to be returned.
}
}
Loading history...
|
|||
24 | } |
||
25 | |||
26 | return parent::render($request, $e); |
||
27 | } |
||
28 | |||
29 | /** {@inheritdoc} */ |
||
30 | protected function renderHttpException(HttpException $e): Response |
||
31 | { |
||
32 | return $this->convertExceptionToResponse($e); |
||
33 | } |
||
34 | } |
||
35 |