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
|
|||||
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
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
![]() |
|||||
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 |
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.