GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

HoneybadgerContext::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 7
c 3
b 0
f 0
dl 0
loc 13
rs 10
cc 3
nc 3
nop 2
1
<?php
2
3
namespace Honeybadger\HoneybadgerLaravel\Middleware;
4
5
use Closure;
6
use Honeybadger\Contracts\Reporter;
7
use Illuminate\Support\Facades\Route;
8
9
/**
10
 * @deprecated Honeybadger adds the context automatically
11
 */
12
class HoneybadgerContext
13
{
14
    /**
15
     * @var \Honeybadger\Honeybadger;
16
     */
17
    protected $honeybadger;
18
19
    /**
20
     * @param  \Honeybadger\Contracts\Reporter  $honeybadger
21
     */
22
    public function __construct(Reporter $honeybadger)
23
    {
24
        $this->honeybadger = $honeybadger;
0 ignored issues
show
Documentation Bug introduced by
$honeybadger is of type Honeybadger\Contracts\Reporter, but the property $honeybadger was declared to be of type Honeybadger\Honeybadger. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
25
    }
26
27
    /**
28
     * Handle an incoming request.
29
     *
30
     * @param  \Illuminate\Http\Request  $request
31
     * @param  \Closure  $next
32
     * @return mixed
33
     */
34
    public function handle($request, Closure $next)
35
    {
36
        if (app()->bound('honeybadger')) {
37
            $this->setUserContext($request);
38
39
            if (app('honeybadger.isLumen')) {
40
                $this->setLumenRouteActionContext($request);
41
            } else {
42
                $this->setRouteActionContext();
43
            }
44
        }
45
46
        return $next($request);
47
    }
48
49
    private function setLumenRouteActionContext($request)
50
    {
51
        $routeDetails = app()->router->getRoutes()[$request->method().$request->getPathInfo()]['action'];
52
53
        if (! isset($routeDetails['uses']) && ! empty($routeDetails[0])) {
54
            $this->honeybadger->setComponent(get_class($routeDetails[0]));
55
56
            return;
57
        }
58
59
        $routeAction = explode('@', $routeDetails['uses']);
60
61
        if (! empty($routeAction[0])) {
62
            $this->honeybadger->setComponent($routeAction[0] ?? '');
63
        }
64
65
        if (! empty($routeAction[1])) {
66
            $this->honeybadger->setAction($routeAction[1] ?? '');
67
        }
68
    }
69
70
    private function setRouteActionContext()
71
    {
72
        if (Route::getCurrentRoute()) {
73
            $routeAction = explode('@', Route::getCurrentRoute()->getActionName());
74
75
            if (! empty($routeAction[0])) {
76
                $this->honeybadger->setComponent($routeAction[0] ?? '');
77
            }
78
79
            if (! empty($routeAction[1])) {
80
                $this->honeybadger->setAction($routeAction[1] ?? '');
81
            }
82
        }
83
    }
84
85
    private function setUserContext($request)
86
    {
87
        try {
88
            if ($request->user()) {
89
                $this->honeybadger->context(
90
                    'user_id',
91
                    $request->user()->getAuthIdentifier()
92
                );
93
            }
94
        } catch (\InvalidArgumentException $e) {
95
            // swallow
96
        }
97
    }
98
}
99