Test Setup Failed
Pull Request — master (#150)
by Nick
14:47 queued 06:28
created

Authenticate::redirectTo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * Authenticate Middleware.
4
 *
5
 * @package App\Http\Middleware
6
 *
7
 * @author    Taylor Otwell <[email protected]>
8
 * @copyright 2018-2020 Nick Menke
9
 *
10
 * @link https://github.com/nlmenke/vertebrae
11
 */
12
13
declare(strict_types=1);
14
15
namespace App\Http\Middleware;
16
17
use Illuminate\Auth\Middleware\Authenticate as Middleware;
18
use Illuminate\Http\Request;
19
20
/**
21
 * The Authenticate middleware class.
22
 *
23
 * This class checks if a user has been authenticated and allows them to
24
 * proceed to their expected page or redirects them to login.
25
 *
26
 * @since 0.0.0-framework introduced
27
 */
28
class Authenticate extends Middleware
29
{
30
    /**
31
     * Get the path the user should be redirected to when they are not authenticated.
32
     *
33
     * @param Request $request
34
     *
35
     * @return string|null
36
     */
37
    protected function redirectTo($request): ?string
38
    {
39
        if (!$request->expectsJson()) {
40
            return route('login');
41
        }
42
43
        return null;
44
    }
45
}
46