Handler::render()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 8
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 3
nc 2
nop 2
crap 12
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
'fondbot.webhook' of type string is incompatible with the type Illuminate\Http\dynamic expected by parameter $patterns of Illuminate\Http\Request::routeIs(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
        if (!$e instanceof HttpException && $request->routeIs(/** @scrutinizer ignore-type */ 'fondbot.webhook')) {
Loading history...
23
            return 'Something went wrong.';
0 ignored issues
show
Bug Best Practice introduced by
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