Skip to content

Commit

Permalink
MDL-70303 libraries: upgrade GeoIP to 2.11.0 and MaxMind DB to 1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranrecio committed Jan 19, 2021
1 parent c381757 commit 23b681c
Show file tree
Hide file tree
Showing 42 changed files with 466 additions and 334 deletions.
48 changes: 17 additions & 31 deletions lib/maxmind/GeoIp2/Database/Reader.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace GeoIp2\Database;

use GeoIp2\Exception\AddressNotFoundException;
Expand Down Expand Up @@ -48,8 +50,8 @@ class Reader implements ProviderInterface
* is corrupt or invalid
*/
public function __construct(
$filename,
$locales = ['en']
string $filename,
array $locales = ['en']
) {
$this->dbReader = new DbReader($filename);
$this->dbType = $this->dbReader->metadata()->databaseType;
Expand All @@ -65,10 +67,8 @@ public function __construct(
* not in the database
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
* is corrupt or invalid
*
* @return \GeoIp2\Model\City
*/
public function city($ipAddress)
public function city(string $ipAddress): \GeoIp2\Model\City
{
return $this->modelFor('City', 'City', $ipAddress);
}
Expand All @@ -82,10 +82,8 @@ public function city($ipAddress)
* not in the database
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
* is corrupt or invalid
*
* @return \GeoIp2\Model\Country
*/
public function country($ipAddress)
public function country(string $ipAddress): \GeoIp2\Model\Country
{
return $this->modelFor('Country', 'Country', $ipAddress);
}
Expand All @@ -99,10 +97,8 @@ public function country($ipAddress)
* not in the database
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
* is corrupt or invalid
*
* @return \GeoIp2\Model\AnonymousIp
*/
public function anonymousIp($ipAddress)
public function anonymousIp(string $ipAddress): \GeoIp2\Model\AnonymousIp
{
return $this->flatModelFor(
'AnonymousIp',
Expand All @@ -120,10 +116,8 @@ public function anonymousIp($ipAddress)
* not in the database
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
* is corrupt or invalid
*
* @return \GeoIp2\Model\Asn
*/
public function asn($ipAddress)
public function asn(string $ipAddress): \GeoIp2\Model\Asn
{
return $this->flatModelFor(
'Asn',
Expand All @@ -141,10 +135,8 @@ public function asn($ipAddress)
* not in the database
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
* is corrupt or invalid
*
* @return \GeoIp2\Model\ConnectionType
*/
public function connectionType($ipAddress)
public function connectionType(string $ipAddress): \GeoIp2\Model\ConnectionType
{
return $this->flatModelFor(
'ConnectionType',
Expand All @@ -162,10 +154,8 @@ public function connectionType($ipAddress)
* not in the database
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
* is corrupt or invalid
*
* @return \GeoIp2\Model\Domain
*/
public function domain($ipAddress)
public function domain(string $ipAddress): \GeoIp2\Model\Domain
{
return $this->flatModelFor(
'Domain',
Expand All @@ -183,10 +173,8 @@ public function domain($ipAddress)
* not in the database
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
* is corrupt or invalid
*
* @return \GeoIp2\Model\Enterprise
*/
public function enterprise($ipAddress)
public function enterprise(string $ipAddress): \GeoIp2\Model\Enterprise
{
return $this->modelFor('Enterprise', 'Enterprise', $ipAddress);
}
Expand All @@ -200,10 +188,8 @@ public function enterprise($ipAddress)
* not in the database
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
* is corrupt or invalid
*
* @return \GeoIp2\Model\Isp
*/
public function isp($ipAddress)
public function isp(string $ipAddress): \GeoIp2\Model\Isp
{
return $this->flatModelFor(
'Isp',
Expand All @@ -212,7 +198,7 @@ public function isp($ipAddress)
);
}

private function modelFor($class, $type, $ipAddress)
private function modelFor(string $class, string $type, string $ipAddress)
{
list($record, $prefixLen) = $this->getRecord($class, $type, $ipAddress);

Expand All @@ -224,7 +210,7 @@ private function modelFor($class, $type, $ipAddress)
return new $class($record, $this->locales);
}

private function flatModelFor($class, $type, $ipAddress)
private function flatModelFor(string $class, string $type, string $ipAddress)
{
list($record, $prefixLen) = $this->getRecord($class, $type, $ipAddress);

Expand All @@ -235,7 +221,7 @@ private function flatModelFor($class, $type, $ipAddress)
return new $class($record);
}

private function getRecord($class, $type, $ipAddress)
private function getRecord(string $class, string $type, string $ipAddress): array
{
if (strpos($this->dbType, $type) === false) {
$method = lcfirst($class);
Expand Down Expand Up @@ -272,15 +258,15 @@ private function getRecord($class, $type, $ipAddress)
*
* @return \MaxMind\Db\Reader\Metadata object for the database
*/
public function metadata()
public function metadata(): \MaxMind\Db\Reader\Metadata
{
return $this->dbReader->metadata();
}

/**
* Closes the GeoIP2 database and returns the resources to the system.
*/
public function close()
public function close(): void
{
$this->dbReader->close();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/maxmind/GeoIp2/Exception/AddressNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace GeoIp2\Exception;

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/maxmind/GeoIp2/Exception/AuthenticationException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace GeoIp2\Exception;

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/maxmind/GeoIp2/Exception/GeoIp2Exception.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace GeoIp2\Exception;

/**
Expand Down
8 changes: 5 additions & 3 deletions lib/maxmind/GeoIp2/Exception/HttpException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace GeoIp2\Exception;

/**
Expand All @@ -13,9 +15,9 @@ class HttpException extends GeoIp2Exception
public $uri;

public function __construct(
$message,
$httpStatus,
$uri,
string $message,
int $httpStatus,
string $uri,
\Exception $previous = null
) {
$this->uri = $uri;
Expand Down
10 changes: 6 additions & 4 deletions lib/maxmind/GeoIp2/Exception/InvalidRequestException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace GeoIp2\Exception;

/**
Expand All @@ -14,10 +16,10 @@ class InvalidRequestException extends HttpException
public $error;

public function __construct(
$message,
$error,
$httpStatus,
$uri,
string $message,
string $error,
int $httpStatus,
string $uri,
\Exception $previous = null
) {
$this->error = $error;
Expand Down
2 changes: 2 additions & 0 deletions lib/maxmind/GeoIp2/Exception/OutOfQueriesException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace GeoIp2\Exception;

/**
Expand Down
20 changes: 7 additions & 13 deletions lib/maxmind/GeoIp2/Model/AbstractModel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace GeoIp2\Model;

/**
Expand All @@ -11,20 +13,16 @@ abstract class AbstractModel implements \JsonSerializable

/**
* @ignore
*
* @param mixed $raw
*/
public function __construct($raw)
public function __construct(array $raw)
{
$this->raw = $raw;
}

/**
* @ignore
*
* @param mixed $field
*/
protected function get($field)
protected function get(string $field)
{
if (isset($this->raw[$field])) {
return $this->raw[$field];
Expand All @@ -38,10 +36,8 @@ protected function get($field)

/**
* @ignore
*
* @param mixed $attr
*/
public function __get($attr)
public function __get(string $attr)
{
if ($attr !== 'instance' && property_exists($this, $attr)) {
return $this->$attr;
Expand All @@ -52,15 +48,13 @@ public function __get($attr)

/**
* @ignore
*
* @param mixed $attr
*/
public function __isset($attr)
public function __isset(string $attr): bool
{
return $attr !== 'instance' && isset($this->$attr);
}

public function jsonSerialize()
public function jsonSerialize(): array
{
return $this->raw;
}
Expand Down
10 changes: 7 additions & 3 deletions lib/maxmind/GeoIp2/Model/AnonymousIp.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace GeoIp2\Model;

use GeoIp2\Util;
Expand All @@ -17,6 +19,8 @@
* to a hosting or VPN provider (see description of isAnonymousVpn property).
* @property-read bool $isPublicProxy This is true if the IP address belongs to
* a public proxy.
* @property-read bool $isResidentialProxy This is true if the IP address is
* on a suspected anonymizing network and belongs to a residential ISP.
* @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
Expand All @@ -31,23 +35,23 @@ class AnonymousIp extends AbstractModel
protected $isAnonymousVpn;
protected $isHostingProvider;
protected $isPublicProxy;
protected $isResidentialProxy;
protected $isTorExitNode;
protected $ipAddress;
protected $network;

/**
* @ignore
*
* @param mixed $raw
*/
public function __construct($raw)
public function __construct(array $raw)
{
parent::__construct($raw);

$this->isAnonymous = $this->get('is_anonymous');
$this->isAnonymousVpn = $this->get('is_anonymous_vpn');
$this->isHostingProvider = $this->get('is_hosting_provider');
$this->isPublicProxy = $this->get('is_public_proxy');
$this->isResidentialProxy = $this->get('is_residential_proxy');
$this->isTorExitNode = $this->get('is_tor_exit_node');
$ipAddress = $this->get('ip_address');
$this->ipAddress = $ipAddress;
Expand Down
6 changes: 3 additions & 3 deletions lib/maxmind/GeoIp2/Model/Asn.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace GeoIp2\Model;

use GeoIp2\Util;
Expand Down Expand Up @@ -27,10 +29,8 @@ class Asn extends AbstractModel

/**
* @ignore
*
* @param mixed $raw
*/
public function __construct($raw)
public function __construct(array $raw)
{
parent::__construct($raw);
$this->autonomousSystemNumber = $this->get('autonomous_system_number');
Expand Down
Loading

0 comments on commit 23b681c

Please sign in to comment.