Completed
Branch develop (3b1731)
by Niclas Leon
05:45 queued 03:31
created

SetSentryContext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 4
1
<?php
2
namespace App\Http\Middleware;
3
4
use Closure;
5
6
class SetSentryContext
7
{
8
    /**
9
     * Handle an incoming request.
10
     *
11
     * @param  \Illuminate\Http\Request $request
12
     * @param  \Closure $next
13
     *
14
     * @return mixed
15
     */
16
    public function handle($request, Closure $next)
17
    {
18
        if (!app()->environment('local') && app()->bound('sentry')) {
0 ignored issues
show
Bug introduced by
The method environment() does not exist on Illuminate\Container\Container. It seems like you code against a sub-type of Illuminate\Container\Container such as Illuminate\Foundation\Application. ( Ignorable by Annotation )

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

18
        if (!app()->/** @scrutinizer ignore-call */ environment('local') && app()->bound('sentry')) {
Loading history...
19
            /** @var \Raven_Client $sentry */
20
            $sentry = app('sentry');
21
22
            // Add user context
23
            if (auth()->check()) {
24
                $user = auth()->user();
25
26
                $sentry->user_context([
27
                    'github_username' => $user->github_username,
28
                    'github_id' => $user->github_id,
29
                    'github_token' => str_limit($user->github_token, 8),
30
                ]);
31
            }
32
        }
33
34
        return $next($request);
35
    }
36
}
37