ExceptionHandler::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
/**
4
 * This file is part of Collision.
5
 *
6
 * (c) Nuno Maduro <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace NunoMaduro\Collision\Adapters\Laravel;
13
14
use Illuminate\Contracts\Container\Container;
15
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
16
use NunoMaduro\Collision\Contracts\Provider as ProviderContract;
17
use Symfony\Component\Console\Exception\ExceptionInterface as SymfonyConsoleExceptionInterface;
18
use Throwable;
19
20
/**
21
 * This is an Collision Laravel Adapter ExceptionHandler implementation.
22
 *
23
 * Registers the Error Handler on Laravel.
24
 *
25
 * @author Nuno Maduro <[email protected]>
26
 */
27
class ExceptionHandler implements ExceptionHandlerContract
28
{
29
    /**
30
     * Holds an instance of the application exception handler.
31
     *
32
     * @var \Illuminate\Contracts\Debug\ExceptionHandler
33
     */
34
    protected $appExceptionHandler;
35
36
    /**
37
     * Holds an instance of the container.
38
     *
39
     * @var \Illuminate\Contracts\Container\Container
40
     */
41
    protected $container;
42
43
    /**
44
     * Creates a new instance of the ExceptionHandler.
45
     */
46 6
    public function __construct(Container $container, ExceptionHandlerContract $appExceptionHandler)
47
    {
48 6
        $this->container           = $container;
49 6
        $this->appExceptionHandler = $appExceptionHandler;
50 6
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 1
    public function report(Throwable $e)
56
    {
57 1
        $this->appExceptionHandler->report($e);
58 1
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 1
    public function render($request, Throwable $e)
64
    {
65 1
        return $this->appExceptionHandler->render($request, $e);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 2
    public function renderForConsole($output, Throwable $e)
72
    {
73 2
        if ($e instanceof SymfonyConsoleExceptionInterface) {
74 1
            $this->appExceptionHandler->renderForConsole($output, $e);
75
        } else {
76 1
            $handler = $this->container->make(ProviderContract::class)
77 1
                ->register()
78 1
                ->getHandler()
79 1
                ->setOutput($output);
80
81 1
            $handler->setInspector((new Inspector($e)));
82
83 1
            $handler->handle();
84
        }
85 2
    }
86
87
    /**
88
     * Determine if the exception should be reported.
89
     *
90
     * @return bool
91
     */
92
    public function shouldReport(Throwable $e)
93
    {
94
        return $this->appExceptionHandler->shouldReport($e);
95
    }
96
}
97