Mygento_Geoip_Model_City::getCityByIp()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
/**
4
 *
5
 *
6
 * @category Mygento
7
 * @package Mygento_Geoip
8
 * @copyright 2014 NKS LLC. (https://www.mygento.ru)
9
 */
10
class Mygento_Geoip_Model_City extends Mygento_Geoip_Model_Abstract
11
{
12
13
    private $city;
14
15
    public function __construct()
16
    {
17
        parent::__construct();
18
        if (!Mage::getSingleton('core/session')->getGeoCity()) {
19
            $this->city = $this->getCityByIp(Mage::helper('core/http')->getRemoteAddr());
20
            Mage::getSingleton('core/session')->setGeoCity($this->city);
21
        }
22
    }
23
24 View Code Duplication
    public function getCityByIp($ip)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        if (!$this->isFileExists()) {
27
            return null;
28
        }
29
        $SxGeo = new GeoIP_SxGeo($this->local_file);
30
        $city_full = $SxGeo->getCity($ip);
31
        unset($SxGeo);
32
        if ($city_full['city']['name_ru'] != '') {
33
            return $city_full['city']['name_ru'];
34
        }
35
        return Mage::getStoreConfig('geoip/general/city');
36
    }
37
38 View Code Duplication
    public function getCity()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        if (!$this->city) {
41
            $this->city = $this->getCityByIp(Mage::helper('core/http')->getRemoteAddr());
42
        }
43
        return $this->city;
44
    }
45
}
46