Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint build #220

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require __DIR__ . '/../vendor/autoload.php';

use GeoIp2\Database\Reader;
use GeoIp2\Exception\AddressNotFoundException;

srand(0);

Expand All @@ -14,7 +15,7 @@

try {
$t = $reader->city($ip);
} catch (\GeoIp2\Exception\AddressNotFoundException $e) {
} catch (AddressNotFoundException $e) {
}
if ($i % 10000 === 0) {
echo $i . ' ' . $ip . "\n";
Expand Down
54 changes: 19 additions & 35 deletions src/Database/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use GeoIp2\ProviderInterface;
use MaxMind\Db\Reader as DbReader;
use MaxMind\Db\Reader\InvalidDatabaseException;
use MaxMind\Db\Reader\Metadata;

/**
* Instances of this class provide a reader for the GeoIP2 database format.
Expand Down Expand Up @@ -59,8 +60,7 @@ class Reader implements ProviderInterface
* @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
* @throws InvalidDatabaseException if the database is corrupt or invalid
*/
public function __construct(
string $filename,
Expand All @@ -76,10 +76,8 @@ public function __construct(
*
* @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
* @throws AddressNotFoundException if the address is not in the database
* @throws InvalidDatabaseException if the database is corrupt or invalid
*/
public function city(string $ipAddress): City
{
Expand All @@ -91,10 +89,8 @@ public function city(string $ipAddress): City
*
* @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
* @throws AddressNotFoundException if the address is not in the database
* @throws InvalidDatabaseException if the database is corrupt or invalid
*/
public function country(string $ipAddress): Country
{
Expand All @@ -106,10 +102,8 @@ public function country(string $ipAddress): Country
*
* @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
* @throws AddressNotFoundException if the address is not in the database
* @throws InvalidDatabaseException if the database is corrupt or invalid
*/
public function anonymousIp(string $ipAddress): AnonymousIp
{
Expand All @@ -125,10 +119,8 @@ public function anonymousIp(string $ipAddress): AnonymousIp
*
* @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
* @throws AddressNotFoundException if the address is not in the database
* @throws InvalidDatabaseException if the database is corrupt or invalid
*/
public function asn(string $ipAddress): Asn
{
Expand All @@ -144,10 +136,8 @@ public function asn(string $ipAddress): Asn
*
* @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
* @throws AddressNotFoundException if the address is not in the database
* @throws InvalidDatabaseException if the database is corrupt or invalid
*/
public function connectionType(string $ipAddress): ConnectionType
{
Expand All @@ -163,10 +153,8 @@ public function connectionType(string $ipAddress): ConnectionType
*
* @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
* @throws AddressNotFoundException if the address is not in the database
* @throws InvalidDatabaseException if the database is corrupt or invalid
*/
public function domain(string $ipAddress): Domain
{
Expand All @@ -182,10 +170,8 @@ public function domain(string $ipAddress): Domain
*
* @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
* @throws AddressNotFoundException if the address is not in the database
* @throws InvalidDatabaseException if the database is corrupt or invalid
*/
public function enterprise(string $ipAddress): Enterprise
{
Expand All @@ -197,10 +183,8 @@ public function enterprise(string $ipAddress): Enterprise
*
* @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
* @throws AddressNotFoundException if the address is not in the database
* @throws InvalidDatabaseException if the database is corrupt or invalid
*/
public function isp(string $ipAddress): Isp
{
Expand Down Expand Up @@ -267,7 +251,7 @@ private function getRecord(string $class, string $type, string $ipAddress): arra
* @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
* @return Metadata object for the database
*/
public function metadata(): DbReader\Metadata
{
Expand Down
52 changes: 30 additions & 22 deletions src/Model/City.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace GeoIp2\Model;

use GeoIp2\Record\City as CityRecord;
use GeoIp2\Record\Location;
use GeoIp2\Record\Postal;
use GeoIp2\Record\Subdivision;

/**
* Model class for the data returned by City Plus web service and City
* database.
Expand All @@ -14,39 +19,42 @@
class City extends Country
{
/**
* @var \GeoIp2\Record\City city data for the requested IP
* address
* @var CityRecord city data for the requested IP address
*/
public readonly \GeoIp2\Record\City $city;
public readonly CityRecord $city;

/**
* @var \GeoIp2\Record\Location location data for the
* requested IP address
* @var Location location data for the requested IP address
*/
public readonly \GeoIp2\Record\Location $location;

/**
* @var \GeoIp2\Record\Subdivision An object
* representing the most specific subdivision returned. If the response
* did not contain any subdivisions, this method returns an empty
* \GeoIp2\Record\Subdivision object.
* @var Subdivision An object representing the most specific subdivision
* returned. If the response did not contain any
* subdivisions, this method returns an empty
* \GeoIp2\Record\Subdivision object.
*/
public readonly \GeoIp2\Record\Subdivision $mostSpecificSubdivision;

/**
* @var \GeoIp2\Record\Postal postal data for the
* requested IP address
* @var Postal postal data for the
* requested IP address
*/
public readonly \GeoIp2\Record\Postal $postal;

/**
* @var array<\GeoIp2\Record\Subdivision> An array of \GeoIp2\Record\Subdivision
* objects representing the country subdivisions for the requested IP
* address. The number and type of subdivisions varies by country, but a
* subdivision is typically a state, province, county, etc. Subdivisions
* are ordered from most general (largest) to most specific (smallest).
* If the response did not contain any subdivisions, this method returns
* an empty array.
* objects representing the country
* subdivisions for the requested IP
* address. The number and type of
* subdivisions varies by country,
* but a subdivision is typically a
* state, province, county, etc.
* Subdivisions are ordered from most
* general (largest) to most specific
* (smallest). If the response did
* not contain any subdivisions, this
* method returns an empty array.
*/
public readonly array $subdivisions;

Expand All @@ -57,22 +65,22 @@ public function __construct(array $raw, array $locales = ['en'])
{
parent::__construct($raw, $locales);

$this->city = new \GeoIp2\Record\City($raw['city'] ?? [], $locales);
$this->location = new \GeoIp2\Record\Location($raw['location'] ?? []);
$this->postal = new \GeoIp2\Record\Postal($raw['postal'] ?? []);
$this->city = new CityRecord($raw['city'] ?? [], $locales);
$this->location = new Location($raw['location'] ?? []);
$this->postal = new Postal($raw['postal'] ?? []);

if (!isset($raw['subdivisions'])) {
$this->subdivisions = [];
$this->mostSpecificSubdivision =
new \GeoIp2\Record\Subdivision([], $locales);
new Subdivision([], $locales);

return;
}

$subdivisions = [];
foreach ($raw['subdivisions'] as $sub) {
$subdivisions[] =
new \GeoIp2\Record\Subdivision($sub, $locales)
new Subdivision($sub, $locales)
;
}

Expand Down
53 changes: 29 additions & 24 deletions src/Model/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

namespace GeoIp2\Model;

use GeoIp2\Record\Continent;
use GeoIp2\Record\Country as CountryRecord;
use GeoIp2\Record\MaxMind;
use GeoIp2\Record\RepresentedCountry;
use GeoIp2\Record\Traits;

/**
* Model class for the data returned by GeoIP2 Country web service and database.
*
Expand All @@ -12,42 +18,41 @@
class Country implements \JsonSerializable
{
/**
* @var \GeoIp2\Record\Continent continent data for the
* requested IP address
* @var Continent continent data for the requested IP address
*/
public readonly \GeoIp2\Record\Continent $continent;

/**
* @var \GeoIp2\Record\Country Country data for the requested
* IP address. This object represents the country where MaxMind believes the
* end user is located.
* @var CountryRecord Country data for the requested IP address. This
* object represents the country where MaxMind believes
* the end user is located.
*/
public readonly \GeoIp2\Record\Country $country;
public readonly CountryRecord $country;

/**
* @var \GeoIp2\Record\MaxMind data related to your MaxMind
* account
* @var MaxMind data related to your MaxMind account
*/
public readonly \GeoIp2\Record\MaxMind $maxmind;

/**
* @var \GeoIp2\Record\Country 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.
* @var CountryRecord 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.
*/
public readonly \GeoIp2\Record\Country $registeredCountry;
public readonly CountryRecord $registeredCountry;

/**
* @var \GeoIp2\Record\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.
* @var 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.
*/
public readonly \GeoIp2\Record\RepresentedCountry $representedCountry;

/**
* @var \GeoIp2\Record\Traits data for the traits of the
* requested IP address
* @var Traits data for the traits of the requested IP address
*/
public readonly \GeoIp2\Record\Traits $traits;

Expand All @@ -56,24 +61,24 @@ class Country implements \JsonSerializable
*/
public function __construct(array $raw, array $locales = ['en'])
{
$this->continent = new \GeoIp2\Record\Continent(
$this->continent = new Continent(
$raw['continent'] ?? [],
$locales
);
$this->country = new \GeoIp2\Record\Country(
$this->country = new CountryRecord(
$raw['country'] ?? [],
$locales
);
$this->maxmind = new \GeoIp2\Record\MaxMind($raw['maxmind'] ?? []);
$this->registeredCountry = new \GeoIp2\Record\Country(
$this->maxmind = new MaxMind($raw['maxmind'] ?? []);
$this->registeredCountry = new CountryRecord(
$raw['registered_country'] ?? [],
$locales
);
$this->representedCountry = new \GeoIp2\Record\RepresentedCountry(
$this->representedCountry = new RepresentedCountry(
$raw['represented_country'] ?? [],
$locales
);
$this->traits = new \GeoIp2\Record\Traits($raw['traits'] ?? []);
$this->traits = new Traits($raw['traits'] ?? []);
}

public function jsonSerialize(): ?array
Expand Down
4 changes: 2 additions & 2 deletions src/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ interface ProviderInterface
/**
* @param string $ipAddress an IPv4 or IPv6 address to lookup
*
* @return \GeoIp2\Model\Country a Country model for the requested IP address
* @return Model\Country a Country model for the requested IP address
*/
public function country(string $ipAddress): Model\Country;

/**
* @param string $ipAddress an IPv4 or IPv6 address to lookup
*
* @return \GeoIp2\Model\City a City model for the requested IP address
* @return Model\City a City model for the requested IP address
*/
public function city(string $ipAddress): Model\City;
}
Loading