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
|
|||
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 |
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.