Completed
Pull Request — master (#144)
by
unknown
13:04
created

IpVoter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
    public function __construct(ManagerRegistry $registry)
21
    {
22
        $this->registry = $registry;
23
    }
24
25
    /**
26
     * @param Request $request
27
     * @return int either ACCESS_GRANTED or ACCESS_DENIED
28
     */
29
    public function vote(Request $request)
30
    {
31
        if (true === $this->registry->getRepository('AppBundle:Client')->isBanned($request->getClientIp())) {
32
            return self::ACCESS_DENIED;
33
        }
34
35
        return self::ACCESS_GRANTED;
36
    }
37
}
38