Passed
Push — stable ( cff678...1149ad )
by Nuno
10:30
created

ExceptionHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 74
ccs 19
cts 21
cp 0.9048
rs 10
c 0
b 0
f 0

5 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
A shouldReport() 0 4 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 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 6
    public function __construct(Application $app, ExceptionHandlerContract $appExceptionHandler)
50
    {
51 6
        $this->app = $app;
52 6
        $this->appExceptionHandler = $appExceptionHandler;
53 6
    }
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 1
    public function render($request, Exception $e)
67
    {
68 1
        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
    /**
91
     * Determine if the exception should be reported.
92
     *
93
     * @param  \Exception  $e
94
     * @return bool
95
     */
96
    public function shouldReport(Exception $e)
97
    {
98
        return $this->appExceptionHandler->shouldReport($e);
0 ignored issues
show
Bug introduced by
The method shouldReport() does not exist on Illuminate\Contracts\Debug\ExceptionHandler. Did you maybe mean report()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
99
    }
100
}
101