Completed
Push — develop ( 10b573...34b970 )
by Abdelrahman
09:38
created

UpdateLastActivity   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 4 1
A terminate() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Fort\Http\Middleware;
6
7
use Closure;
8
use Illuminate\Http\Request;
9
10
class UpdateLastActivity
11
{
12
    /**
13
     * Handle an incoming request.
14
     *
15
     * @param \Illuminate\Http\Request $request
16
     * @param \Closure                 $next
17
     *
18
     * @return mixed
19
     */
20
    public function handle(Request $request, Closure $next)
21
    {
22
        return $next($request);
23
    }
24
25
    /**
26
     * Perform any final actions for the request lifecycle.
27
     *
28
     * @param \Illuminate\Http\Request                   $request
29
     * @param \Symfony\Component\HttpFoundation\Response $response
30
     *
31
     * @return void
32
     */
33
    public function terminate($request, $response): void
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...
34
    {
35
        if ($user = $request->user()) {
36
            // We are using database queries rather than eloquent, to bypass triggering events.
37
            // Triggering update events flush cache and costs us more queries, which we don't need.
38
            $userModel = config('auth.providers.'.config('auth.guards.'.config('auth.defaults.guard').'.provider').'.model');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
39
            (new $userModel())->where($user->getKeyName(), $user->getKey())->update(['last_activity' => now()]);
40
        }
41
    }
42
}
43