DemoModeController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A catchFallback() 0 13 3
A grantAccess() 0 6 1
1
<?php
2
3
namespace Spatie\DemoMode;
4
5
use Illuminate\Http\RedirectResponse;
6
use Illuminate\Http\Request;
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 (!config('demo-mode.enabled')) {
22
            abort(404);
23
        }
24
25
        if (!app(DemoGuard::class)->hasDemoAccess($request)) {
26
            return new RedirectResponse(
27
                config('demo-mode.redirect_unauthorized_users_to_url')
28
            );
29
        }
30
31
        abort(404);
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Illuminate\Http\RedirectResponse. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
32
    }
33
}
34