UpdateLastActivity::terminate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\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(request()->route('guard'))) {
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
            $user->newQuery()->where($user->getKeyName(), $user->getKey())->update(['last_activity' => now()]);
39
        }
40
    }
41
}
42