Mygento_Geoip_Model_City::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
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