Skip to content

Commit f939ded

Browse files
authored
Merge pull request #153 from maxmind/greg/fix-lint
Run new php-cs-linter against code
2 parents b8aee85 + e714388 commit f939ded

6 files changed

Lines changed: 46 additions & 62 deletions

File tree

src/MaxMind/Db/Reader.php

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44

55
namespace MaxMind\Db;
66

7-
use ArgumentCountError;
8-
use BadMethodCallException;
9-
use Exception;
10-
use InvalidArgumentException;
117
use MaxMind\Db\Reader\Decoder;
128
use MaxMind\Db\Reader\InvalidDatabaseException;
139
use MaxMind\Db\Reader\Metadata;
1410
use MaxMind\Db\Reader\Util;
15-
use UnexpectedValueException;
1611

1712
/**
1813
* Instances of this class provide a reader for the MaxMind DB format. IP
@@ -72,30 +67,30 @@ class Reader
7267
* @param string $database
7368
* the MaxMind DB file to use
7469
*
75-
* @throws InvalidArgumentException for invalid database path or unknown arguments
70+
* @throws \InvalidArgumentException for invalid database path or unknown arguments
7671
* @throws InvalidDatabaseException
77-
* if the database is invalid or there is an error reading
78-
* from it
72+
* if the database is invalid or there is an error reading
73+
* from it
7974
*/
8075
public function __construct(string $database)
8176
{
8277
if (\func_num_args() !== 1) {
83-
throw new ArgumentCountError(
78+
throw new \ArgumentCountError(
8479
sprintf('%s() expects exactly 1 parameter, %d given', __METHOD__, \func_num_args())
8580
);
8681
}
8782

8883
$fileHandle = @fopen($database, 'rb');
8984
if ($fileHandle === false) {
90-
throw new InvalidArgumentException(
85+
throw new \InvalidArgumentException(
9186
"The file \"$database\" does not exist or is not readable."
9287
);
9388
}
9489
$this->fileHandle = $fileHandle;
9590

9691
$fileSize = @filesize($database);
9792
if ($fileSize === false) {
98-
throw new UnexpectedValueException(
93+
throw new \UnexpectedValueException(
9994
"Error determining the size of \"$database\"."
10095
);
10196
}
@@ -118,18 +113,18 @@ public function __construct(string $database)
118113
* @param string $ipAddress
119114
* the IP address to look up
120115
*
121-
* @throws BadMethodCallException if this method is called on a closed database
122-
* @throws InvalidArgumentException if something other than a single IP address is passed to the method
116+
* @throws \BadMethodCallException if this method is called on a closed database
117+
* @throws \InvalidArgumentException if something other than a single IP address is passed to the method
123118
* @throws InvalidDatabaseException
124-
* if the database is invalid or there is an error reading
125-
* from it
119+
* if the database is invalid or there is an error reading
120+
* from it
126121
*
127122
* @return mixed the record for the IP address
128123
*/
129124
public function get(string $ipAddress)
130125
{
131126
if (\func_num_args() !== 1) {
132-
throw new ArgumentCountError(
127+
throw new \ArgumentCountError(
133128
sprintf('%s() expects exactly 1 parameter, %d given', __METHOD__, \func_num_args())
134129
);
135130
}
@@ -144,25 +139,25 @@ public function get(string $ipAddress)
144139
* @param string $ipAddress
145140
* the IP address to look up
146141
*
147-
* @throws BadMethodCallException if this method is called on a closed database
148-
* @throws InvalidArgumentException if something other than a single IP address is passed to the method
142+
* @throws \BadMethodCallException if this method is called on a closed database
143+
* @throws \InvalidArgumentException if something other than a single IP address is passed to the method
149144
* @throws InvalidDatabaseException
150-
* if the database is invalid or there is an error reading
151-
* from it
145+
* if the database is invalid or there is an error reading
146+
* from it
152147
*
153148
* @return array an array where the first element is the record and the
154149
* second the network prefix length for the record
155150
*/
156151
public function getWithPrefixLen(string $ipAddress): array
157152
{
158153
if (\func_num_args() !== 1) {
159-
throw new ArgumentCountError(
154+
throw new \ArgumentCountError(
160155
sprintf('%s() expects exactly 1 parameter, %d given', __METHOD__, \func_num_args())
161156
);
162157
}
163158

164159
if (!\is_resource($this->fileHandle)) {
165-
throw new BadMethodCallException(
160+
throw new \BadMethodCallException(
166161
'Attempt to read from a closed MaxMind DB.'
167162
);
168163
}
@@ -179,7 +174,7 @@ private function findAddressInTree(string $ipAddress): array
179174
{
180175
$packedAddr = @inet_pton($ipAddress);
181176
if ($packedAddr === false) {
182-
throw new InvalidArgumentException(
177+
throw new \InvalidArgumentException(
183178
"The value \"$ipAddress\" is not a valid IP address."
184179
);
185180
}
@@ -201,7 +196,7 @@ private function findAddressInTree(string $ipAddress): array
201196
$node = $this->ipV4Start;
202197
}
203198
} elseif ($metadata->ipVersion === 4 && $bitCount === 128) {
204-
throw new InvalidArgumentException(
199+
throw new \InvalidArgumentException(
205200
"Error looking up $ipAddress. You attempted to look up an"
206201
. ' IPv6 address in an IPv4-only database.'
207202
);
@@ -332,23 +327,23 @@ private function findMetadataStart(string $filename): int
332327
}
333328

334329
/**
335-
* @throws InvalidArgumentException if arguments are passed to the method
336-
* @throws BadMethodCallException if the database has been closed
330+
* @throws \InvalidArgumentException if arguments are passed to the method
331+
* @throws \BadMethodCallException if the database has been closed
337332
*
338333
* @return Metadata object for the database
339334
*/
340335
public function metadata(): Metadata
341336
{
342337
if (\func_num_args()) {
343-
throw new ArgumentCountError(
338+
throw new \ArgumentCountError(
344339
sprintf('%s() expects exactly 0 parameters, %d given', __METHOD__, \func_num_args())
345340
);
346341
}
347342

348343
// Not technically required, but this makes it consistent with
349344
// C extension and it allows us to change our implementation later.
350345
if (!\is_resource($this->fileHandle)) {
351-
throw new BadMethodCallException(
346+
throw new \BadMethodCallException(
352347
'Attempt to read from a closed MaxMind DB.'
353348
);
354349
}
@@ -359,19 +354,19 @@ public function metadata(): Metadata
359354
/**
360355
* Closes the MaxMind DB and returns resources to the system.
361356
*
362-
* @throws Exception
363-
* if an I/O error occurs
357+
* @throws \Exception
358+
* if an I/O error occurs
364359
*/
365360
public function close(): void
366361
{
367362
if (\func_num_args()) {
368-
throw new ArgumentCountError(
363+
throw new \ArgumentCountError(
369364
sprintf('%s() expects exactly 0 parameters, %d given', __METHOD__, \func_num_args())
370365
);
371366
}
372367

373368
if (!\is_resource($this->fileHandle)) {
374-
throw new BadMethodCallException(
369+
throw new \BadMethodCallException(
375370
'Attempt to close a closed MaxMind DB.'
376371
);
377372
}

src/MaxMind/Db/Reader/Decoder.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace MaxMind\Db\Reader;
66

77
// @codingStandardsIgnoreLine
8-
use RuntimeException;
98

109
class Decoder
1110
{
@@ -282,7 +281,7 @@ private function decodePointer(int $ctrlByte, int $offset): array
282281
if (\PHP_INT_MAX - $pointerBase >= $pointerOffset) {
283282
$pointer = $pointerOffset + $pointerBase;
284283
} else {
285-
throw new RuntimeException(
284+
throw new \RuntimeException(
286285
'The database offset is too large to be represented on your platform.'
287286
);
288287
}
@@ -324,7 +323,7 @@ private function decodeUint(string $bytes, int $byteLength)
324323
} elseif (\extension_loaded('bcmath')) {
325324
$integer = bcadd(bcmul((string) $integer, '256'), (string) $part);
326325
} else {
327-
throw new RuntimeException(
326+
throw new \RuntimeException(
328327
'The gmp or bcmath extension must be installed to read this database.'
329328
);
330329
}

src/MaxMind/Db/Reader/InvalidDatabaseException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
namespace MaxMind\Db\Reader;
66

7-
use Exception;
8-
97
/**
108
* This class should be thrown when unexpected data is found in the database.
119
*/
12-
class InvalidDatabaseException extends Exception
10+
class InvalidDatabaseException extends \Exception
1311
{
1412
}

src/MaxMind/Db/Reader/Metadata.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace MaxMind\Db\Reader;
66

7-
use ArgumentCountError;
8-
97
/**
108
* This class provides the metadata for the MaxMind DB file.
119
*/
@@ -100,7 +98,7 @@ class Metadata
10098
public function __construct(array $metadata)
10199
{
102100
if (\func_num_args() !== 1) {
103-
throw new ArgumentCountError(
101+
throw new \ArgumentCountError(
104102
sprintf('%s() expects exactly 1 parameter, %d given', __METHOD__, \func_num_args())
105103
);
106104
}

tests/MaxMind/Db/Test/Reader/MetadataTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace MaxMind\Db\Test\Reader;
66

7-
use ArgumentCountError;
87
use MaxMind\Db\Reader\Metadata;
98
use PHPUnit\Framework\TestCase;
109

@@ -45,7 +44,7 @@ public function testConstructor(): void
4544

4645
public function testTooManyConstructorArgs(): void
4746
{
48-
$this->expectException(ArgumentCountError::class);
47+
$this->expectException(\ArgumentCountError::class);
4948
$this->expectExceptionMessage('MaxMind\Db\Reader\Metadata::__construct() expects exactly 1');
5049
new Metadata([], 1);
5150
}
@@ -55,7 +54,7 @@ public function testTooManyConstructorArgs(): void
5554
*/
5655
public function testNoConstructorArgs(): void
5756
{
58-
$this->expectException(ArgumentCountError::class);
57+
$this->expectException(\ArgumentCountError::class);
5958
// @phpstan-ignore-next-line
6059
new Metadata();
6160
}

tests/MaxMind/Db/Test/ReaderTest.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44

55
namespace MaxMind\Db\Test\Reader;
66

7-
use ArgumentCountError;
8-
use BadMethodCallException;
9-
use InvalidArgumentException;
107
use MaxMind\Db\Reader;
118
use MaxMind\Db\Reader\InvalidDatabaseException;
129
use PHPUnit\Framework\TestCase;
13-
use ReflectionClass;
1410

1511
/**
1612
* @coversNothing
@@ -254,9 +250,8 @@ public function testGetWithPrefixLen(): void
254250

255251
public function testV6AddressV4Database(): void
256252
{
257-
$this->expectException(InvalidArgumentException::class);
253+
$this->expectException(\InvalidArgumentException::class);
258254
$this->expectExceptionMessage('Error looking up 2001::. You attempted to look up an IPv6 address in an IPv4-only database');
259-
// @phpstan-ignore-next-line
260255
if (\defined('MaxMind\\Db\\Reader::MMDB_LIB_VERSION') && version_compare(Reader::MMDB_LIB_VERSION, '1.2.0', '<')) {
261256
$this->markTestSkipped('MMDB_LIB_VERSION < 1.2.0');
262257
}
@@ -266,7 +261,7 @@ public function testV6AddressV4Database(): void
266261

267262
public function testIpValidation(): void
268263
{
269-
$this->expectException(InvalidArgumentException::class);
264+
$this->expectException(\InvalidArgumentException::class);
270265
$this->expectExceptionMessage('The value "not_ip" is not a valid IP address.');
271266
$reader = new Reader('tests/data/test-data/MaxMind-DB-test-decoder.mmdb');
272267
$reader->get('not_ip');
@@ -298,7 +293,7 @@ public function testBrokenDataPointer(): void
298293

299294
public function testMissingDatabase(): void
300295
{
301-
$this->expectException(InvalidArgumentException::class);
296+
$this->expectException(\InvalidArgumentException::class);
302297
$this->expectExceptionMessage('The file "file-does-not-exist.mmdb" does not exist or is not readable.');
303298
new Reader('file-does-not-exist.mmdb');
304299
}
@@ -312,7 +307,7 @@ public function testNonDatabase(): void
312307

313308
public function testTooManyConstructorArgs(): void
314309
{
315-
$this->expectException(ArgumentCountError::class);
310+
$this->expectException(\ArgumentCountError::class);
316311
$this->expectExceptionMessage('MaxMind\Db\Reader::__construct() expects exactly 1');
317312
new Reader('README.md', 1);
318313
}
@@ -322,14 +317,14 @@ public function testTooManyConstructorArgs(): void
322317
*/
323318
public function testNoConstructorArgs(): void
324319
{
325-
$this->expectException(ArgumentCountError::class);
320+
$this->expectException(\ArgumentCountError::class);
326321
// @phpstan-ignore-next-line
327322
new Reader();
328323
}
329324

330325
public function testTooManyGetArgs(): void
331326
{
332-
$this->expectException(ArgumentCountError::class);
327+
$this->expectException(\ArgumentCountError::class);
333328
$this->expectExceptionMessage('MaxMind\Db\Reader::get() expects exactly 1');
334329
$reader = new Reader(
335330
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -342,7 +337,7 @@ public function testTooManyGetArgs(): void
342337
*/
343338
public function testNoGetArgs(): void
344339
{
345-
$this->expectException(ArgumentCountError::class);
340+
$this->expectException(\ArgumentCountError::class);
346341
$reader = new Reader(
347342
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
348343
);
@@ -352,7 +347,7 @@ public function testNoGetArgs(): void
352347

353348
public function testMetadataArgs(): void
354349
{
355-
$this->expectException(ArgumentCountError::class);
350+
$this->expectException(\ArgumentCountError::class);
356351
$this->expectExceptionMessage('MaxMind\Db\Reader::metadata() expects exactly 0');
357352
$reader = new Reader(
358353
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -372,7 +367,7 @@ public function testClose(): void
372367

373368
public function testCloseArgs(): void
374369
{
375-
$this->expectException(ArgumentCountError::class);
370+
$this->expectException(\ArgumentCountError::class);
376371
$this->expectExceptionMessage('MaxMind\Db\Reader::close() expects exactly 0');
377372
$reader = new Reader(
378373
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -382,7 +377,7 @@ public function testCloseArgs(): void
382377

383378
public function testDoubleClose(): void
384379
{
385-
$this->expectException(BadMethodCallException::class);
380+
$this->expectException(\BadMethodCallException::class);
386381
$this->expectExceptionMessage('Attempt to close a closed MaxMind DB.');
387382
$reader = new Reader(
388383
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -393,7 +388,7 @@ public function testDoubleClose(): void
393388

394389
public function testClosedGet(): void
395390
{
396-
$this->expectException(BadMethodCallException::class);
391+
$this->expectException(\BadMethodCallException::class);
397392
$this->expectExceptionMessage('Attempt to read from a closed MaxMind DB.');
398393
$reader = new Reader(
399394
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -404,7 +399,7 @@ public function testClosedGet(): void
404399

405400
public function testClosedMetadata(): void
406401
{
407-
$this->expectException(BadMethodCallException::class);
402+
$this->expectException(\BadMethodCallException::class);
408403
$this->expectExceptionMessage('Attempt to read from a closed MaxMind DB.');
409404
$reader = new Reader(
410405
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -415,7 +410,7 @@ public function testClosedMetadata(): void
415410

416411
public function testReaderIsNotFinal(): void
417412
{
418-
$reflectionClass = new ReflectionClass(Reader::class);
413+
$reflectionClass = new \ReflectionClass(Reader::class);
419414
$this->assertFalse($reflectionClass->isFinal());
420415
}
421416

0 commit comments

Comments
 (0)