MaxmindLookupAdapter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 20
ccs 3
cts 9
cp 0.3333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getCountry() 0 6 1
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