XerviceExceptionHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 36
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 21 3
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Service\Lumen\ExceptionHandler;
6
7
8
use DataProvider\ApiExceptionDataProvider;
0 ignored issues
show
Bug introduced by
The type DataProvider\ApiExceptionDataProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Exception;
10
use Illuminate\Http\JsonResponse;
11
use Illuminate\Http\Response;
12
use Laravel\Lumen\Exceptions\Handler;
13
use Xervice\Core\Exception\XerviceException;
14
use Xervice\Core\Locator\Dynamic\DynamicLocator;
15
16
17
class XerviceExceptionHandler extends Handler
18
{
19
    use DynamicLocator;
20
21
    protected $dontReport = [
22
        XerviceException::class
23
    ];
24
25
    /**
26
     * @param \Illuminate\Http\Request $request
27
     * @param \Exception $e
28
     *
29
     * @return \Illuminate\Http\Response
30
     * @throws \Core\Locator\Dynamic\ServiceNotParseable
31
     */
32
    public function render($request, Exception $e): Response
33
    {
34
        $dataProvider = new ApiExceptionDataProvider();
35
        $dataProvider->setStatus($e->getCode())
36
            ->setException(get_class($e))
37
            ->setMessage($e->getMessage());
38
39
        if ($this->getFacade()->isDebug()) {
0 ignored issues
show
Bug introduced by
The method isDebug() does not exist on Xervice\Core\Facade\FacadeInterface. It seems like you code against a sub-type of Xervice\Core\Facade\FacadeInterface such as Xervice\Service\ServiceFacade. ( Ignorable by Annotation )

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

39
        if ($this->getFacade()->/** @scrutinizer ignore-call */ isDebug()) {
Loading history...
40
            $dataProvider->setTrace($e->getTraceAsString());
41
        }
42
43
        $response = new JsonResponse();
44
        if (method_exists($e, 'getStatusCode')) {
45
            $response->setStatusCode($e->getStatusCode());
46
        } else {
47
            $response->setStatusCode(500);
48
        }
49
50
        $response->setData($dataProvider->toArray());
51
52
        return $response;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response returns the type Illuminate\Http\JsonResponse which is incompatible with the type-hinted return Illuminate\Http\Response.
Loading history...
53
    }
54
55
56
}