Test Failed
Pull Request — stable (#58)
by Fractal
02:20
created

ExceptionHandler::convertThrowable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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\Foundation\Application;
15
use NunoMaduro\Collision\Contracts\Provider as ProviderContract;
16
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
17
use Symfony\Component\Console\Exception\ExceptionInterface as SymfonyConsoleExceptionInterface;
18
19
/**
20
 * This is an Collision Laravel Adapter ExceptionHandler implementation.
21
 *
22
 * Registers the Error Handler on Laravel.
23
 *
24
 * @author Nuno Maduro <[email protected]>
25
 */
26
class ExceptionHandler implements ExceptionHandlerContract
27
{
28
    /**
29
     * Holds an instance of the application exception handler.
30
     *
31
     * @var \Illuminate\Contracts\Debug\ExceptionHandler
32
     */
33
    protected $appExceptionHandler;
34
35
    /**
36
     * Holds an instance of the application.
37
     *
38
     * @var \Illuminate\Contracts\Foundation\Application
39
     */
40
    protected $app;
41
42
    /**
43
     * Creates a new instance of the ExceptionHandler.
44
     *
45
     * @param \Illuminate\Contracts\Foundation\Application $app
46
     * @param \Illuminate\Contracts\Debug\ExceptionHandler $appExceptionHandler
47
     */
48 4
    public function __construct(Application $app, ExceptionHandlerContract $appExceptionHandler)
49
    {
50 4
        $this->app = $app;
51 4
        $this->appExceptionHandler = $appExceptionHandler;
52 4
    }
53
54
    /**
55
     * Converts \Throwable to \Exception.
56
     *
57
     * @param  \Throwable|\Exception $e
58
     *
59
     * @return \Exception
60
     */
61
    protected function convertThrowable($e)
62
    {
63
        return ($e instanceof \Throwable) ? new \Exception($e->getMessage(), $e->getCode(), $e) : $e;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function report($e)
70
    {
71
        $this->appExceptionHandler->report(
72
            $this->convertThrowable($e)
73
        );
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function render($request, $e)
80
    {
81
        return $this->appExceptionHandler->render(
82
            $request, $this->convertThrowable($e)
83
        );
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89 2
    public function renderForConsole($output, $e)
90
    {
91 2
        if ($e instanceof SymfonyConsoleExceptionInterface) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\Consol...tion\ExceptionInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
92 1
            $this->appExceptionHandler->renderForConsole($output, $e);
93
        } else {
94 1
            $handler = $this->app->make(ProviderContract::class)
95 1
                ->register()
96 1
                ->getHandler()
97 1
                ->setOutput($output);
98
99 1
            $handler->setInspector((new Inspector($e)));
100
101 1
            $handler->handle();
102
        }
103 2
    }
104
105
    /**
106
     * Determine if the exception should be reported.
107
     *
108
     * @param  \Exception  $e
109
     * @return bool
110
     */
111
    public function shouldReport($e)
112
    {
113
        return $this->appExceptionHandler->shouldReport($e);
114
    }
115
}
116