Mygento_Geoip_Model_Country::getCity()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
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 Copyright © 2015 NKS LLC. (http://www.mygento.ru)
9
 */
10
class Mygento_Geoip_Model_Country extends Mygento_Geoip_Model_Abstract
11
{
12
13
    private $country;
14
15
    public function __construct()
16
    {
17
        parent::__construct();
18
        if (!Mage::getSingleton('core/session')->getGeoCountry()) {
19
            $this->country = $this->getCountryByIp(Mage::helper('core/http')->getRemoteAddr());
20
            Mage::getSingleton('core/session')->setGeoCountry($this->country);
21
        }
22
    }
23
24
    public function getCountryByIp($ip)
25
    {
26
        if (!$this->isFileExists()) {
27
            return null;
28
        }
29
        $SxGeo = new GeoIP_SxGeo($this->local_file);
30
        $country = $SxGeo->getCountry($ip);
31
        if ($country) {
32
            return $country;
33
        }
34
        return Mage::getStoreConfig('geoip/general/country');
35
    }
36
37 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...
38
    {
39
        if (!$this->city) {
40
            $this->city = $this->getCityByIp(Mage::helper('core/http')->getRemoteAddr());
0 ignored issues
show
Bug introduced by
The property city does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The method getCityByIp() does not exist on Mygento_Geoip_Model_Country. Did you maybe mean getCity()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
41
        }
42
        return $this->city;
43
    }
44
}
45