Passed
Push — master ( d7d8c0...c26592 )
by Mads
03:35
created

ApiHandler::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 14
nc 3
nop 2
dl 0
loc 22
ccs 0
cts 11
cp 0
crap 12
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Napp\Core\Api\Exceptions;
4
5
use Exception;
6
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
7
use Napp\Core\Api\Exceptions\Exceptions\ApiInternalCallValidationException;
8
9
class ApiHandler extends ExceptionHandler
10
{
11
    /**
12
     * @param \Illuminate\Http\Request $request
13
     * @param \Exception $e
14
     * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
15
     */
16
    public function render($request, Exception $e)
17
    {
18
        if (true === app()->isDownForMaintenance()) {
0 ignored issues
show
introduced by
The method isDownForMaintenance() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

18
        if (true === app()->/** @scrutinizer ignore-call */ isDownForMaintenance()) {
Loading history...
19
            return response()->json([
20
                'error' => [
21
                    'code' => 503,
22
                    'message' => 'Service is down for scheduled maintenance. Be right back!'
23
                ]
24
            ], 503);
25
        }
26
27
        if (true === $e instanceof ApiInternalCallValidationException) {
28
            $response = response([
0 ignored issues
show
Bug introduced by
array('error' => array('...> 'Validation failed')) of type array<string,array<string,integer|string>> is incompatible with the type string expected by parameter $content of response(). ( Ignorable by Annotation )

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

28
            $response = response(/** @scrutinizer ignore-type */ [
Loading history...
29
                'error' => [
30
                    'code' => 215,
31
                    'message' => 'Validation failed']
32
            ], 400);
33
34
            return $response->withException($e);
0 ignored issues
show
Bug introduced by
The method withException() does not exist on Symfony\Component\HttpFoundation\Response. It seems like you code against a sub-type of Symfony\Component\HttpFoundation\Response such as Illuminate\Http\Response or Illuminate\Http\JsonResponse or Illuminate\Http\RedirectResponse. ( Ignorable by Annotation )

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

34
            return $response->/** @scrutinizer ignore-call */ withException($e);
Loading history...
35
        }
36
37
        return (new NappApiHandler($e))->render();
38
    }
39
}
40