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.
Completed
Pull Request — master (#42)
by TJ
01:32
created

HoneybadgerContext::setLumenRouteActionContext()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.3222
c 0
b 0
f 0
cc 5
nc 5
nop 1
1
<?php
2
3
namespace Honeybadger\HoneybadgerLaravel\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use Honeybadger\Contracts\Reporter;
8
use Illuminate\Support\Facades\Route;
9
use App\Providers\AuthServiceProvider;
10
11
class HoneybadgerContext
12
{
13
    /**
14
     * @var \Honeybadger\Honeybadger;
15
     */
16
    protected $honeybadger;
17
18
    /**
19
     * @param  \Honeybadger\Contracts\Reporter  $honeybadger
20
     */
21
    public function __construct(Reporter $honeybadger)
22
    {
23
        $this->honeybadger = $honeybadger;
24
    }
25
26
    /**
27
     * Handle an incoming request.
28
     *
29
     * @param  \Illuminate\Http\Request  $request
30
     * @param  \Closure  $next
31
     * @return mixed
32
     */
33
    public function handle($request, Closure $next)
34
    {
35
        if (app()->bound('honeybadger')) {
36
            $this->setUserContext($request);
37
38
            if (app('honeybadger.isLumen')) {
39
                $this->setLumenRouteActionContext($request);
40
            } else {
41
                $this->setRouteActionContext();
42
            }
43
        }
44
45
        return $next($request);
46
    }
47
48
    private function setLumenRouteActionContext($request)
49
    {
50
        $routeDetails = app()->router->getRoutes()[$request->method().$request->getPathInfo()]['action'];
51
52
        if (!isset($routeDetails['uses']) && !empty($routeAction[0])) {
0 ignored issues
show
Bug introduced by
The variable $routeAction seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
53
            $this->honeybadger->setComponent(get_class($routeDetails[0]));
54
            return;
55
        }
56
57
        $routeAction = explode('@', $routeDetails['uses']);
58
59
        if (! empty($routeAction[0])) {
60
            $this->honeybadger->setComponent($routeAction[0] ?? '');
61
        }
62
63
        if (! empty($routeAction[1])) {
64
            $this->honeybadger->setAction($routeAction[1] ?? '');
65
        }
66
    }
67
68
    private function setRouteActionContext()
69
    {
70
        if (Route::getCurrentRoute()) {
0 ignored issues
show
Bug introduced by
The method getCurrentRoute() does not exist on Illuminate\Support\Facades\Route. Did you maybe mean current()?

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...
71
            $routeAction = explode('@', Route::getCurrentRoute()->getActionName());
0 ignored issues
show
Bug introduced by
The method getCurrentRoute() does not exist on Illuminate\Support\Facades\Route. Did you maybe mean current()?

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...
72
73
            if (! empty($routeAction[0])) {
74
                $this->honeybadger->setComponent($routeAction[0] ?? '');
75
            }
76
77
            if (! empty($routeAction[1])) {
78
                $this->honeybadger->setAction($routeAction[1] ?? '');
79
            }
80
        }
81
    }
82
83
    private function setUserContext($request)
84
    {
85
        if (app()->bound(AuthServiceProvider::class) && $request->user()) {
86
            $this->honeybadger->context(
87
                'user_id',
88
                $request->user()->getAuthIdentifier()
89
            );
90
        }
91
    }
92
}
93