Skip to content

Commit ea64f0c

Browse files
authored
Merge pull request #158 from maxmind/greg/phpstan
Lint with phpstan
2 parents 762d7e7 + 6ff3ae9 commit ea64f0c

32 files changed

+279
-83
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ jobs:
2323

2424
- name: Lint with phpcs
2525
run: vendor/bin/phpcs --standard=PSR2 src/
26+
27+
- name: Lint with phpstan
28+
run: vendor/bin/phpstan analyze

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"require-dev": {
2222
"friendsofphp/php-cs-fixer": "*",
2323
"phpunit/phpunit": "^8.0 || ^9.0",
24-
"squizlabs/php_codesniffer": "3.*"
24+
"squizlabs/php_codesniffer": "3.*",
25+
"phpstan/phpstan": "*"
2526
},
2627
"autoload": {
2728
"psr-4": {

phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src
5+
- tests
6+
checkMissingIterableValueType: false
7+

src/Database/Reader.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace GeoIp2\Database;
66

77
use GeoIp2\Exception\AddressNotFoundException;
8+
use GeoIp2\Model\AbstractModel;
89
use GeoIp2\ProviderInterface;
910
use MaxMind\Db\Reader as DbReader;
1011
use MaxMind\Db\Reader\InvalidDatabaseException;
@@ -35,8 +36,17 @@
3536
*/
3637
class Reader implements ProviderInterface
3738
{
39+
/**
40+
* @var DbReader
41+
*/
3842
private $dbReader;
43+
/**
44+
* @var string
45+
*/
3946
private $dbType;
47+
/**
48+
* @var array<string>
49+
*/
4050
private $locales;
4151

4252
/**
@@ -70,6 +80,7 @@ public function __construct(
7080
*/
7181
public function city(string $ipAddress): \GeoIp2\Model\City
7282
{
83+
// @phpstan-ignore-next-line
7384
return $this->modelFor('City', 'City', $ipAddress);
7485
}
7586

@@ -85,6 +96,7 @@ public function city(string $ipAddress): \GeoIp2\Model\City
8596
*/
8697
public function country(string $ipAddress): \GeoIp2\Model\Country
8798
{
99+
// @phpstan-ignore-next-line
88100
return $this->modelFor('Country', 'Country', $ipAddress);
89101
}
90102

@@ -100,6 +112,7 @@ public function country(string $ipAddress): \GeoIp2\Model\Country
100112
*/
101113
public function anonymousIp(string $ipAddress): \GeoIp2\Model\AnonymousIp
102114
{
115+
// @phpstan-ignore-next-line
103116
return $this->flatModelFor(
104117
'AnonymousIp',
105118
'GeoIP2-Anonymous-IP',
@@ -119,6 +132,7 @@ public function anonymousIp(string $ipAddress): \GeoIp2\Model\AnonymousIp
119132
*/
120133
public function asn(string $ipAddress): \GeoIp2\Model\Asn
121134
{
135+
// @phpstan-ignore-next-line
122136
return $this->flatModelFor(
123137
'Asn',
124138
'GeoLite2-ASN',
@@ -138,6 +152,7 @@ public function asn(string $ipAddress): \GeoIp2\Model\Asn
138152
*/
139153
public function connectionType(string $ipAddress): \GeoIp2\Model\ConnectionType
140154
{
155+
// @phpstan-ignore-next-line
141156
return $this->flatModelFor(
142157
'ConnectionType',
143158
'GeoIP2-Connection-Type',
@@ -157,6 +172,7 @@ public function connectionType(string $ipAddress): \GeoIp2\Model\ConnectionType
157172
*/
158173
public function domain(string $ipAddress): \GeoIp2\Model\Domain
159174
{
175+
// @phpstan-ignore-next-line
160176
return $this->flatModelFor(
161177
'Domain',
162178
'GeoIP2-Domain',
@@ -176,6 +192,7 @@ public function domain(string $ipAddress): \GeoIp2\Model\Domain
176192
*/
177193
public function enterprise(string $ipAddress): \GeoIp2\Model\Enterprise
178194
{
195+
// @phpstan-ignore-next-line
179196
return $this->modelFor('Enterprise', 'Enterprise', $ipAddress);
180197
}
181198

@@ -191,14 +208,15 @@ public function enterprise(string $ipAddress): \GeoIp2\Model\Enterprise
191208
*/
192209
public function isp(string $ipAddress): \GeoIp2\Model\Isp
193210
{
211+
// @phpstan-ignore-next-line
194212
return $this->flatModelFor(
195213
'Isp',
196214
'GeoIP2-ISP',
197215
$ipAddress
198216
);
199217
}
200218

201-
private function modelFor(string $class, string $type, string $ipAddress)
219+
private function modelFor(string $class, string $type, string $ipAddress): AbstractModel
202220
{
203221
list($record, $prefixLen) = $this->getRecord($class, $type, $ipAddress);
204222

@@ -210,7 +228,7 @@ private function modelFor(string $class, string $type, string $ipAddress)
210228
return new $class($record, $this->locales);
211229
}
212230

213-
private function flatModelFor(string $class, string $type, string $ipAddress)
231+
private function flatModelFor(string $class, string $type, string $ipAddress): AbstractModel
214232
{
215233
list($record, $prefixLen) = $this->getRecord($class, $type, $ipAddress);
216234

src/Exception/HttpException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class HttpException extends GeoIp2Exception
1111
{
1212
/**
1313
* The URI queried.
14+
*
15+
* @var string
1416
*/
1517
public $uri;
1618

src/Exception/InvalidRequestException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class InvalidRequestException extends HttpException
1212
{
1313
/**
1414
* The code returned by the MaxMind web service.
15+
*
16+
* @var string
1517
*/
1618
public $error;
1719

src/Model/AbstractModel.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
abstract class AbstractModel implements \JsonSerializable
1111
{
12+
/**
13+
* @var array<string, mixed>
14+
*/
1215
protected $raw;
1316

1417
/**
@@ -21,6 +24,8 @@ public function __construct(array $raw)
2124

2225
/**
2326
* @ignore
27+
*
28+
* @return mixed
2429
*/
2530
protected function get(string $field)
2631
{
@@ -36,6 +41,8 @@ protected function get(string $field)
3641

3742
/**
3843
* @ignore
44+
*
45+
* @return mixed
3946
*/
4047
public function __get(string $attr)
4148
{

src/Model/AnonymousIp.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,37 @@
3131
*/
3232
class AnonymousIp extends AbstractModel
3333
{
34+
/**
35+
* @var bool
36+
*/
3437
protected $isAnonymous;
38+
/**
39+
* @var bool
40+
*/
3541
protected $isAnonymousVpn;
42+
/**
43+
* @var bool
44+
*/
3645
protected $isHostingProvider;
46+
/**
47+
* @var bool
48+
*/
3749
protected $isPublicProxy;
50+
/**
51+
* @var bool
52+
*/
3853
protected $isResidentialProxy;
54+
/**
55+
* @var bool
56+
*/
3957
protected $isTorExitNode;
58+
/**
59+
* @var string
60+
*/
4061
protected $ipAddress;
62+
/**
63+
* @var string
64+
*/
4165
protected $network;
4266

4367
/**

src/Model/Asn.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,21 @@
2222
*/
2323
class Asn extends AbstractModel
2424
{
25+
/**
26+
* @var int|null
27+
*/
2528
protected $autonomousSystemNumber;
29+
/**
30+
* @var string|null
31+
*/
2632
protected $autonomousSystemOrganization;
33+
/**
34+
* @var string
35+
*/
2736
protected $ipAddress;
37+
/**
38+
* @var string
39+
*/
2840
protected $network;
2941

3042
/**

src/Model/City.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,26 @@ class City extends Country
3333
{
3434
/**
3535
* @ignore
36+
*
37+
* @var \GeoIp2\Record\City
3638
*/
3739
protected $city;
3840
/**
3941
* @ignore
42+
*
43+
* @var \GeoIp2\Record\Location
4044
*/
4145
protected $location;
4246
/**
4347
* @ignore
48+
*
49+
* @var \GeoIp2\Record\Postal
4450
*/
4551
protected $postal;
4652
/**
4753
* @ignore
54+
*
55+
* @var array<\GeoIp2\Record\Subdivision>
4856
*/
4957
protected $subdivisions = [];
5058

@@ -77,6 +85,8 @@ private function createSubdivisions(array $raw, array $locales): void
7785

7886
/**
7987
* @ignore
88+
*
89+
* @return mixed
8090
*/
8191
public function __get(string $attr)
8292
{

0 commit comments

Comments
 (0)