ServiceProvider::getWhoopsPrettyHandler()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
namespace MathieuTu\LaravelOpenInEditor;
4
5
use App\Exceptions\Handler;
6
use Illuminate\Contracts\Debug\ExceptionHandler;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
9
use ReflectionMethod;
10
use Whoops\Handler\PrettyPageHandler;
11
12
class ServiceProvider extends LaravelServiceProvider
13
{
14 9
    public function boot()
15
    {
16 9
        if ($this->app['config']->get('app.debug')) {
17 8
            $this->app['router']->get('/__open-in-editor', function (Request $request) {
18 8
                return redirect($this->getEditorLink($request->input('file'), $request->input('line', 0)));
0 ignored issues
show
Documentation introduced by
$request->input('line', 0) is of type string|array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Security Bug introduced by
It seems like $this->getEditorLink($re...uest->input('line', 0)) targeting MathieuTu\LaravelOpenInE...ovider::getEditorLink() can also be of type false; however, redirect() does only seem to accept string|null, did you maybe forget to handle an error condition?
Loading history...
19 8
            });
20
        }
21 9
    }
22
23 8
    protected function getEditorLink($file, $line = 0)
24
    {
25 8
        return $this->getWhoopsPrettyHandler()->getEditorHref($file, $line);
26
    }
27
28 8
    protected function getWhoopsPrettyHandler(): PrettyPageHandler
29
    {
30 8
        return tap(new ReflectionMethod(Handler::class, 'whoopsHandler'))
31 8
            ->setAccessible(true)
32 8
            ->invoke($this->app[ExceptionHandler::class]);
33
    }
34
}
35