Completed
Push — master ( 709dbb...f12a68 )
by Tobias
09:11
created

FakeRequestListener   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 28
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onKernelRequest() 0 10 4
A getFakeIp() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the BazingaGeocoderBundle package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @license    MIT License
9
 */
10
11
namespace Bazinga\GeocoderBundle\EventListener;
12
13
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
14
use Symfony\Component\HttpKernel\HttpKernelInterface;
15
16
/**
17
 * @author William Durand <[email protected]>
18
 */
19
class FakeRequestListener
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $fakeIp = null;
25
26
    public function __construct($fakeIp)
27
    {
28
        $this->fakeIp = $fakeIp;
29
    }
30
31
    public function onKernelRequest(GetResponseEvent $event)
32
    {
33
        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
34
            return;
35
        }
36
37
        if (null !== $this->fakeIp && !empty($this->fakeIp)) {
38
            $event->getRequest()->server->set('REMOTE_ADDR', $this->fakeIp);
39
        }
40
    }
41
42
    public function getFakeIp()
43
    {
44
        return $this->fakeIp;
45
    }
46
}
47