Skip to content

Commit 78b2297

Browse files
authored
Merge pull request #150 from maxmind/greg/types
Extend type hinting
2 parents 61d9b9b + 2292908 commit 78b2297

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+223
-232
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ dist: trusty
55

66
matrix:
77
include:
8-
- php: '5.6'
9-
- php: '7.0'
10-
- php: '7.1'
118
- php: '7.2'
129
- php: '7.3'
10+
- php: '7.4'
1311
env:
1412
- RUN_LINTER=1
1513
- RUN_SNYK=1
16-
- php: '7.4'
1714
- php: 'master'
1815
- php: 'nightly'
1916
fast_finish: true

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ CHANGELOG
44
2.11.0
55
-------------------
66

7+
* IMPORTANT: PHP 7.2 or greater is now required.
78
* Added the `isResidentialProxy` property to `GeoIp2\Model\AnonymousIP` and
89
`GeoIp2\Record\Traits`.
10+
* Additional type hints have been added.
911

1012
2.10.0 (2019-12-12)
1113
-------------------

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
}
1414
],
1515
"require": {
16-
"maxmind-db/reader": "~1.5",
16+
"maxmind-db/reader": "~1.7",
1717
"maxmind/web-service-common": "~0.6",
18-
"php": ">=5.6",
18+
"php": ">=7.2",
1919
"ext-json": "*"
2020
},
2121
"require-dev": {
2222
"friendsofphp/php-cs-fixer": "2.*",
23-
"phpunit/phpunit": "5.*",
23+
"phpunit/phpunit": "^8.0 || ^9.0",
2424
"squizlabs/php_codesniffer": "3.*"
2525
},
2626
"autoload": {

src/Database/Reader.php

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIp2\Database;
46

57
use GeoIp2\Exception\AddressNotFoundException;
@@ -48,8 +50,8 @@ class Reader implements ProviderInterface
4850
* is corrupt or invalid
4951
*/
5052
public function __construct(
51-
$filename,
52-
$locales = ['en']
53+
string $filename,
54+
array $locales = ['en']
5355
) {
5456
$this->dbReader = new DbReader($filename);
5557
$this->dbType = $this->dbReader->metadata()->databaseType;
@@ -65,10 +67,8 @@ public function __construct(
6567
* not in the database
6668
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
6769
* is corrupt or invalid
68-
*
69-
* @return \GeoIp2\Model\City
7070
*/
71-
public function city($ipAddress)
71+
public function city(string $ipAddress): \GeoIp2\Model\City
7272
{
7373
return $this->modelFor('City', 'City', $ipAddress);
7474
}
@@ -82,10 +82,8 @@ public function city($ipAddress)
8282
* not in the database
8383
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
8484
* is corrupt or invalid
85-
*
86-
* @return \GeoIp2\Model\Country
8785
*/
88-
public function country($ipAddress)
86+
public function country(string $ipAddress): \GeoIp2\Model\Country
8987
{
9088
return $this->modelFor('Country', 'Country', $ipAddress);
9189
}
@@ -99,10 +97,8 @@ public function country($ipAddress)
9997
* not in the database
10098
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
10199
* is corrupt or invalid
102-
*
103-
* @return \GeoIp2\Model\AnonymousIp
104100
*/
105-
public function anonymousIp($ipAddress)
101+
public function anonymousIp(string $ipAddress): \GeoIp2\Model\AnonymousIp
106102
{
107103
return $this->flatModelFor(
108104
'AnonymousIp',
@@ -120,10 +116,8 @@ public function anonymousIp($ipAddress)
120116
* not in the database
121117
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
122118
* is corrupt or invalid
123-
*
124-
* @return \GeoIp2\Model\Asn
125119
*/
126-
public function asn($ipAddress)
120+
public function asn(string $ipAddress): \GeoIp2\Model\Asn
127121
{
128122
return $this->flatModelFor(
129123
'Asn',
@@ -141,10 +135,8 @@ public function asn($ipAddress)
141135
* not in the database
142136
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
143137
* is corrupt or invalid
144-
*
145-
* @return \GeoIp2\Model\ConnectionType
146138
*/
147-
public function connectionType($ipAddress)
139+
public function connectionType(string $ipAddress): \GeoIp2\Model\ConnectionType
148140
{
149141
return $this->flatModelFor(
150142
'ConnectionType',
@@ -162,10 +154,8 @@ public function connectionType($ipAddress)
162154
* not in the database
163155
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
164156
* is corrupt or invalid
165-
*
166-
* @return \GeoIp2\Model\Domain
167157
*/
168-
public function domain($ipAddress)
158+
public function domain(string $ipAddress): \GeoIp2\Model\Domain
169159
{
170160
return $this->flatModelFor(
171161
'Domain',
@@ -183,10 +173,8 @@ public function domain($ipAddress)
183173
* not in the database
184174
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
185175
* is corrupt or invalid
186-
*
187-
* @return \GeoIp2\Model\Enterprise
188176
*/
189-
public function enterprise($ipAddress)
177+
public function enterprise(string $ipAddress): \GeoIp2\Model\Enterprise
190178
{
191179
return $this->modelFor('Enterprise', 'Enterprise', $ipAddress);
192180
}
@@ -200,10 +188,8 @@ public function enterprise($ipAddress)
200188
* not in the database
201189
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
202190
* is corrupt or invalid
203-
*
204-
* @return \GeoIp2\Model\Isp
205191
*/
206-
public function isp($ipAddress)
192+
public function isp(string $ipAddress): \GeoIp2\Model\Isp
207193
{
208194
return $this->flatModelFor(
209195
'Isp',
@@ -212,7 +198,7 @@ public function isp($ipAddress)
212198
);
213199
}
214200

215-
private function modelFor($class, $type, $ipAddress)
201+
private function modelFor(string $class, string $type, string $ipAddress)
216202
{
217203
list($record, $prefixLen) = $this->getRecord($class, $type, $ipAddress);
218204

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

227-
private function flatModelFor($class, $type, $ipAddress)
213+
private function flatModelFor(string $class, string $type, string $ipAddress)
228214
{
229215
list($record, $prefixLen) = $this->getRecord($class, $type, $ipAddress);
230216

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

238-
private function getRecord($class, $type, $ipAddress)
224+
private function getRecord(string $class, string $type, string $ipAddress): array
239225
{
240226
if (strpos($this->dbType, $type) === false) {
241227
$method = lcfirst($class);
@@ -272,15 +258,15 @@ private function getRecord($class, $type, $ipAddress)
272258
*
273259
* @return \MaxMind\Db\Reader\Metadata object for the database
274260
*/
275-
public function metadata()
261+
public function metadata(): \MaxMind\Db\Reader\Metadata
276262
{
277263
return $this->dbReader->metadata();
278264
}
279265

280266
/**
281267
* Closes the GeoIP2 database and returns the resources to the system.
282268
*/
283-
public function close()
269+
public function close(): void
284270
{
285271
$this->dbReader->close();
286272
}

src/Exception/AddressNotFoundException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIp2\Exception;
46

57
/**

src/Exception/AuthenticationException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIp2\Exception;
46

57
/**

src/Exception/GeoIp2Exception.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIp2\Exception;
46

57
/**

src/Exception/HttpException.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIp2\Exception;
46

57
/**
@@ -13,9 +15,9 @@ class HttpException extends GeoIp2Exception
1315
public $uri;
1416

1517
public function __construct(
16-
$message,
17-
$httpStatus,
18-
$uri,
18+
string $message,
19+
int $httpStatus,
20+
string $uri,
1921
\Exception $previous = null
2022
) {
2123
$this->uri = $uri;

src/Exception/InvalidRequestException.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIp2\Exception;
46

57
/**
@@ -14,10 +16,10 @@ class InvalidRequestException extends HttpException
1416
public $error;
1517

1618
public function __construct(
17-
$message,
18-
$error,
19-
$httpStatus,
20-
$uri,
19+
string $message,
20+
string $error,
21+
int $httpStatus,
22+
string $uri,
2123
\Exception $previous = null
2224
) {
2325
$this->error = $error;

src/Exception/OutOfQueriesException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIp2\Exception;
46

57
/**

0 commit comments

Comments
 (0)