Updated code to follow the PSR-2 style guidelines.
This commit is contained in:
@@ -4,25 +4,29 @@ namespace GeoIP2\Record;
|
||||
|
||||
abstract class AbstractPlaceRecord extends AbstractRecord
|
||||
{
|
||||
private $languages;
|
||||
private $languages;
|
||||
|
||||
public function __construct($record, $languages){
|
||||
$this->languages = $languages;
|
||||
parent::__construct($record);
|
||||
}
|
||||
|
||||
public function __get($attr) {
|
||||
if ($attr == 'name') {
|
||||
return $this->name();
|
||||
} else {
|
||||
return parent::__get($attr);
|
||||
public function __construct($record, $languages)
|
||||
{
|
||||
$this->languages = $languages;
|
||||
parent::__construct($record);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function name() {
|
||||
foreach($this->languages as $language) {
|
||||
if (isset($this->names[$language])) return $this->names[$language];
|
||||
public function __get($attr)
|
||||
{
|
||||
if ($attr == 'name') {
|
||||
return $this->name();
|
||||
} else {
|
||||
return parent::__get($attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function name()
|
||||
{
|
||||
foreach ($this->languages as $language) {
|
||||
if (isset($this->names[$language])) {
|
||||
return $this->names[$language];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,23 +4,25 @@ namespace GeoIP2\Record;
|
||||
|
||||
abstract class AbstractRecord
|
||||
{
|
||||
private $record;
|
||||
private $record;
|
||||
|
||||
public function __construct($record) {
|
||||
$this->record = $record;
|
||||
}
|
||||
|
||||
public function __get($attr) {
|
||||
$valid = in_array($attr, $this->validAttributes);
|
||||
// XXX - kind of ugly but greatly reduces boilerplate code
|
||||
$key = strtolower(preg_replace('/([A-Z])/', '_\1', $attr));
|
||||
|
||||
if ($valid && isset($this->record[$key])){
|
||||
return $this->record[$key];
|
||||
} elseif ($valid) {
|
||||
return null;
|
||||
} else {
|
||||
throw new \RuntimeException("Unknown attribute: $attr");
|
||||
public function __construct($record)
|
||||
{
|
||||
$this->record = $record;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __get($attr)
|
||||
{
|
||||
$valid = in_array($attr, $this->validAttributes);
|
||||
// XXX - kind of ugly but greatly reduces boilerplate code
|
||||
$key = strtolower(preg_replace('/([A-Z])/', '_\1', $attr));
|
||||
|
||||
if ($valid && isset($this->record[$key])) {
|
||||
return $this->record[$key];
|
||||
} elseif ($valid) {
|
||||
return null;
|
||||
} else {
|
||||
throw new \RuntimeException("Unknown attribute: $attr");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@ namespace GeoIP2\Record;
|
||||
|
||||
class City extends AbstractPlaceRecord
|
||||
{
|
||||
protected $validAttributes = Array('confidence', 'geonameId', 'names');
|
||||
}
|
||||
protected $validAttributes = array('confidence', 'geonameId', 'names');
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ namespace GeoIP2\Record;
|
||||
|
||||
class Continent extends AbstractPlaceRecord
|
||||
{
|
||||
protected $validAttributes = Array('continentCode',
|
||||
'geonameId',
|
||||
'names');
|
||||
}
|
||||
protected $validAttributes = array(
|
||||
'continentCode',
|
||||
'geonameId',
|
||||
'names'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ namespace GeoIP2\Record;
|
||||
|
||||
class Country extends AbstractPlaceRecord
|
||||
{
|
||||
|
||||
protected $validAttributes = Array('confidence',
|
||||
'geonameId',
|
||||
'isoCode',
|
||||
'names');
|
||||
}
|
||||
protected $validAttributes = array(
|
||||
'confidence',
|
||||
'geonameId',
|
||||
'isoCode',
|
||||
'names'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@ namespace GeoIP2\Record;
|
||||
|
||||
class Location extends AbstractRecord
|
||||
{
|
||||
protected $validAttributes = Array('accuracyRadius',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'metroCode',
|
||||
'postalCode',
|
||||
'postalConfidence',
|
||||
'timeZone');
|
||||
}
|
||||
protected $validAttributes = array(
|
||||
'accuracyRadius',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'metroCode',
|
||||
'postalCode',
|
||||
'postalConfidence',
|
||||
'timeZone'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@ namespace GeoIP2\Record;
|
||||
|
||||
class Postal extends AbstractRecord
|
||||
{
|
||||
protected $validAttributes = Array('code', 'confidence');
|
||||
protected $validAttributes = array('code', 'confidence');
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ namespace GeoIP2\Record;
|
||||
|
||||
class RepresentedCountry extends Country
|
||||
{
|
||||
protected $validAttributes = Array('confidence',
|
||||
'geonameId',
|
||||
'isoCode',
|
||||
'names',
|
||||
'type');
|
||||
}
|
||||
protected $validAttributes = array(
|
||||
'confidence',
|
||||
'geonameId',
|
||||
'isoCode',
|
||||
'namespace',
|
||||
'type'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ namespace GeoIP2\Record;
|
||||
|
||||
class Subdivision extends AbstractPlaceRecord
|
||||
{
|
||||
protected $validAttributes = Array('confidence',
|
||||
'geonameId',
|
||||
'isoCode',
|
||||
'names');
|
||||
}
|
||||
protected $validAttributes = array(
|
||||
'confidence',
|
||||
'geonameId',
|
||||
'isoCode',
|
||||
'names'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,14 +4,15 @@ namespace GeoIP2\Record;
|
||||
|
||||
class Traits extends AbstractRecord
|
||||
{
|
||||
protected $validAttributes = Array('autonomousSystemNumber',
|
||||
'autonomousSystemOrganization',
|
||||
'domain',
|
||||
'isAnonymousProxy',
|
||||
'isSatelliteProvider',
|
||||
'isp',
|
||||
'ipAddress',
|
||||
'organization',
|
||||
'userType');
|
||||
|
||||
}
|
||||
protected $validAttributes = array(
|
||||
'autonomousSystemNumber',
|
||||
'autonomousSystemOrganization',
|
||||
'domain',
|
||||
'isAnonymousProxy',
|
||||
'isSatelliteProvider',
|
||||
'isp',
|
||||
'ipAddress',
|
||||
'organization',
|
||||
'userType'
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user