DefaultDemoGuard::demoRouteEnabled()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Spatie\DemoMode;
4
5
use Illuminate\Http\Request;
6
7
class DefaultDemoGuard implements DemoGuard
8
{
9
    public function hasDemoAccess(Request $request): bool
10
    {
11
        if ($this->isIpAuthorized($request) || auth()->check()) {
12
            return true;
13
        }
14
15
        return $this->demoRouteEnabled() && session()->has('demo_access_route_visited');
16
    }
17
18
    protected function demoRouteEnabled(): bool
19
    {
20
        return !config('demo-mode.strict_mode');
21
    }
22
23
    protected function isIpAuthorized(Request $request): bool
24
    {
25
        return in_array($request->ip(), config('demo-mode.authorized_ips'));
26
    }
27
}
28