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.

ContextManager::setUserContext()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
c 1
b 0
f 1
dl 0
loc 10
rs 10
cc 3
nc 4
nop 1
1
<?php
2
3
namespace Honeybadger\HoneybadgerLaravel;
4
5
use Honeybadger\Contracts\Reporter;
6
use Illuminate\Support\Facades\Route;
7
use Symfony\Component\HttpFoundation\Request;
8
9
class ContextManager
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;
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...
22
    }
23
24
    public function setRouteAction(Request $request)
25
    {
26
        if (app('honeybadger.isLumen')) {
27
            $this->setLumenRouteActionContext($request);
28
        } else {
29
            $this->setLaravelRouteActionContext();
30
        }
31
    }
32
33
    private function setLumenRouteActionContext(Request $request)
34
    {
35
        $routes = app()->router->getRoutes();
36
        $routeIdentifier = $request->method().$request->getPathInfo();
0 ignored issues
show
introduced by
The method method() does not exist on Symfony\Component\HttpFoundation\Request. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        $routeIdentifier = $request->/** @scrutinizer ignore-call */ method().$request->getPathInfo();
Loading history...
37
38
        if (! array_key_exists($routeIdentifier, $routes)) {
39
            return;
40
        }
41
42
        $routeDetails = $routes[$routeIdentifier]['action'];
43
44
        if (! isset($routeDetails['uses']) && ! empty($routeDetails[0])) {
45
            $this->honeybadger->setComponent(get_class($routeDetails[0]));
46
47
            return;
48
        }
49
50
        $routeAction = explode('@', $routeDetails['uses']);
51
52
        if (! empty($routeAction[0])) {
53
            $this->honeybadger->setComponent($routeAction[0] ?? '');
54
        }
55
56
        if (! empty($routeAction[1])) {
57
            $this->honeybadger->setAction($routeAction[1] ?? '');
58
        }
59
    }
60
61
    private function setLaravelRouteActionContext()
62
    {
63
        if (Route::getCurrentRoute()) {
64
            $routeAction = explode('@', Route::getCurrentRoute()->getActionName());
65
66
            if (! empty($routeAction[0])) {
67
                $this->honeybadger->setComponent($routeAction[0] ?? '');
68
            }
69
70
            if (! empty($routeAction[1])) {
71
                $this->honeybadger->setAction($routeAction[1] ?? '');
72
            }
73
        }
74
    }
75
76
    public function setUserContext($request)
77
    {
78
        try {
79
            if ($request->user()) {
80
                $this->honeybadger->context(
81
                    'user_id',
82
                    $request->user()->getAuthIdentifier()
83
                );
84
            }
85
        } catch (\InvalidArgumentException $e) {
86
            // swallow
87
        }
88
    }
89
}
90