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

HandleExceptions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 33
ccs 0
cts 8
cp 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A reportException() 0 3 1
A renderException() 0 3 1
A handleException() 0 5 1
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