Completed
Push — stable ( 40e75b...0ef583 )
by Nuno
21:47 queued 05:32
created

ExceptionHandler   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 33.33%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 7
c 6
b 0
f 0
lcom 1
cbo 6
dl 0
loc 67
ccs 7
cts 21
cp 0.3333
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 9 3
A renderForConsole() 0 14 2
A __construct() 0 5 1
A report() 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 NunoMaduro\Collision\Provider;
16
use Illuminate\Contracts\Foundation\Application;
17
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
18
use NunoMaduro\Collision\Contracts\Adapters\Phpunit\Listener as ListenerContract;
19
use Symfony\Component\Console\Exception\ExceptionInterface as SymfonyConsoleExceptionInterface;
20
21
/**
22
 * This is an Collision Laravel Adapter ExceptionHandler implementation.
23
 *
24
 * Registers the Error Handler on Laravel.
25
 *
26
 * @author Nuno Maduro <[email protected]>
27
 */
28
class ExceptionHandler implements ExceptionHandlerContract
29
{
30
    /**
31
     * Holds an instance of the application exception handler.
32
     *
33
     * @var \Illuminate\Contracts\Debug\ExceptionHandler
34
     */
35
    protected $appExceptionHandler;
36
37
    /**
38
     * Holds an instance of the application.
39
     *
40
     * @var \Illuminate\Contracts\Foundation\Application
41
     */
42
    protected $app;
43
44
    /**
45
     * Creates a new instance of the ExceptionHandler.
46
     *
47
     * @param \Illuminate\Contracts\Foundation\Application $app
48
     * @param \Illuminate\Contracts\Debug\ExceptionHandler $appExceptionHandler
49
     */
50 4
    public function __construct(Application $app, ExceptionHandlerContract $appExceptionHandler)
51
    {
52 4
        $this->app = $app;
53 4
        $this->appExceptionHandler = $appExceptionHandler;
54 4
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 2
    public function report(Exception $e)
60
    {
61 2
        $this->appExceptionHandler->report($e);
62 2
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function render($request, Exception $e)
68
    {
69
        if ($this->app->environment() === 'testing' && $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...
70
            $this->app->make(ListenerContract::class)
71
                ->render($e);
72
        }
73
74
        return $this->appExceptionHandler->render($request, $e);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function renderForConsole($output, Exception $e)
81
    {
82
        if ($e instanceof SymfonyConsoleExceptionInterface) {
83
            $this->appExceptionHandler->renderForConsole($output, $e);
84
        } else {
85
            $handler = (new Provider)->register()
86
                ->getHandler()
87
                ->setOutput($output);
88
89
            $handler->setInspector((new Inspector($e)));
90
91
            $handler->handle();
92
        }
93
    }
94
}
95