Completed
Push — stable ( 1a9a26...6db3dc )
by Nuno
02:54 queued 01:02
created

ExceptionHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 89.47%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 5
c 7
b 0
f 0
lcom 1
cbo 3
dl 0
loc 63
ccs 17
cts 19
cp 0.8947
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A report() 0 4 1
A render() 0 4 1
A renderForConsole() 0 15 2
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 Exception;
15
use Illuminate\Contracts\Foundation\Application;
16
use NunoMaduro\Collision\Contracts\Provider as ProviderContract;
17
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
18
use Symfony\Component\Console\Exception\ExceptionInterface as SymfonyConsoleExceptionInterface;
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 application.
38
     *
39
     * @var \Illuminate\Contracts\Foundation\Application
40
     */
41
    protected $app;
42
43
    /**
44
     * Creates a new instance of the ExceptionHandler.
45
     *
46
     * @param \Illuminate\Contracts\Foundation\Application $app
47
     * @param \Illuminate\Contracts\Debug\ExceptionHandler $appExceptionHandler
48
     */
49 5
    public function __construct(Application $app, ExceptionHandlerContract $appExceptionHandler)
50
    {
51 5
        $this->app = $app;
52 5
        $this->appExceptionHandler = $appExceptionHandler;
53 5
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 1
    public function report(Exception $e)
59
    {
60 1
        $this->appExceptionHandler->report($e);
61 1
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function render($request, Exception $e)
67
    {
68
        return $this->appExceptionHandler->render($request, $e);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 2
    public function renderForConsole($output, Exception $e)
75
    {
76 2
        if ($e instanceof SymfonyConsoleExceptionInterface) {
77 1
            $this->appExceptionHandler->renderForConsole($output, $e);
78
        } else {
79 1
            $handler = $this->app->make(ProviderContract::class)
80 1
                ->register()
81 1
                ->getHandler()
82 1
                ->setOutput($output);
83
84 1
            $handler->setInspector((new Inspector($e)));
85
86 1
            $handler->handle();
87
        }
88 2
    }
89
}
90