Completed
Pull Request — develop (#50)
by Abdelrahman
01:55
created

Reauthenticate::handle()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 10
c 1
b 0
f 0
nc 6
nop 6
dl 0
loc 17
rs 8.8571
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Fort\Http\Middleware;
6
7
use Closure;
8
9
class Reauthenticate
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param \Illuminate\Http\Request $request
15
     * @param \Closure                 $next
16
     * @param string                   $type
17
     * @param string                   $sessionName
0 ignored issues
show
Documentation introduced by
Should the type for parameter $sessionName not be null|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
18
     * @param int                      $timeout
0 ignored issues
show
Documentation introduced by
Should the type for parameter $timeout not be null|integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
19
     * @param bool                     $renew
20
     *
21
     * @return mixed
22
     */
23
    public function handle($request, Closure $next, string $type = 'password', string $sessionName = null, int $timeout = null, bool $renew = false)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 148 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...
24
    {
25
        $timeout = $timeout ?? config('cortex.fort.reauthentication.timeout');
26
        $sessionName = $sessionName ? 'cortex.fort.reauthentication.'.$sessionName : 'cortex.fort.reauthentication.'.$request->route()->getName();
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 146 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...
27
       
28
        if(is_null(session($sessionName)) || time() - session($sessionName) >= $timeout) {
29
            session()->forget($sessionName);
30
            session()->put('cortex.fort.reauthentication.intended', $request->url());
31
            session()->put('cortex.fort.reauthentication.session_name', $sessionName);
32
33
            return view('cortex/fort::frontarea.common.reauthentication.'.$type);
34
        }
35
36
        ! $renew || session()->put($sessionName, time());
37
38
        return $next($request);
39
    }
40
}
41