Updated code to follow the PSR-2 style guidelines.
This commit is contained in:
+42
-21
@@ -4,28 +4,49 @@ namespace GeoIP2\Model;
|
||||
|
||||
class City extends Country
|
||||
{
|
||||
protected $city;
|
||||
protected $location;
|
||||
protected $postal;
|
||||
protected $subdivisions = Array();
|
||||
protected $city;
|
||||
protected $location;
|
||||
protected $postal;
|
||||
protected $subdivisions = array();
|
||||
|
||||
public function __construct($raw, $languages)
|
||||
{
|
||||
parent::__construct($raw, $languages);
|
||||
public function __construct($raw, $languages)
|
||||
{
|
||||
parent::__construct($raw, $languages);
|
||||
|
||||
$this->city = new \GeoIP2\Record\City($this->get('city'), $languages);
|
||||
$this->location = new \GeoIP2\Record\Location($this->get('location'));
|
||||
$this->postal = new \GeoIP2\Record\Postal($this->get('postal'));
|
||||
$this->city = new \GeoIP2\Record\City($this->get('city'), $languages);
|
||||
$this->location = new \GeoIP2\Record\Location($this->get('location'));
|
||||
$this->postal = new \GeoIP2\Record\Postal($this->get('postal'));
|
||||
|
||||
$this->createSubdivisions($raw, $languages);
|
||||
}
|
||||
|
||||
private function createSubdivisions($raw, $languages) {
|
||||
if(!isset($raw['subdivisions'])) return;
|
||||
|
||||
foreach ($raw['subdivisions'] as $sub) {
|
||||
array_push($this->subdivisions,
|
||||
new \GeoIP2\Record\Subdivision($sub, $languages));
|
||||
$this->createSubdivisions($raw, $languages);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createSubdivisions($raw, $languages)
|
||||
{
|
||||
if (!isset($raw['subdivisions'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($raw['subdivisions'] as $sub) {
|
||||
array_push(
|
||||
$this->subdivisions,
|
||||
new \GeoIP2\Record\Subdivision($sub, $languages)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function __get($attr)
|
||||
{
|
||||
if ($attr == 'mostSpecificSubdivision') {
|
||||
return $this->$attr();
|
||||
} else {
|
||||
return parent::__get($attr);
|
||||
}
|
||||
}
|
||||
|
||||
private function mostSpecificSubdivision()
|
||||
{
|
||||
return empty($this->subdivisions)?
|
||||
new \GeoIP2\Record\Subdivision(array(), $this->languages):
|
||||
end($this->subdivisions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,4 @@ namespace GeoIP2\Model;
|
||||
|
||||
class CityIspOrg extends City
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,36 +4,50 @@ namespace GeoIP2\Model;
|
||||
|
||||
class Country
|
||||
{
|
||||
private $continent;
|
||||
private $country;
|
||||
private $registeredCountry;
|
||||
private $representedCountry;
|
||||
private $traits;
|
||||
private $raw;
|
||||
private $continent;
|
||||
private $country;
|
||||
private $languages;
|
||||
private $registeredCountry;
|
||||
private $representedCountry;
|
||||
private $traits;
|
||||
private $raw;
|
||||
|
||||
public function __construct($raw, $languages) {
|
||||
$this->raw = $raw;
|
||||
public function __construct($raw, $languages)
|
||||
{
|
||||
$this->raw = $raw;
|
||||
|
||||
$this->continent = new \GeoIP2\Record\Continent($this->get('continent'),
|
||||
$languages);
|
||||
$this->country = new \GeoIP2\Record\Country($this->get('country'),
|
||||
$languages);
|
||||
$this->registeredCountry =
|
||||
new \GeoIP2\Record\Country($this->get('registered_country'), $languages);
|
||||
$this->representedCountry =
|
||||
new \GeoIP2\Record\RepresentedCountry($this->get('represented_country'),
|
||||
$languages);
|
||||
$this->traits = new \GeoIP2\Record\Traits($this->get('traits'));
|
||||
}
|
||||
$this->continent = new \GeoIP2\Record\Continent(
|
||||
$this->get('continent'),
|
||||
$languages
|
||||
);
|
||||
$this->country = new \GeoIP2\Record\Country(
|
||||
$this->get('country'),
|
||||
$languages
|
||||
);
|
||||
$this->registeredCountry = new \GeoIP2\Record\Country(
|
||||
$this->get('registered_country'),
|
||||
$languages
|
||||
);
|
||||
$this->representedCountry = new \GeoIP2\Record\RepresentedCountry(
|
||||
$this->get('represented_country'),
|
||||
$languages
|
||||
);
|
||||
$this->traits = new \GeoIP2\Record\Traits($this->get('traits'));
|
||||
|
||||
protected function get($field) {
|
||||
return isset($this->raw[$field]) ? $this->raw[$field] : Array();
|
||||
}
|
||||
$this->languages = $languages;
|
||||
}
|
||||
|
||||
public function __get ($attr)
|
||||
{
|
||||
if ($attr != "instance" && isset($this->$attr)) return $this->$attr;
|
||||
protected function get($field)
|
||||
{
|
||||
return isset($this->raw[$field]) ? $this->raw[$field] : array();
|
||||
}
|
||||
|
||||
throw new \RuntimeException("Unknown attribute: $attr");
|
||||
}
|
||||
public function __get ($attr)
|
||||
{
|
||||
if ($attr != "instance" && isset($this->$attr)) {
|
||||
return $this->$attr;
|
||||
}
|
||||
|
||||
throw new \RuntimeException("Unknown attribute: $attr");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,4 @@ namespace GeoIP2\Model;
|
||||
|
||||
class Omni extends CityIspOrg
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user