Completed
Push — stable ( 9156b2...b71e94 )
by Nuno
01:46
created

src/Adapters/Laravel/ExceptionHandler.php (1 issue)

Labels
Severity
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
    public function __construct(Application $app, ExceptionHandlerContract $appExceptionHandler)
51
    {
52
        $this->app = $app;
53
        $this->appExceptionHandler = $appExceptionHandler;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function report(Exception $e)
60
    {
61
        $this->appExceptionHandler->report($e);
62
    }
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
The method shouldReport() does not exist on Illuminate\Contracts\Debug\ExceptionHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        if ($this->app->environment() === 'testing' && $this->appExceptionHandler->/** @scrutinizer ignore-call */ shouldReport($e)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

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