MaxmindLookupAdapter::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 3
cts 6
cp 0.5
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2.5
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