MaxmindLookupAdapter::getCountry()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
namespace Azine\GeoBlockingBundle\Adapter;
3
4
use Maxmind\lib\GeoIp;
5
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
8
class MaxmindLookupAdapter implements GeoIpLookupAdapterInterface
9
{
10
    protected $geoip = null;
11
12 1
    public function __construct(ContainerInterface $container)
13
    {
14 1
        if (!$container->hasParameter('maxmind_geoip_data_file_path')) {
15 1
            throw new \InvalidArgumentException("It seems, the MaxmindGeoIP-Bundle is not installed. The parameter 'maxmind_geoip_data_file_path' is not defined.");
16
        }
17
        $filePath = $container->getParameter('maxmind_geoip_data_file_path');
18
        $this->geoip = new GeoIp($filePath);
19
    }
20
21
    public function getCountry($visitorAddress)
22
    {
23
        $record = $this->geoip->geoip_record_by_addr($visitorAddress);
24
25
        return $record->country_code;
26
    }
27
}
28