DefaultDemoGuard::hasDemoAccess()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 3
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 7
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