diff --git a/lib/maxmind/GeoIp2/Database/Reader.php b/lib/maxmind/GeoIp2/Database/Reader.php
index b19b5f1a390..84cf2beb423 100644
--- a/lib/maxmind/GeoIp2/Database/Reader.php
+++ b/lib/maxmind/GeoIp2/Database/Reader.php
@@ -5,6 +5,7 @@ namespace GeoIp2\Database;
use GeoIp2\Exception\AddressNotFoundException;
use GeoIp2\ProviderInterface;
use MaxMind\Db\Reader as DbReader;
+use MaxMind\Db\Reader\InvalidDatabaseException;
/**
* Instances of this class provide a reader for the GeoIP2 database format.
@@ -29,7 +30,6 @@ use MaxMind\Db\Reader as DbReader;
* SPL {@link \InvalidArgumentException} will be thrown. If the database is
* corrupt or invalid, a {@link \MaxMind\Db\Reader\InvalidDatabaseException}
* will be thrown.
- *
*/
class Reader implements ProviderInterface
{
@@ -39,15 +39,16 @@ class Reader implements ProviderInterface
/**
* Constructor.
*
- * @param string $filename The path to the GeoIP2 database file.
- * @param array $locales List of locale codes to use in name property
- * from most preferred to least preferred.
+ * @param string $filename the path to the GeoIP2 database file
+ * @param array $locales list of locale codes to use in name property
+ * from most preferred to least preferred
+ *
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
- * is corrupt or invalid
+ * is corrupt or invalid
*/
public function __construct(
$filename,
- $locales = array('en')
+ $locales = ['en']
) {
$this->dbReader = new DbReader($filename);
$this->locales = $locales;
@@ -56,14 +57,14 @@ class Reader implements ProviderInterface
/**
* This method returns a GeoIP2 City model.
*
- * @param string $ipAddress IPv4 or IPv6 address as a string.
+ * @param string $ipAddress an IPv4 or IPv6 address as a string
+ *
+ * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ * not in the database
+ * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ * is corrupt or invalid
*
* @return \GeoIp2\Model\City
- *
- * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
- * not in the database.
- * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
- * is corrupt or invalid
*/
public function city($ipAddress)
{
@@ -73,14 +74,14 @@ class Reader implements ProviderInterface
/**
* This method returns a GeoIP2 Country model.
*
- * @param string $ipAddress IPv4 or IPv6 address as a string.
+ * @param string $ipAddress an IPv4 or IPv6 address as a string
+ *
+ * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ * not in the database
+ * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ * is corrupt or invalid
*
* @return \GeoIp2\Model\Country
- *
- * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
- * not in the database.
- * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
- * is corrupt or invalid
*/
public function country($ipAddress)
{
@@ -90,14 +91,14 @@ class Reader implements ProviderInterface
/**
* This method returns a GeoIP2 Anonymous IP model.
*
- * @param string $ipAddress IPv4 or IPv6 address as a string.
+ * @param string $ipAddress an IPv4 or IPv6 address as a string
+ *
+ * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ * not in the database
+ * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ * is corrupt or invalid
*
* @return \GeoIp2\Model\AnonymousIp
- *
- * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
- * not in the database.
- * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
- * is corrupt or invalid
*/
public function anonymousIp($ipAddress)
{
@@ -108,17 +109,38 @@ class Reader implements ProviderInterface
);
}
+ /**
+ * This method returns a GeoLite2 ASN model.
+ *
+ * @param string $ipAddress an IPv4 or IPv6 address as a string
+ *
+ * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ * not in the database
+ * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ * is corrupt or invalid
+ *
+ * @return \GeoIp2\Model\Asn
+ */
+ public function asn($ipAddress)
+ {
+ return $this->flatModelFor(
+ 'Asn',
+ 'GeoLite2-ASN',
+ $ipAddress
+ );
+ }
+
/**
* This method returns a GeoIP2 Connection Type model.
*
- * @param string $ipAddress IPv4 or IPv6 address as a string.
+ * @param string $ipAddress an IPv4 or IPv6 address as a string
+ *
+ * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ * not in the database
+ * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ * is corrupt or invalid
*
* @return \GeoIp2\Model\ConnectionType
- *
- * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
- * not in the database.
- * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
- * is corrupt or invalid
*/
public function connectionType($ipAddress)
{
@@ -132,14 +154,14 @@ class Reader implements ProviderInterface
/**
* This method returns a GeoIP2 Domain model.
*
- * @param string $ipAddress IPv4 or IPv6 address as a string.
+ * @param string $ipAddress an IPv4 or IPv6 address as a string
+ *
+ * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ * not in the database
+ * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ * is corrupt or invalid
*
* @return \GeoIp2\Model\Domain
- *
- * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
- * not in the database.
- * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
- * is corrupt or invalid
*/
public function domain($ipAddress)
{
@@ -153,14 +175,14 @@ class Reader implements ProviderInterface
/**
* This method returns a GeoIP2 Enterprise model.
*
- * @param string $ipAddress IPv4 or IPv6 address as a string.
+ * @param string $ipAddress an IPv4 or IPv6 address as a string
+ *
+ * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ * not in the database
+ * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ * is corrupt or invalid
*
* @return \GeoIp2\Model\Enterprise
- *
- * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
- * not in the database.
- * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
- * is corrupt or invalid
*/
public function enterprise($ipAddress)
{
@@ -170,14 +192,14 @@ class Reader implements ProviderInterface
/**
* This method returns a GeoIP2 ISP model.
*
- * @param string $ipAddress IPv4 or IPv6 address as a string.
+ * @param string $ipAddress an IPv4 or IPv6 address as a string
+ *
+ * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ * not in the database
+ * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ * is corrupt or invalid
*
* @return \GeoIp2\Model\Isp
- *
- * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
- * not in the database.
- * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
- * is corrupt or invalid
*/
public function isp($ipAddress)
{
@@ -193,7 +215,7 @@ class Reader implements ProviderInterface
$record = $this->getRecord($class, $type, $ipAddress);
$record['traits']['ip_address'] = $ipAddress;
- $class = "GeoIp2\\Model\\" . $class;
+ $class = 'GeoIp2\\Model\\' . $class;
return new $class($record, $this->locales);
}
@@ -203,7 +225,7 @@ class Reader implements ProviderInterface
$record = $this->getRecord($class, $type, $ipAddress);
$record['ip_address'] = $ipAddress;
- $class = "GeoIp2\\Model\\" . $class;
+ $class = 'GeoIp2\\Model\\' . $class;
return new $class($record);
}
@@ -214,7 +236,7 @@ class Reader implements ProviderInterface
$method = lcfirst($class);
throw new \BadMethodCallException(
"The $method method cannot be used to open a "
- . $this->metadata()->databaseType . " database"
+ . $this->metadata()->databaseType . ' database'
);
}
$record = $this->dbReader->get($ipAddress);
@@ -223,13 +245,28 @@ class Reader implements ProviderInterface
"The address $ipAddress is not in the database."
);
}
+ if (!is_array($record)) {
+ // This can happen on corrupt databases. Generally,
+ // MaxMind\Db\Reader will throw a
+ // MaxMind\Db\Reader\InvalidDatabaseException, but occasionally
+ // the lookup may result in a record that looks valid but is not
+ // an array. This mostly happens when the user is ignoring all
+ // exceptions and the more frequent InvalidDatabaseException
+ // exceptions go unnoticed.
+ throw new InvalidDatabaseException(
+ "Expected an array when looking up $ipAddress but received: "
+ . gettype($record)
+ );
+ }
+
return $record;
}
/**
- * @throws \InvalidArgumentException if arguments are passed to the method.
- * @throws \BadMethodCallException if the database has been closed.
- * @return \MaxMind\Db\Reader\Metadata object for the database.
+ * @throws \InvalidArgumentException if arguments are passed to the method
+ * @throws \BadMethodCallException if the database has been closed
+ *
+ * @return \MaxMind\Db\Reader\Metadata object for the database
*/
public function metadata()
{
diff --git a/lib/maxmind/GeoIp2/Exception/HttpException.php b/lib/maxmind/GeoIp2/Exception/HttpException.php
index 931fd46ae36..62ec707ac65 100644
--- a/lib/maxmind/GeoIp2/Exception/HttpException.php
+++ b/lib/maxmind/GeoIp2/Exception/HttpException.php
@@ -5,11 +5,10 @@ namespace GeoIp2\Exception;
/**
* This class represents an HTTP transport error.
*/
-
class HttpException extends GeoIp2Exception
{
/**
- * The URI queried
+ * The URI queried.
*/
public $uri;
diff --git a/lib/maxmind/GeoIp2/Exception/InvalidRequestException.php b/lib/maxmind/GeoIp2/Exception/InvalidRequestException.php
index 6712d73e972..6464bcbb1eb 100644
--- a/lib/maxmind/GeoIp2/Exception/InvalidRequestException.php
+++ b/lib/maxmind/GeoIp2/Exception/InvalidRequestException.php
@@ -9,7 +9,7 @@ namespace GeoIp2\Exception;
class InvalidRequestException extends HttpException
{
/**
- * The code returned by the MaxMind web service
+ * The code returned by the MaxMind web service.
*/
public $error;
diff --git a/lib/maxmind/GeoIp2/Model/AbstractModel.php b/lib/maxmind/GeoIp2/Model/AbstractModel.php
index c24266610b3..d4b9b70ff2e 100644
--- a/lib/maxmind/GeoIp2/Model/AbstractModel.php
+++ b/lib/maxmind/GeoIp2/Model/AbstractModel.php
@@ -2,17 +2,17 @@
namespace GeoIp2\Model;
-use GeoIp2\Compat\JsonSerializable;
-
/**
* @ignore
*/
-abstract class AbstractModel implements JsonSerializable
+abstract class AbstractModel implements \JsonSerializable
{
protected $raw;
/**
* @ignore
+ *
+ * @param mixed $raw
*/
public function __construct($raw)
{
@@ -21,26 +21,29 @@ abstract class AbstractModel implements JsonSerializable
/**
* @ignore
+ *
+ * @param mixed $field
*/
protected function get($field)
{
if (isset($this->raw[$field])) {
return $this->raw[$field];
- } else {
- if (preg_match('/^is_/', $field)) {
- return false;
- } else {
- return null;
- }
}
+ if (preg_match('/^is_/', $field)) {
+ return false;
+ }
+
+ return null;
}
/**
* @ignore
+ *
+ * @param mixed $attr
*/
public function __get($attr)
{
- if ($attr != "instance" && property_exists($this, $attr)) {
+ if ($attr !== 'instance' && property_exists($this, $attr)) {
return $this->$attr;
}
@@ -49,10 +52,12 @@ abstract class AbstractModel implements JsonSerializable
/**
* @ignore
+ *
+ * @param mixed $attr
*/
public function __isset($attr)
{
- return $attr != "instance" && isset($this->$attr);
+ return $attr !== 'instance' && isset($this->$attr);
}
public function jsonSerialize()
diff --git a/lib/maxmind/GeoIp2/Model/AnonymousIp.php b/lib/maxmind/GeoIp2/Model/AnonymousIp.php
index 90e77069d7d..bdaeb898105 100644
--- a/lib/maxmind/GeoIp2/Model/AnonymousIp.php
+++ b/lib/maxmind/GeoIp2/Model/AnonymousIp.php
@@ -5,24 +5,18 @@ namespace GeoIp2\Model;
/**
* This class provides the GeoIP2 Anonymous IP model.
*
- * @property-read boolean $isAnonymous This is true if the IP address belongs to
+ * @property-read bool $isAnonymous This is true if the IP address belongs to
* any sort of anonymous network.
- *
- * @property-read boolean $isAnonymousVpn This is true if the IP address belongs to
+ * @property-read bool $isAnonymousVpn This is true if the IP address belongs to
* an anonymous VPN system.
- *
- * @property-read boolean $isHostingProvider This is true if the IP address belongs
+ * @property-read bool $isHostingProvider This is true if the IP address belongs
* to a hosting provider.
- *
- * @property-read boolean $isPublicProxy This is true if the IP address belongs to
+ * @property-read bool $isPublicProxy This is true if the IP address belongs to
* a public proxy.
- *
- * @property-read boolean $isTorExitNode This is true if the IP address is a Tor
+ * @property-read bool $isTorExitNode This is true if the IP address is a Tor
* exit node.
- *
* @property-read string $ipAddress The IP address that the data in the model is
* for.
- *
*/
class AnonymousIp extends AbstractModel
{
@@ -35,6 +29,8 @@ class AnonymousIp extends AbstractModel
/**
* @ignore
+ *
+ * @param mixed $raw
*/
public function __construct($raw)
{
diff --git a/lib/maxmind/GeoIp2/Model/Asn.php b/lib/maxmind/GeoIp2/Model/Asn.php
new file mode 100644
index 00000000000..4144142fe02
--- /dev/null
+++ b/lib/maxmind/GeoIp2/Model/Asn.php
@@ -0,0 +1,35 @@
+autonomousSystemNumber = $this->get('autonomous_system_number');
+ $this->autonomousSystemOrganization =
+ $this->get('autonomous_system_organization');
+ $this->ipAddress = $this->get('ip_address');
+ }
+}
diff --git a/lib/maxmind/GeoIp2/Model/City.php b/lib/maxmind/GeoIp2/Model/City.php
index fb7ddda9af6..32859035a1e 100644
--- a/lib/maxmind/GeoIp2/Model/City.php
+++ b/lib/maxmind/GeoIp2/Model/City.php
@@ -11,33 +11,25 @@ namespace GeoIp2\Model;
*
* @property-read \GeoIp2\Record\City $city City data for the requested IP
* address.
- *
* @property-read \GeoIp2\Record\Continent $continent Continent data for the
* requested IP address.
- *
* @property-read \GeoIp2\Record\Country $country Country data for the requested
* IP address. This object represents the country where MaxMind believes the
* end user is located.
- *
* @property-read \GeoIp2\Record\Location $location Location data for the
* requested IP address.
- *
* @property-read \GeoIp2\Record\Postal $postal Postal data for the
* requested IP address.
- *
* @property-read \GeoIp2\Record\MaxMind $maxmind Data related to your MaxMind
* account.
- *
* @property-read \GeoIp2\Record\Country $registeredCountry Registered country
* data for the requested IP address. This record represents the country
* where the ISP has registered a given IP block and may differ from the
* user's country.
- *
* @property-read \GeoIp2\Record\RepresentedCountry $representedCountry
* Represented country data for the requested IP address. The represented
* country is used for things like military bases. It is only present when
* the represented country differs from the country.
- *
* @property-read array $subdivisions An array of {@link \GeoIp2\Record\Subdivision}
* objects representing the country subdivisions for the requested IP
* address. The number and type of subdivisions varies by country, but a
@@ -45,12 +37,10 @@ namespace GeoIp2\Model;
* are ordered from most general (largest) to most specific (smallest).
* If the response did not contain any subdivisions, this method returns
* an empty array.
- *
* @property-read \GeoIp2\Record\Subdivision $mostSpecificSubdivision An object
* representing the most specific subdivision returned. If the response
* did not contain any subdivisions, this method returns an empty
* {@link \GeoIp2\Record\Subdivision} object.
- *
* @property-read \GeoIp2\Record\Traits $traits Data for the traits of the
* requested IP address.
*/
@@ -71,12 +61,15 @@ class City extends Country
/**
* @ignore
*/
- protected $subdivisions = array();
+ protected $subdivisions = [];
/**
* @ignore
+ *
+ * @param mixed $raw
+ * @param mixed $locales
*/
- public function __construct($raw, $locales = array('en'))
+ public function __construct($raw, $locales = ['en'])
{
parent::__construct($raw, $locales);
@@ -103,20 +96,38 @@ class City extends Country
/**
* @ignore
+ *
+ * @param mixed $attr
*/
public function __get($attr)
{
- if ($attr == 'mostSpecificSubdivision') {
+ if ($attr === 'mostSpecificSubdivision') {
return $this->$attr();
- } else {
- return parent::__get($attr);
}
+
+ return parent::__get($attr);
+ }
+
+ /**
+ * @ignore
+ *
+ * @param mixed $attr
+ */
+ public function __isset($attr)
+ {
+ if ($attr === 'mostSpecificSubdivision') {
+ // We always return a mostSpecificSubdivision, even if it is the
+ // empty subdivision
+ return true;
+ }
+
+ return parent::__isset($attr);
}
private function mostSpecificSubdivision()
{
return empty($this->subdivisions) ?
- new \GeoIp2\Record\Subdivision(array(), $this->locales) :
+ new \GeoIp2\Record\Subdivision([], $this->locales) :
end($this->subdivisions);
}
}
diff --git a/lib/maxmind/GeoIp2/Model/ConnectionType.php b/lib/maxmind/GeoIp2/Model/ConnectionType.php
index dccd500a804..169e7c11792 100644
--- a/lib/maxmind/GeoIp2/Model/ConnectionType.php
+++ b/lib/maxmind/GeoIp2/Model/ConnectionType.php
@@ -8,10 +8,8 @@ namespace GeoIp2\Model;
* @property-read string|null $connectionType The connection type may take the
* following values: "Dialup", "Cable/DSL", "Corporate", "Cellular".
* Additional values may be added in the future.
- *
* @property-read string $ipAddress The IP address that the data in the model is
* for.
- *
*/
class ConnectionType extends AbstractModel
{
@@ -20,6 +18,8 @@ class ConnectionType extends AbstractModel
/**
* @ignore
+ *
+ * @param mixed $raw
*/
public function __construct($raw)
{
diff --git a/lib/maxmind/GeoIp2/Model/Country.php b/lib/maxmind/GeoIp2/Model/Country.php
index 05cdea7eb53..17833a152ca 100644
--- a/lib/maxmind/GeoIp2/Model/Country.php
+++ b/lib/maxmind/GeoIp2/Model/Country.php
@@ -11,24 +11,19 @@ namespace GeoIp2\Model;
*
* @property-read \GeoIp2\Record\Continent $continent Continent data for the
* requested IP address.
- *
* @property-read \GeoIp2\Record\Country $country Country data for the requested
* IP address. This object represents the country where MaxMind believes the
* end user is located.
- *
* @property-read \GeoIp2\Record\MaxMind $maxmind Data related to your MaxMind
* account.
- *
* @property-read \GeoIp2\Record\Country $registeredCountry Registered country
* data for the requested IP address. This record represents the country
* where the ISP has registered a given IP block and may differ from the
* user's country.
- *
* @property-read \GeoIp2\Record\RepresentedCountry $representedCountry
* Represented country data for the requested IP address. The represented
* country is used for things like military bases. It is only present when
* the represented country differs from the country.
- *
* @property-read \GeoIp2\Record\Traits $traits Data for the traits of the
* requested IP address.
*/
@@ -44,8 +39,11 @@ class Country extends AbstractModel
/**
* @ignore
+ *
+ * @param mixed $raw
+ * @param mixed $locales
*/
- public function __construct($raw, $locales = array('en'))
+ public function __construct($raw, $locales = ['en'])
{
parent::__construct($raw);
diff --git a/lib/maxmind/GeoIp2/Model/Domain.php b/lib/maxmind/GeoIp2/Model/Domain.php
index c540644d3a5..f452e866917 100644
--- a/lib/maxmind/GeoIp2/Model/Domain.php
+++ b/lib/maxmind/GeoIp2/Model/Domain.php
@@ -8,10 +8,8 @@ namespace GeoIp2\Model;
* @property-read string|null $domain The second level domain associated with the
* IP address. This will be something like "example.com" or
* "example.co.uk", not "foo.example.com".
- *
* @property-read string $ipAddress The IP address that the data in the model is
* for.
- *
*/
class Domain extends AbstractModel
{
@@ -20,6 +18,8 @@ class Domain extends AbstractModel
/**
* @ignore
+ *
+ * @param mixed $raw
*/
public function __construct($raw)
{
diff --git a/lib/maxmind/GeoIp2/Model/Enterprise.php b/lib/maxmind/GeoIp2/Model/Enterprise.php
index 12d45bd7986..6b98c0553de 100644
--- a/lib/maxmind/GeoIp2/Model/Enterprise.php
+++ b/lib/maxmind/GeoIp2/Model/Enterprise.php
@@ -11,30 +11,23 @@ namespace GeoIp2\Model;
*
* @property-read \GeoIp2\Record\City $city City data for the requested IP
* address.
- *
* @property-read \GeoIp2\Record\Continent $continent Continent data for the
* requested IP address.
- *
* @property-read \GeoIp2\Record\Country $country Country data for the requested
* IP address. This object represents the country where MaxMind believes the
* end user is located.
- *
* @property-read \GeoIp2\Record\Location $location Location data for the
* requested IP address.
- *
* @property-read \GeoIp2\Record\MaxMind $maxmind Data related to your MaxMind
* account.
- *
* @property-read \GeoIp2\Record\Country $registeredCountry Registered country
* data for the requested IP address. This record represents the country
* where the ISP has registered a given IP block and may differ from the
* user's country.
- *
* @property-read \GeoIp2\Record\RepresentedCountry $representedCountry
* Represented country data for the requested IP address. The represented
* country is used for things like military bases. It is only present when
* the represented country differs from the country.
- *
* @property-read array $subdivisions An array of {@link \GeoIp2\Record\Subdivision}
* objects representing the country subdivisions for the requested IP
* address. The number and type of subdivisions varies by country, but a
@@ -42,12 +35,10 @@ namespace GeoIp2\Model;
* are ordered from most general (largest) to most specific (smallest).
* If the response did not contain any subdivisions, this method returns
* an empty array.
- *
* @property-read \GeoIp2\Record\Subdivision $mostSpecificSubdivision An object
* representing the most specific subdivision returned. If the response
* did not contain any subdivisions, this method returns an empty
* {@link \GeoIp2\Record\Subdivision} object.
- *
* @property-read \GeoIp2\Record\Traits $traits Data for the traits of the
* requested IP address.
*/
diff --git a/lib/maxmind/GeoIp2/Model/Insights.php b/lib/maxmind/GeoIp2/Model/Insights.php
index 7c0c9e16ce6..cefcfb916c9 100644
--- a/lib/maxmind/GeoIp2/Model/Insights.php
+++ b/lib/maxmind/GeoIp2/Model/Insights.php
@@ -11,30 +11,23 @@ namespace GeoIp2\Model;
*
* @property-read \GeoIp2\Record\City $city City data for the requested IP
* address.
- *
* @property-read \GeoIp2\Record\Continent $continent Continent data for the
* requested IP address.
- *
* @property-read \GeoIp2\Record\Country $country Country data for the requested
* IP address. This object represents the country where MaxMind believes the
* end user is located.
- *
* @property-read \GeoIp2\Record\Location $location Location data for the
* requested IP address.
- *
* @property-read \GeoIp2\Record\MaxMind $maxmind Data related to your MaxMind
* account.
- *
* @property-read \GeoIp2\Record\Country $registeredCountry Registered country
* data for the requested IP address. This record represents the country
* where the ISP has registered a given IP block and may differ from the
* user's country.
- *
* @property-read \GeoIp2\Record\RepresentedCountry $representedCountry
* Represented country data for the requested IP address. The represented
* country is used for things like military bases. It is only present when
* the represented country differs from the country.
- *
* @property-read array $subdivisions An array of {@link \GeoIp2\Record\Subdivision}
* objects representing the country subdivisions for the requested IP
* address. The number and type of subdivisions varies by country, but a
@@ -42,12 +35,10 @@ namespace GeoIp2\Model;
* are ordered from most general (largest) to most specific (smallest).
* If the response did not contain any subdivisions, this method returns
* an empty array.
- *
* @property-read \GeoIp2\Record\Subdivision $mostSpecificSubdivision An object
* representing the most specific subdivision returned. If the response
* did not contain any subdivisions, this method returns an empty
* {@link \GeoIp2\Record\Subdivision} object.
- *
* @property-read \GeoIp2\Record\Traits $traits Data for the traits of the
* requested IP address.
*/
diff --git a/lib/maxmind/GeoIp2/Model/Isp.php b/lib/maxmind/GeoIp2/Model/Isp.php
index c2dd35735ca..51e0b680ecb 100644
--- a/lib/maxmind/GeoIp2/Model/Isp.php
+++ b/lib/maxmind/GeoIp2/Model/Isp.php
@@ -3,24 +3,19 @@
namespace GeoIp2\Model;
/**
- * This class provides the GeoIP2 Connection-Type model.
+ * This class provides the GeoIP2 ISP model.
*
- * @property-read integer|null $autonomousSystemNumber The autonomous system number
+ * @property-read int|null $autonomousSystemNumber The autonomous system number
* associated with the IP address.
- *
* @property-read string|null $autonomousSystemOrganization The organization
* associated with the registered autonomous system number for the IP
* address.
- *
* @property-read string|null $isp The name of the ISP associated with the IP
* address.
- *
* @property-read string|null $organization The name of the organization associated
* with the IP address.
- *
* @property-read string $ipAddress The IP address that the data in the model is
* for.
- *
*/
class Isp extends AbstractModel
{
@@ -32,6 +27,8 @@ class Isp extends AbstractModel
/**
* @ignore
+ *
+ * @param mixed $raw
*/
public function __construct($raw)
{
diff --git a/lib/maxmind/GeoIp2/ProviderInterface.php b/lib/maxmind/GeoIp2/ProviderInterface.php
index 6c3992f5548..44851b07e12 100644
--- a/lib/maxmind/GeoIp2/ProviderInterface.php
+++ b/lib/maxmind/GeoIp2/ProviderInterface.php
@@ -5,16 +5,16 @@ namespace GeoIp2;
interface ProviderInterface
{
/**
- * @param ipAddress
- * IPv4 or IPv6 address to lookup.
- * @return \GeoIp2\Model\Country A Country model for the requested IP address.
+ * @param string $ipAddress an IPv4 or IPv6 address to lookup
+ *
+ * @return \GeoIp2\Model\Country a Country model for the requested IP address
*/
public function country($ipAddress);
/**
- * @param ipAddress
- * IPv4 or IPv6 address to lookup.
- * @return \GeoIp2\Model\City A City model for the requested IP address.
+ * @param string $ipAddress an IPv4 or IPv6 address to lookup
+ *
+ * @return \GeoIp2\Model\City a City model for the requested IP address
*/
public function city($ipAddress);
}
diff --git a/lib/maxmind/GeoIp2/Record/AbstractPlaceRecord.php b/lib/maxmind/GeoIp2/Record/AbstractPlaceRecord.php
index 0b7e7d693e2..1e079c62944 100644
--- a/lib/maxmind/GeoIp2/Record/AbstractPlaceRecord.php
+++ b/lib/maxmind/GeoIp2/Record/AbstractPlaceRecord.php
@@ -8,8 +8,11 @@ abstract class AbstractPlaceRecord extends AbstractRecord
/**
* @ignore
+ *
+ * @param mixed $record
+ * @param mixed $locales
*/
- public function __construct($record, $locales = array('en'))
+ public function __construct($record, $locales = ['en'])
{
$this->locales = $locales;
parent::__construct($record);
@@ -17,22 +20,47 @@ abstract class AbstractPlaceRecord extends AbstractRecord
/**
* @ignore
+ *
+ * @param mixed $attr
*/
public function __get($attr)
{
- if ($attr == 'name') {
+ if ($attr === 'name') {
return $this->name();
- } else {
- return parent::__get($attr);
}
+
+ return parent::__get($attr);
+ }
+
+ /**
+ * @ignore
+ *
+ * @param mixed $attr
+ */
+ public function __isset($attr)
+ {
+ if ($attr === 'name') {
+ return $this->firstSetNameLocale() === null ? false : true;
+ }
+
+ return parent::__isset($attr);
}
private function name()
+ {
+ $locale = $this->firstSetNameLocale();
+
+ return $locale === null ? null : $this->names[$locale];
+ }
+
+ private function firstSetNameLocale()
{
foreach ($this->locales as $locale) {
if (isset($this->names[$locale])) {
- return $this->names[$locale];
+ return $locale;
}
}
+
+ return null;
}
}
diff --git a/lib/maxmind/GeoIp2/Record/AbstractRecord.php b/lib/maxmind/GeoIp2/Record/AbstractRecord.php
index 7bb1c5bb848..5d8cb0bf10d 100644
--- a/lib/maxmind/GeoIp2/Record/AbstractRecord.php
+++ b/lib/maxmind/GeoIp2/Record/AbstractRecord.php
@@ -2,22 +2,24 @@
namespace GeoIp2\Record;
-use GeoIp2\Compat\JsonSerializable;
-
-abstract class AbstractRecord implements JsonSerializable
+abstract class AbstractRecord implements \JsonSerializable
{
private $record;
/**
* @ignore
+ *
+ * @param mixed $record
*/
public function __construct($record)
{
- $this->record = isset($record) ? $record : array();
+ $this->record = isset($record) ? $record : [];
}
/**
* @ignore
+ *
+ * @param mixed $attr
*/
public function __get($attr)
{
@@ -29,12 +31,11 @@ abstract class AbstractRecord implements JsonSerializable
} elseif ($this->validAttribute($attr)) {
if (preg_match('/^is_/', $key)) {
return false;
- } else {
- return null;
}
- } else {
- throw new \RuntimeException("Unknown attribute: $attr");
+
+ return null;
}
+ throw new \RuntimeException("Unknown attribute: $attr");
}
public function __isset($attr)
@@ -50,7 +51,7 @@ abstract class AbstractRecord implements JsonSerializable
private function validAttribute($attr)
{
- return in_array($attr, $this->validAttributes);
+ return in_array($attr, $this->validAttributes, true);
}
public function jsonSerialize()
diff --git a/lib/maxmind/GeoIp2/Record/City.php b/lib/maxmind/GeoIp2/Record/City.php
index 9f1560f6eb5..7f495ad7cc0 100644
--- a/lib/maxmind/GeoIp2/Record/City.php
+++ b/lib/maxmind/GeoIp2/Record/City.php
@@ -11,14 +11,11 @@ namespace GeoIp2\Record;
* @property-read int|null $confidence A value from 0-100 indicating MaxMind's
* confidence that the city is correct. This attribute is only available
* from the Insights service and the GeoIP2 Enterprise database.
- *
* @property-read int|null $geonameId The GeoName ID for the city. This attribute
* is returned by all location services and databases.
- *
* @property-read string|null $name The name of the city based on the locales list
* passed to the constructor. This attribute is returned by all location
* services and databases.
- *
* @property-read array|null $names A array map where the keys are locale codes
* and the values are names. This attribute is returned by all location
* services and databases.
@@ -28,5 +25,5 @@ class City extends AbstractPlaceRecord
/**
* @ignore
*/
- protected $validAttributes = array('confidence', 'geonameId', 'names');
+ protected $validAttributes = ['confidence', 'geonameId', 'names'];
}
diff --git a/lib/maxmind/GeoIp2/Record/Continent.php b/lib/maxmind/GeoIp2/Record/Continent.php
index 4893e9ee77d..c6b17056e32 100644
--- a/lib/maxmind/GeoIp2/Record/Continent.php
+++ b/lib/maxmind/GeoIp2/Record/Continent.php
@@ -3,21 +3,18 @@
namespace GeoIp2\Record;
/**
- * Contains data for the continent record associated with an IP address
+ * Contains data for the continent record associated with an IP address.
*
* This record is returned by all location services and databases.
*
* @property-read string|null $code A two character continent code like "NA" (North
* America) or "OC" (Oceania). This attribute is returned by all location
* services and databases.
- *
* @property-read int|null $geonameId The GeoName ID for the continent. This
* attribute is returned by all location services and databases.
- *
* @property-read string|null $name Returns the name of the continent based on the
* locales list passed to the constructor. This attribute is returned by all location
* services and databases.
- *
* @property-read array|null $names An array map where the keys are locale codes
* and the values are names. This attribute is returned by all location
* services and databases.
@@ -27,9 +24,9 @@ class Continent extends AbstractPlaceRecord
/**
* @ignore
*/
- protected $validAttributes = array(
+ protected $validAttributes = [
'code',
'geonameId',
- 'names'
- );
+ 'names',
+ ];
}
diff --git a/lib/maxmind/GeoIp2/Record/Country.php b/lib/maxmind/GeoIp2/Record/Country.php
index 922195b1b85..5b3b0d2f282 100644
--- a/lib/maxmind/GeoIp2/Record/Country.php
+++ b/lib/maxmind/GeoIp2/Record/Country.php
@@ -3,26 +3,22 @@
namespace GeoIp2\Record;
/**
- * Contains data for the country record associated with an IP address
+ * Contains data for the country record associated with an IP address.
*
* This record is returned by all location services and databases.
*
* @property-read int|null $confidence A value from 0-100 indicating MaxMind's
* confidence that the country is correct. This attribute is only available
* from the Insights service and the GeoIP2 Enterprise database.
- *
* @property-read int|null $geonameId The GeoName ID for the country. This
* attribute is returned by location services and databases.
- *
- * @property-read string|null $isoCode The {@link
- * http://en.wikipedia.org/wiki/ISO_3166-1 two-character ISO 3166-1 alpha
+ * @property-read string|null $isoCode The
+ * {@link * http://en.wikipedia.org/wiki/ISO_3166-1 two-character ISO 3166-1 alpha
* code} for the country. This attribute is returned by all location services
* and databases.
- *
* @property-read string|null $name The name of the country based on the locales
* list passed to the constructor. This attribute is returned by all location
* services and databases.
- *
* @property-read array|null $names An array map where the keys are locale codes
* and the values are names. This attribute is returned by all location
* services and databases.
@@ -32,10 +28,10 @@ class Country extends AbstractPlaceRecord
/**
* @ignore
*/
- protected $validAttributes = array(
+ protected $validAttributes = [
'confidence',
'geonameId',
'isoCode',
- 'names'
- );
+ 'names',
+ ];
}
diff --git a/lib/maxmind/GeoIp2/Record/Location.php b/lib/maxmind/GeoIp2/Record/Location.php
index 5d0742dece8..9b81adf33e4 100644
--- a/lib/maxmind/GeoIp2/Record/Location.php
+++ b/lib/maxmind/GeoIp2/Record/Location.php
@@ -3,7 +3,7 @@
namespace GeoIp2\Record;
/**
- * Contains data for the location record associated with an IP address
+ * Contains data for the location record associated with an IP address.
*
* This record is returned by all location services and databases besides
* Country.
@@ -11,31 +11,24 @@ namespace GeoIp2\Record;
* @property-read int|null $averageIncome The average income in US dollars
* associated with the requested IP address. This attribute is only available
* from the Insights service.
- *
* @property-read int|null $accuracyRadius The approximate accuracy radius in
* kilometers around the latitude and longitude for the IP address. This is
* the radius where we have a 67% confidence that the device using the IP
* address resides within the circle centered at the latitude and longitude
* with the provided radius.
- *
* @property-read float|null $latitude The approximate latitude of the location
* associated with the IP address. This value is not precise and should not be
* used to identify a particular address or household.
- *
* @property-read float|null $longitude The approximate longitude of the location
* associated with the IP address. This value is not precise and should not be
* used to identify a particular address or household.
- *
* @property-read int|null $populationDensity The estimated population per square
* kilometer associated with the IP address. This attribute is only available
* from the Insights service.
- *
* @property-read int|null $metroCode The metro code of the location if the location
* is in the US. MaxMind returns the same metro codes as the
- * {@link
- * https://developers.google.com/adwords/api/docs/appendix/cities-DMAregions
+ * {@link * https://developers.google.com/adwords/api/docs/appendix/cities-DMAregions
* Google AdWords API}.
- *
* @property-read string|null $timeZone The time zone associated with location, as
* specified by the {@link http://www.iana.org/time-zones IANA Time Zone
* Database}, e.g., "America/New_York".
@@ -45,7 +38,7 @@ class Location extends AbstractRecord
/**
* @ignore
*/
- protected $validAttributes = array(
+ protected $validAttributes = [
'averageIncome',
'accuracyRadius',
'latitude',
@@ -54,6 +47,6 @@ class Location extends AbstractRecord
'populationDensity',
'postalCode',
'postalConfidence',
- 'timeZone'
- );
+ 'timeZone',
+ ];
}
diff --git a/lib/maxmind/GeoIp2/Record/MaxMind.php b/lib/maxmind/GeoIp2/Record/MaxMind.php
index 8971e96fac9..2e2cc0024fc 100644
--- a/lib/maxmind/GeoIp2/Record/MaxMind.php
+++ b/lib/maxmind/GeoIp2/Record/MaxMind.php
@@ -15,5 +15,5 @@ class MaxMind extends AbstractRecord
/**
* @ignore
*/
- protected $validAttributes = array('queriesRemaining');
+ protected $validAttributes = ['queriesRemaining'];
}
diff --git a/lib/maxmind/GeoIp2/Record/Postal.php b/lib/maxmind/GeoIp2/Record/Postal.php
index 81d30115f50..69508c782b7 100644
--- a/lib/maxmind/GeoIp2/Record/Postal.php
+++ b/lib/maxmind/GeoIp2/Record/Postal.php
@@ -3,7 +3,7 @@
namespace GeoIp2\Record;
/**
- * Contains data for the postal record associated with an IP address
+ * Contains data for the postal record associated with an IP address.
*
* This record is returned by all location databases and services besides
* Country.
@@ -12,7 +12,6 @@ namespace GeoIp2\Record;
* are not available for all countries. In some countries, this will only
* contain part of the postal code. This attribute is returned by all location
* databases and services besides Country.
- *
* @property-read int|null $confidence A value from 0-100 indicating MaxMind's
* confidence that the postal code is correct. This attribute is only
* available from the Insights service and the GeoIP2 Enterprise
@@ -23,5 +22,5 @@ class Postal extends AbstractRecord
/**
* @ignore
*/
- protected $validAttributes = array('code', 'confidence');
+ protected $validAttributes = ['code', 'confidence'];
}
diff --git a/lib/maxmind/GeoIp2/Record/RepresentedCountry.php b/lib/maxmind/GeoIp2/Record/RepresentedCountry.php
index dd491147ffc..c37102ea715 100644
--- a/lib/maxmind/GeoIp2/Record/RepresentedCountry.php
+++ b/lib/maxmind/GeoIp2/Record/RepresentedCountry.php
@@ -3,7 +3,7 @@
namespace GeoIp2\Record;
/**
- * Contains data for the represented country associated with an IP address
+ * Contains data for the represented country associated with an IP address.
*
* This class contains the country-level data associated with an IP address
* for the IP's represented country. The represented country is the country
@@ -12,29 +12,24 @@ namespace GeoIp2\Record;
* @property-read int|null $confidence A value from 0-100 indicating MaxMind's
* confidence that the country is correct. This attribute is only available
* from the Insights service and the GeoIP2 Enterprise database.
- *
* @property-read int|null $geonameId The GeoName ID for the country.
- *
* @property-read string|null $isoCode The {@link http://en.wikipedia.org/wiki/ISO_3166-1
* two-character ISO 3166-1 alpha code} for the country.
- *
* @property-read string|null $name The name of the country based on the locales list
* passed to the constructor.
- *
* @property-read array|null $names An array map where the keys are locale codes and
* the values are names.
- *
* @property-read string|null $type A string indicating the type of entity that is
* representing the country. Currently we only return military
* but this could expand to include other types in the future.
*/
class RepresentedCountry extends Country
{
- protected $validAttributes = array(
+ protected $validAttributes = [
'confidence',
'geonameId',
'isoCode',
'names',
- 'type'
- );
+ 'type',
+ ];
}
diff --git a/lib/maxmind/GeoIp2/Record/Subdivision.php b/lib/maxmind/GeoIp2/Record/Subdivision.php
index cb5256afe2d..386c68d8fa7 100644
--- a/lib/maxmind/GeoIp2/Record/Subdivision.php
+++ b/lib/maxmind/GeoIp2/Record/Subdivision.php
@@ -3,8 +3,7 @@
namespace GeoIp2\Record;
/**
- *
- * Contains data for the subdivisions associated with an IP address
+ * Contains data for the subdivisions associated with an IP address.
*
* This record is returned by all location databases and services besides
* Country.
@@ -13,20 +12,16 @@ namespace GeoIp2\Record;
* MaxMind's confidence that the subdivision is correct. This attribute is
* only available from the Insights service and the GeoIP2 Enterprise
* database.
- *
* @property-read int|null $geonameId This is a GeoName ID for the subdivision.
* This attribute is returned by all location databases and services besides
* Country.
- *
* @property-read string|null $isoCode This is a string up to three characters long
- * contain the subdivision portion of the {@link
- * http://en.wikipedia.org/wiki/ISO_3166-2 ISO 3166-2 code}. This attribute
+ * contain the subdivision portion of the
+ * {@link * http://en.wikipedia.org/wiki/ISO_3166-2 ISO 3166-2 code}. This attribute
* is returned by all location databases and services except Country.
- *
* @property-read string|null $name The name of the subdivision based on the
* locales list passed to the constructor. This attribute is returned by all
* location databases and services besides Country.
- *
* @property-read array|null $names An array map where the keys are locale codes
* and the values are names. This attribute is returned by all location
* databases and services besides Country.
@@ -36,10 +31,10 @@ class Subdivision extends AbstractPlaceRecord
/**
* @ignore
*/
- protected $validAttributes = array(
+ protected $validAttributes = [
'confidence',
'geonameId',
'isoCode',
- 'names'
- );
+ 'names',
+ ];
}
diff --git a/lib/maxmind/GeoIp2/Record/Traits.php b/lib/maxmind/GeoIp2/Record/Traits.php
index 7d8710f57e7..582eea609b2 100644
--- a/lib/maxmind/GeoIp2/Record/Traits.php
+++ b/lib/maxmind/GeoIp2/Record/Traits.php
@@ -3,65 +3,53 @@
namespace GeoIp2\Record;
/**
- *
- * Contains data for the traits record associated with an IP address
+ * Contains data for the traits record associated with an IP address.
*
* This record is returned by all location services and databases.
*
- * @property-read int|null $autonomousSystemNumber The {@link
- * http://en.wikipedia.org/wiki/Autonomous_system_(Internet) autonomous
+ * @property-read int|null $autonomousSystemNumber The
+ * {@link * http://en.wikipedia.org/wiki/Autonomous_system_(Internet) autonomous
* system number} associated with the IP address. This attribute is only
* available from the City and Insights web service and the GeoIP2
* Enterprise database.
- *
* @property-read string|null $autonomousSystemOrganization The organization
- * associated with the registered {@link
- * http://en.wikipedia.org/wiki/Autonomous_system_(Internet) autonomous
+ * associated with the registered {@link * http://en.wikipedia.org/wiki/Autonomous_system_(Internet) autonomous
* system number} for the IP address. This attribute is only available from
* the City and Insights web service and the GeoIP2 Enterprise
* database.
- *
* @property-read string|null $connectionType The connection type may take the
* following values: "Dialup", "Cable/DSL", "Corporate", "Cellular".
* Additional values may be added in the future. This attribute is only
* available in the GeoIP2 Enterprise database.
- *
* @property-read string|null $domain The second level domain associated with the
* IP address. This will be something like "example.com" or "example.co.uk",
* not "foo.example.com". This attribute is only available from the
* City and Insights web service and the GeoIP2 Enterprise
* database.
- *
* @property-read string $ipAddress The IP address that the data in the model
* is for. If you performed a "me" lookup against the web service, this
* will be the externally routable IP address for the system the code is
* running on. If the system is behind a NAT, this may differ from the IP
* address locally assigned to it. This attribute is returned by all end
* points.
- *
- * @property-read boolean $isAnonymousProxy *Deprecated.* Please see our {@link
- * https://www.maxmind.com/en/geoip2-anonymous-ip-database GeoIP2
+ * @property-read bool $isAnonymousProxy *Deprecated.* Please see our
+ * {@link * https://www.maxmind.com/en/geoip2-anonymous-ip-database GeoIP2
* Anonymous IP database} to determine whether the IP address is used by an
* anonymizing service.
- *
- * @property-read boolean $isLegitimateProxy This attribute is true if MaxMind
+ * @property-read bool $isLegitimateProxy This attribute is true if MaxMind
* believes this IP address to be a legitimate proxy, such as an internal
* VPN used by a corporation. This attribute is only available in the GeoIP2
* Enterprise database.
- *
- * @property-read boolean $isSatelliteProvider *Deprecated.* Due to the
+ * @property-read bool $isSatelliteProvider *Deprecated.* Due to the
* increased coverage by mobile carriers, very few satellite providers now
* serve multiple countries. As a result, the output does not provide
* sufficiently relevant data for us to maintain it.
- *
* @property-read string|null $isp The name of the ISP associated with the IP
* address. This attribute is only available from the City and Insights web
* services and the GeoIP2 Enterprise database.
- *
* @property-read string|null $organization The name of the organization associated
* with the IP address. This attribute is only available from the City and
* Insights web services and the GeoIP2 Enterprise database.
- *
* @property-read string|null $userType
The user type associated with the IP * address. This can be one of the following values:
*