Completed
Push — master ( c89276...395830 )
by Freek
01:06
created

DemoMode::demoRouteEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\DemoMode;
4
5
use Closure;
6
use Illuminate\Config\Repository;
7
use Illuminate\Http\RedirectResponse;
8
use Illuminate\Http\Request;
9
10
class DemoMode
11
{
12
    /** @var array */
13
    protected $config;
14
15
    public function __construct(Repository $config)
16
    {
17
        $this->config = $config->get('demo-mode');
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->get('demo-mode') of type * is incompatible with the declared type array of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
18
    }
19
20
    /**
21
     * Handle an incoming request.
22
     *
23
     * @param \Illuminate\Http\Request $request
24
     * @param \Closure                 $next
25
     *
26
     * @return mixed
27
     */
28
    public function handle($request, Closure $next)
29
    {
30
        if (! $this->config['enabled']) {
31
            return $next($request);
32
        }
33
34
        if ($this->protectedByDemoMode($request)) {
35
36
37
            if (! (new DemoGuard())->hasDemoAccess($request)) {
38
                return new RedirectResponse($this->config['redirect_unauthorized_users_to_url']);
39
            }
40
        }
41
42
        return $next($request);
43
    }
44
45
    protected function protectedByDemoMode(Request $request): bool
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
46
    {
47
        return true;
48
    }
49
}
50