Completed
Push — master ( 0ae072...5bde57 )
by Anton
04:24 queued 01:11
created

Authenticator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 5 2
A using() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of Laravel Authenticator.
5
 *
6
 * (c) Anton Komarev <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cog\Laravel\Sense\Authentication\Services;
15
16
use Closure;
17
use Illuminate\Http\Request;
18
19
class Authenticator
20
{
21
    /**
22
     * The callback that should be used to authenticate Sense users.
23
     *
24
     * @var \Closure
25
     */
26
    public static $using;
27
28
    /**
29
     * Determine if the given request can access the Sense dashboard.
30
     *
31
     * @param  \Illuminate\Http\Request $request
32
     * @return bool
33
     */
34
    public static function check(Request $request): bool
35
    {
36
        return (static::$using ?: function () {
37
            return app()->environment('local');
0 ignored issues
show
introduced by
The method environment() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
            return app()->/** @scrutinizer ignore-call */ environment('local');
Loading history...
38
        })($request);
39
    }
40
41
    /**
42
     * Set the callback that should be used to authenticate Sense users.
43
     *
44
     * @param  \Closure $callback
45
     * @return void
46
     */
47
    public static function using(Closure $callback): void
48
    {
49
        static::$using = $callback;
50
    }
51
}
52