Completed
Push — master ( d129c8...00172d )
by Gabriel
03:56
created

HandleExceptions::reportException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Nip\Http\Kernel\Traits;
4
5
use Exception;
6
use Nip\Http\Exceptions\Handler;
7
use Nip\Http\Response\Response;
8
use Nip\Request;
9
use Psr\Http\Message\ResponseInterface;
10
use Psr\Http\Message\ServerRequestInterface;
11
12
/**
13
 * Trait HandleExceptions
14
 * @package Nip\Http\Kernel\Traits
15
 */
16
trait HandleExceptions
17
{
18
    /**
19
     * Report the exception to the exception handler.
20
     *
21
     * @param Exception $e
22
     * @return void
23
     */
24
    protected function reportException(Exception $e)
25
    {
26
        app('log')->error($e);
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

26
        /** @scrutinizer ignore-call */ 
27
        app('log')->error($e);
Loading history...
27
    }
28
29
    /**
30
     * @param Request|ServerRequestInterface $request
31
     * @param Exception $e
32
     * @return Response|ResponseInterface
33
     */
34
    protected function renderException($request, Exception $e)
35
    {
36
        return (new Handler($this->getContainer()))->render($request, $e);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Nip\Http\Exce...)->render($request, $e) returns the type Symfony\Component\HttpFoundation\JsonResponse which is incompatible with the documented return type Nip\Http\Response\Respon...ssage\ResponseInterface.
Loading history...
Bug introduced by
It seems like getContainer() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

36
        return (new Handler($this->/** @scrutinizer ignore-call */ getContainer()))->render($request, $e);
Loading history...
37
    }
38
39
    /**
40
     * @param Exception $e
41
     * @param Request|ServerRequestInterface $request
42
     * @return Response
43
     */
44
    protected function handleException($request, Exception $e)
45
    {
46
        $this->reportException($e);
47
48
        return $this->renderException($request, $e);
49
    }
50
}
51