diff --git a/examples/benchmark.php b/examples/benchmark.php index a735a78b..eb657d6f 100644 --- a/examples/benchmark.php +++ b/examples/benchmark.php @@ -3,6 +3,7 @@ require __DIR__ . '/../vendor/autoload.php'; use GeoIp2\Database\Reader; +use GeoIp2\Exception\AddressNotFoundException; srand(0); @@ -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"; diff --git a/src/Database/Reader.php b/src/Database/Reader.php index 1570afb8..36da6583 100644 --- a/src/Database/Reader.php +++ b/src/Database/Reader.php @@ -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. @@ -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, @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/src/Model/City.php b/src/Model/City.php index f89ccfe4..6f766adb 100644 --- a/src/Model/City.php +++ b/src/Model/City.php @@ -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. @@ -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; @@ -57,14 +65,14 @@ 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; } @@ -72,7 +80,7 @@ public function __construct(array $raw, array $locales = ['en']) $subdivisions = []; foreach ($raw['subdivisions'] as $sub) { $subdivisions[] = - new \GeoIp2\Record\Subdivision($sub, $locales) + new Subdivision($sub, $locales) ; } diff --git a/src/Model/Country.php b/src/Model/Country.php index 0fae2db7..11a876cc 100644 --- a/src/Model/Country.php +++ b/src/Model/Country.php @@ -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. * @@ -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; @@ -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 diff --git a/src/ProviderInterface.php b/src/ProviderInterface.php index 7d148912..8f40bee5 100644 --- a/src/ProviderInterface.php +++ b/src/ProviderInterface.php @@ -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; } diff --git a/src/WebService/Client.php b/src/WebService/Client.php index 1e095419..f74bb513 100644 --- a/src/WebService/Client.php +++ b/src/WebService/Client.php @@ -14,6 +14,9 @@ use GeoIp2\Model\Country; use GeoIp2\Model\Insights; use GeoIp2\ProviderInterface; +use MaxMind\Exception\InsufficientFundsException; +use MaxMind\Exception\IpAddressNotFoundException; +use MaxMind\Exception\WebServiceException; use MaxMind\WebService\Client as WsClient; /** @@ -116,24 +119,23 @@ private function userAgent(): string * address is provided, the address that the web service is called * from will be used. * - * @throws \GeoIp2\Exception\AddressNotFoundException if the address you - * provided is not in our database (e.g., a private address). - * @throws \GeoIp2\Exception\AuthenticationException if there is a problem - * with the account ID or license key that you provided - * @throws \GeoIp2\Exception\OutOfQueriesException if your account is out - * of queries - * @throws \GeoIp2\Exception\InvalidRequestException} if your request was received by the web service but is - * invalid for some other reason. This may indicate an issue - * with this API. Please report the error to MaxMind. - * @throws \GeoIp2\Exception\HttpException if an unexpected HTTP error code or message was returned. - * This could indicate a problem with the connection between - * your server and the web service or that the web service - * returned an invalid document or 500 error code - * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent - * class to the above exceptions. It will be thrown directly - * if a 200 status code is returned but the body is invalid. - * @throws \InvalidArgumentException if something other than a single IP address or "me" is - * passed to the method + * @throws AddressNotFoundException if the address you provided is not in our database (e.g., + * a private address). + * @throws AuthenticationException if there is a problem with the account ID or license key + * that you provided + * @throws OutOfQueriesException if your account is out of queries + * @throws InvalidRequestException if your request was received by the web service but is + * invalid for some other reason. This may indicate an issue + * with this API. Please report the error to MaxMind. + * @throws HttpException if an unexpected HTTP error code or message was returned. + * This could indicate a problem with the connection between + * your server and the web service or that the web service + * returned an invalid document or 500 error code + * @throws GeoIp2Exception This serves as the parent + * class to the above exceptions. It will be thrown directly + * if a 200 status code is returned but the body is invalid. + * @throws \InvalidArgumentException if something other than a single IP address or "me" is + * passed to the method */ public function city(string $ipAddress = 'me'): City { @@ -148,24 +150,23 @@ public function city(string $ipAddress = 'me'): City * address is provided, the address that the web service is called * from will be used. * - * @throws \GeoIp2\Exception\AddressNotFoundException if the address you provided is not in our database (e.g., - * a private address). - * @throws \GeoIp2\Exception\AuthenticationException if there is a problem - * with the account ID or license key that you provided - * @throws \GeoIp2\Exception\OutOfQueriesException if your account is out of queries - * @throws \GeoIp2\Exception\InvalidRequestException} if your request was received by the web service but is - * invalid for some other reason. This may indicate an - * issue with this API. Please report the error to MaxMind. - * @throws \GeoIp2\Exception\HttpException if an unexpected HTTP error - * code or message was returned. This could indicate a problem - * with the connection between your server and the web service - * or that the web service returned an invalid document or 500 - * error code. - * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent class to the above exceptions. It - * will be thrown directly if a 200 status code is returned but - * the body is invalid. - * @throws \InvalidArgumentException if something other than a single IP address or "me" is - * passed to the method + * @throws AddressNotFoundException if the address you provided is not in our database (e.g., + * a private address). + * @throws AuthenticationException if there is a problem with the account ID or license key that you provided + * @throws OutOfQueriesException if your account is out of queries + * @throws InvalidRequestException if your request was received by the web service but is + * invalid for some other reason. This may indicate an + * issue with this API. Please report the error to MaxMind. + * @throws HttpException if an unexpected HTTP error + * code or message was returned. This could indicate a problem + * with the connection between your server and the web service + * or that the web service returned an invalid document or 500 + * error code. + * @throws GeoIp2Exception This serves as the parent class to the above exceptions. It + * will be thrown directly if a 200 status code is returned but + * the body is invalid. + * @throws \InvalidArgumentException if something other than a single IP address or "me" is + * passed to the method */ public function country(string $ipAddress = 'me'): Country { @@ -180,24 +181,23 @@ public function country(string $ipAddress = 'me'): Country * address is provided, the address that the web service is called * from will be used. * - * @throws \GeoIp2\Exception\AddressNotFoundException if the address you - * provided is not in our database (e.g., a private address). - * @throws \GeoIp2\Exception\AuthenticationException if there is a problem - * with the account ID or license key that you provided - * @throws \GeoIp2\Exception\OutOfQueriesException if your account is out - * of queries - * @throws \GeoIp2\Exception\InvalidRequestException} if your request was received by the web service but is - * invalid for some other reason. This may indicate an - * issue with this API. Please report the error to MaxMind. - * @throws \GeoIp2\Exception\HttpException if an unexpected HTTP error code or message was returned. - * This could indicate a problem with the connection between - * your server and the web service or that the web service - * returned an invalid document or 500 error code - * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent - * class to the above exceptions. It will be thrown directly - * if a 200 status code is returned but the body is invalid. - * @throws \InvalidArgumentException if something other than a single IP address or "me" is - * passed to the method + * @throws AddressNotFoundException if the address you provided is not in our database (e.g., + * a private address). + * @throws AuthenticationException if there is a problem with the account ID or license key + * that you provided + * @throws OutOfQueriesException if your account is out of queries + * @throws InvalidRequestException if your request was received by the web service but is + * invalid for some other reason. This may indicate an + * issue with this API. Please report the error to MaxMind. + * @throws HttpException if an unexpected HTTP error code or message was returned. + * This could indicate a problem with the connection between + * your server and the web service or that the web service + * returned an invalid document or 500 error code + * @throws GeoIp2Exception This serves as the parent + * class to the above exceptions. It will be thrown directly + * if a 200 status code is returned but the body is invalid. + * @throws \InvalidArgumentException if something other than a single IP address or "me" is + * passed to the method */ public function insights(string $ipAddress = 'me'): Insights { @@ -217,7 +217,7 @@ private function responseFor(string $endpoint, string $class, string $ipAddress) try { $service = (new \ReflectionClass($class))->getShortName(); $body = $this->client->get('GeoIP2 ' . $service, $path); - } catch (\MaxMind\Exception\IpAddressNotFoundException $ex) { + } catch (IpAddressNotFoundException $ex) { throw new AddressNotFoundException( $ex->getMessage(), $ex->getStatusCode(), @@ -229,7 +229,7 @@ private function responseFor(string $endpoint, string $class, string $ipAddress) $ex->getStatusCode(), $ex ); - } catch (\MaxMind\Exception\InsufficientFundsException $ex) { + } catch (InsufficientFundsException $ex) { throw new OutOfQueriesException( $ex->getMessage(), $ex->getStatusCode(), @@ -250,7 +250,7 @@ private function responseFor(string $endpoint, string $class, string $ipAddress) $ex->getUri(), $ex ); - } catch (\MaxMind\Exception\WebServiceException $ex) { + } catch (WebServiceException $ex) { throw new GeoIp2Exception( $ex->getMessage(), $ex->getCode(), diff --git a/tests/GeoIp2/Test/Database/ReaderTest.php b/tests/GeoIp2/Test/Database/ReaderTest.php index 9ab8b880..eea3a849 100644 --- a/tests/GeoIp2/Test/Database/ReaderTest.php +++ b/tests/GeoIp2/Test/Database/ReaderTest.php @@ -5,6 +5,7 @@ namespace GeoIp2\Test\Database; use GeoIp2\Database\Reader; +use GeoIp2\Exception\AddressNotFoundException; use PHPUnit\Framework\TestCase; /** @@ -76,7 +77,7 @@ public function testIsInEuropeanUnion(string $type, string $method): void public function testUnknownAddress(): void { - $this->expectException(\GeoIp2\Exception\AddressNotFoundException::class); + $this->expectException(AddressNotFoundException::class); $this->expectExceptionMessage('The address 10.10.10.10 is not in the database.'); $reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb'); diff --git a/tests/GeoIp2/Test/WebService/ClientTest.php b/tests/GeoIp2/Test/WebService/ClientTest.php index 30225dec..5c291da8 100644 --- a/tests/GeoIp2/Test/WebService/ClientTest.php +++ b/tests/GeoIp2/Test/WebService/ClientTest.php @@ -5,7 +5,14 @@ namespace GeoIp2\Test\WebService; use Composer\CaBundle\CaBundle; +use GeoIp2\Exception\AddressNotFoundException; +use GeoIp2\Exception\AuthenticationException; +use GeoIp2\Exception\GeoIp2Exception; +use GeoIp2\Exception\HttpException; +use GeoIp2\Exception\OutOfQueriesException; +use GeoIp2\WebService\Client; use MaxMind\WebService\Client as WsClient; +use MaxMind\WebService\Http\Request; use PHPUnit\Framework\TestCase; /** @@ -311,7 +318,7 @@ public function testMe(): void public function testNoBodyException(): void { - $this->expectException(\GeoIp2\Exception\GeoIp2Exception::class); + $this->expectException(GeoIp2Exception::class); $this->expectExceptionMessage('Received a 200 response for GeoIP2 Country but did not receive a HTTP body.'); $this->makeRequest('Country', '1.2.3.5'); @@ -319,7 +326,7 @@ public function testNoBodyException(): void public function testBadBodyException(): void { - $this->expectException(\GeoIp2\Exception\GeoIp2Exception::class); + $this->expectException(GeoIp2Exception::class); $this->expectExceptionMessage('Received a 200 response for GeoIP2 Country but could not decode the response as JSON:'); $this->makeRequest('Country', '2.2.3.5'); @@ -335,7 +342,7 @@ public function testInvalidIPException(): void public function testNoErrorBodyIPException(): void { - $this->expectException(\GeoIp2\Exception\HttpException::class); + $this->expectException(HttpException::class); $this->expectExceptionCode(400); $this->expectExceptionMessage('with no body'); @@ -344,7 +351,7 @@ public function testNoErrorBodyIPException(): void public function testWeirdErrorBodyIPException(): void { - $this->expectException(\GeoIp2\Exception\GeoIp2Exception::class); + $this->expectException(GeoIp2Exception::class); $this->expectExceptionMessage('Error response contains JSON but it does not specify code or error keys: {"weird":42}'); $this->makeRequest('Country', '1.2.3.8'); @@ -352,7 +359,7 @@ public function testWeirdErrorBodyIPException(): void public function testInvalidErrorBodyIPException(): void { - $this->expectException(\GeoIp2\Exception\HttpException::class); + $this->expectException(HttpException::class); $this->expectExceptionCode(400); $this->expectExceptionMessage('Received a 400 error for GeoIP2 Country but could not decode the response as JSON: Syntax error. Body: { invalid: }'); @@ -361,7 +368,7 @@ public function testInvalidErrorBodyIPException(): void public function test500PException(): void { - $this->expectException(\GeoIp2\Exception\HttpException::class); + $this->expectException(HttpException::class); $this->expectExceptionCode(500); $this->expectExceptionMessage('Received a server error (500)'); @@ -370,7 +377,7 @@ public function test500PException(): void public function test3xxException(): void { - $this->expectException(\GeoIp2\Exception\HttpException::class); + $this->expectException(HttpException::class); $this->expectExceptionCode(300); $this->expectExceptionMessage('Received an unexpected HTTP status (300) for GeoIP2 Country'); @@ -379,7 +386,7 @@ public function test3xxException(): void public function test406Exception(): void { - $this->expectException(\GeoIp2\Exception\HttpException::class); + $this->expectException(HttpException::class); $this->expectExceptionCode(406); $this->expectExceptionMessage('Received a 406 error for GeoIP2 Country with the following body: Cannot satisfy your Accept-Charset requirements'); @@ -388,7 +395,7 @@ public function test406Exception(): void public function testAddressNotFoundException(): void { - $this->expectException(\GeoIp2\Exception\AddressNotFoundException::class); + $this->expectException(AddressNotFoundException::class); $this->expectExceptionMessage('The address "1.2.3.13" is not in our database.'); $this->makeRequest('Country', '1.2.3.13'); @@ -396,7 +403,7 @@ public function testAddressNotFoundException(): void public function testAddressReservedException(): void { - $this->expectException(\GeoIp2\Exception\AddressNotFoundException::class); + $this->expectException(AddressNotFoundException::class); $this->expectExceptionMessage('The address "1.2.3.14" is a private address.'); $this->makeRequest('Country', '1.2.3.14'); @@ -404,7 +411,7 @@ public function testAddressReservedException(): void public function testAuthorizationException(): void { - $this->expectException(\GeoIp2\Exception\AuthenticationException::class); + $this->expectException(AuthenticationException::class); $this->expectExceptionMessage('A user ID and license key are required to use this service'); $this->makeRequest('Country', '1.2.3.15'); @@ -412,7 +419,7 @@ public function testAuthorizationException(): void public function testMissingLicenseKeyException(): void { - $this->expectException(\GeoIp2\Exception\AuthenticationException::class); + $this->expectException(AuthenticationException::class); $this->expectExceptionMessage('A license key is required to use this service'); $this->makeRequest('Country', '1.2.3.16'); @@ -420,7 +427,7 @@ public function testMissingLicenseKeyException(): void public function testMissingUserIdException(): void { - $this->expectException(\GeoIp2\Exception\AuthenticationException::class); + $this->expectException(AuthenticationException::class); $this->expectExceptionMessage('A user ID is required to use this service'); $this->makeRequest('Country', '1.2.3.17'); @@ -428,7 +435,7 @@ public function testMissingUserIdException(): void public function testMissingAccountIdException(): void { - $this->expectException(\GeoIp2\Exception\AuthenticationException::class); + $this->expectException(AuthenticationException::class); $this->expectExceptionMessage('A account ID is required to use this service'); $this->makeRequest('Country', '1.2.3.19'); @@ -436,7 +443,7 @@ public function testMissingAccountIdException(): void public function testOutOfQueriesException(): void { - $this->expectException(\GeoIp2\Exception\OutOfQueriesException::class); + $this->expectException(OutOfQueriesException::class); $this->expectExceptionMessage('The license key you have provided is out of queries.'); $this->makeRequest('Country', '1.2.3.18'); @@ -499,7 +506,7 @@ private function makeRequest( = $this->getResponse($service, $ipAddress); $stub = $this->createMock( - \MaxMind\WebService\Http\Request::class + Request::class ); $contentType = isset($headers['Content-Type']) ? $headers['Content-Type'] @@ -534,7 +541,7 @@ private function makeRequest( $this->equalTo( [ 'headers' => $headers, - 'userAgent' => 'GeoIP2-API/' . \GeoIp2\WebService\Client::VERSION + 'userAgent' => 'GeoIP2-API/' . Client::VERSION . ' MaxMind-WS-API/' . WsClient::VERSION . ' PHP/' . \PHP_VERSION . ' curl/' . $curlVersion['version'], @@ -552,7 +559,7 @@ private function makeRequest( $method = strtolower($service); - $client = new \GeoIp2\WebService\Client( + $client = new Client( $accountId, $licenseKey, $locales,