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.

StoreDevice   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 53
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 31 5
A terminate() 0 9 3
1
<?php
2
3
namespace Coreproc\Devices\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Validation\UnauthorizedException;
7
8
class StoreDevice
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request $request
14
     * @param  \Closure $next
15
     * @param null $guard
16
     * @param bool $isRequired
17
     * @return mixed
18
     */
19
    public function handle($request, Closure $next, $guard = null, $isRequired = true)
20
    {
21
        $deviceUdid = $request->header('X-Device-UDID');
22
23
        if (empty($deviceUdid) && ! $isRequired) {
24
            // We continue on
25
            return $next($request);
26
        }
27
28
        if (empty($deviceUdid) && $isRequired) {
29
            throw new UnauthorizedException('You need to specify your device details.');
30
        }
31
32
        // We save the device details
33
        $device = app(config('devices.device_model'))->query()->updateOrCreate([
34
            'udid' => $deviceUdid,
35
        ], [
36
            'os' => $request->header('X-Device-OS'),
37
            'os_version' => $request->header('X-Device-OS-Version'),
38
            'manufacturer' => $request->header('X-Device-Manufacturer'),
39
            'model' => $request->header('X-Device-Model'),
40
            'fcm_token' => $request->header('X-Device-FCM-Token'),
41
            'app_version' => $request->header('X-Device-App-Version'),
42
        ]);
43
44
        $request->device = $device;
45
46
        $request->guard = $guard ?? config('auth.defaults.guard');
47
48
        return $next($request);
49
    }
50
51
    public function terminate($request, $response)
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        $user = $request->user($request->guard);
54
55
        if (! empty($user) && ! empty($request->device)) {
56
            $request->device->deviceable()->associate($user);
57
            $request->device->save();
58
        }
59
    }
60
}
61