Completed
Pull Request — master (#144)
by Serhii
24:57
created

IpVoter::vote()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
1
<?php
2
3
namespace AppBundle\Security;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Symfony\Component\HttpFoundation\Request;
7
8
/**
9
 * This is not part of security layer, because we decide to restrict access before security layer
10
 */
11
class IpVoter
12
{
13
    const ACCESS_GRANTED = 1;
14
    const ACCESS_DENIED = -1;
15
16
    protected $registry;
17
18
    protected $ipTable = null;
19
20 99
    public function __construct(ManagerRegistry $registry)
21
    {
22 99
        $this->registry = $registry;
23 99
    }
24
25
    /**
26
     * @param Request $request
27
     * @return int either ACCESS_GRANTED or ACCESS_DENIED
28
     */
29 99
    public function vote(Request $request)
30
    {
31 99
        if (true === $this->registry->getRepository('AppBundle:Client')->isBanned($request->getClientIp())) {
32 1
            return self::ACCESS_DENIED;
33
        }
34
35 98
        return self::ACCESS_GRANTED;
36
    }
37
}
38