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

DemoModeController::hasDemoAccess()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 8.8571
cc 5
eloc 4
nc 3
nop 1
1
<?php
2
3
namespace Spatie\DemoMode;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\RedirectResponse;
7
8
class DemoModeController extends \Illuminate\Routing\Controller
9
{
10
    public function grantAccess(): RedirectResponse
11
    {
12
        session()->put('demo_access_route_visited', true);
13
14
        return new RedirectResponse(
15
            config('demo-mode.redirect_authorized_users_to_url')
16
        );
17
    }
18
19
    public function catchFallback(Request $request): RedirectResponse
20
    {
21
        if (! (new DemoGuard())->hasDemoAccess($request)) {
22
            return new RedirectResponse(
23
                config('demo-mode.redirect_unauthorized_users_to_url')
24
            );
25
        }
26
27
        abort(404);
28
    }
29
}
30