Passed
Push — master ( 8042ba...9ae060 )
by Ivan
02:02
created

Shield   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 36
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A requiresLogin() 0 7 3
A currentUrlIsIgnored() 0 15 3
1
<?php
2
3
namespace CodeZero\StageFront;
4
5
use Illuminate\Support\Facades\Config;
6
use Illuminate\Support\Facades\Request;
7
use Illuminate\Support\Facades\Session;
8
9
class Shield
10
{
11
    /**
12
     * Check if StageFront requires the user to log in.
13
     *
14
     * @return bool
15
     */
16 11
    public function requiresLogin()
17
    {
18 11
        $enabled = Config::get('stagefront.enabled', false);
19 11
        $unlocked = Session::get('stagefront.unlocked', false);
20
21 11
        return $enabled && ! $unlocked && ! $this->currentUrlIsIgnored();
22
    }
23
24
    /**
25
     * Check if the current URL should be ignored.
26
     *
27
     * @return bool
28
     */
29 10
    protected function currentUrlIsIgnored()
30
    {
31 10
        $ignoredUrls = Config::get('stagefront.ignore_urls', []);
32 10
        $ignoredUrls[] = Config::get('stagefront.url');
33
34 10
        foreach ($ignoredUrls as $url) {
35 10
            $url = trim($url, '/');
36
37 10
            if (Request::is($url)) {
38 10
                return true;
39
            }
40
        }
41
42 2
        return false;
43
    }
44
}
45