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
Push — master ( cf8fe5...2efe23 )
by TJ
01:06
created

HoneybadgerContext::setRouteActionContext()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 4
nc 5
nop 0
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
class HoneybadgerContext
10
{
11
    /**
12
     * @var \Honeybadger\Honeybadger;
13
     */
14
    protected $honeybadger;
15
16
    /**
17
     * @param  \Honeybadger\Contracts\Reporter  $honeybadger
18
     */
19
    public function __construct(Reporter $honeybadger)
20
    {
21
        $this->honeybadger = $honeybadger;
22
    }
23
24
    /**
25
     * Handle an incoming request.
26
     *
27
     * @param  \Illuminate\Http\Request  $request
28
     * @param  \Closure  $next
29
     * @return mixed
30
     */
31
    public function handle($request, Closure $next)
32
    {
33
        if (app()->bound('honeybadger')) {
34
            $this->setUserContext($request);
35
36
            if (app('honeybadger.isLumen')) {
37
                $this->setLumenRouteActionContext($request);
38
            } else {
39
                $this->setRouteActionContext();
40
            }
41
        }
42
43
        return $next($request);
44
    }
45
46
    private function setLumenRouteActionContext($request)
47
    {
48
        $routeDetails = app()->router->getRoutes()[$request->method().$request->getPathInfo()]['action'];
49
50
        if (! isset($routeDetails['uses']) && ! empty($routeDetails[0])) {
51
            $this->honeybadger->setComponent(get_class($routeDetails[0]));
52
53
            return;
54
        }
55
56
        $routeAction = explode('@', $routeDetails['uses']);
57
58
        if (! empty($routeAction[0])) {
59
            $this->honeybadger->setComponent($routeAction[0] ?? '');
60
        }
61
62
        if (! empty($routeAction[1])) {
63
            $this->honeybadger->setAction($routeAction[1] ?? '');
64
        }
65
    }
66
67
    private function setRouteActionContext()
68
    {
69
        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...
70
            $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...
71
72
            if (! empty($routeAction[0])) {
73
                $this->honeybadger->setComponent($routeAction[0] ?? '');
74
            }
75
76
            if (! empty($routeAction[1])) {
77
                $this->honeybadger->setAction($routeAction[1] ?? '');
78
            }
79
        }
80
    }
81
82
    private function setUserContext($request)
83
    {
84
        try {
85
            if ($request->user()) {
86
                $this->honeybadger->context(
87
                    'user_id',
88
                    $request->user()->getAuthIdentifier()
89
                );
90
            }
91
        } catch (\InvalidArgumentException $e) {
92
            // swallow
93
        }
94
    }
95
}
96