IpRestricter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isRestrictionEnabled() 0 4 1
A restrict() 0 13 3
A getNotAllowedResponse() 0 6 1
1
<?php
2
3
namespace Tequilarapido\RestrictAccess\Restricter;
4
5
use Symfony\Component\HttpFoundation\Response;
6
7
class IpRestricter extends Restricter
8
{
9
    use IpHelper;
10
11
    /**
12
     * Do we need to restric.
13
     */
14
    public function isRestrictionEnabled()
15
    {
16
        return config('restrict_access.by_ip.enabled');
17
    }
18
19
    /**
20
     * Protection method.
21
     *
22
     * @return mixed
23
     */
24
    public function restrict()
25
    {
26
        if (! $this->isRestrictionEnabled()) {
27
            return false;
28
        }
29
30
31
        if (! $this->isAllowed($this->getClientIp())) {
32
            return $this->getNotAllowedResponse();
33
        }
34
35
        return false;
36
    }
37
38
    /**
39
     * Returns forbidden response.
40
     *
41
     * @return Response
42
     */
43
    protected function getNotAllowedResponse()
44
    {
45
        $headers = ['X-RESTRICT-ACCESS' => 'Not allowed client ip'];
46
47
        return new Response('Not allowed.', 403, $headers);
48
    }
49
}
50