DemoMode::handle()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
c 0
b 0
f 0
nc 4
nop 2
dl 0
loc 13
rs 10
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');
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
            if (!app(DemoGuard::class)->hasDemoAccess($request)) {
36
                return new RedirectResponse($this->config['redirect_unauthorized_users_to_url']);
37
            }
38
        }
39
40
        return $next($request);
41
    }
42
43
    protected function protectedByDemoMode(Request $request): bool
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

43
    protected function protectedByDemoMode(/** @scrutinizer ignore-unused */ Request $request): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45
        return true;
46
    }
47
}
48