Referrer::check()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 4
nc 5
nop 1
1
<?php
2
3
namespace Spinzar\Firewall\Middleware;
4
5
use Spinzar\Firewall\Abstracts\Middleware;
6
use Spinzar\Firewall\Events\AttackDetected;
7
8
class Referrer extends Middleware
9
{
10
    public function check($patterns)
11
    {
12
        $status = false;
13
14
        if (!$blocked = config('firewall.middleware.' . $this->middleware . '.blocked')) {
15
            return $status;
16
        }
17
18
        if (in_array((string) $this->request->server('HTTP_REFERER'), (array) $blocked)) {
19
            $status = true;
20
        }
21
22
        if ($status) {
23
            $log = $this->log();
24
25
            event(new AttackDetected($log));
26
        }
27
28
        return $status;
29
    }
30
}
31