Skip to content

Commit a828140

Browse files
committed
Run new php-cs-linter against code
1 parent b8aee85 commit a828140

6 files changed

Lines changed: 46 additions & 61 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 & 17 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,7 +250,7 @@ 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');
259255
// @phpstan-ignore-next-line
260256
if (\defined('MaxMind\\Db\\Reader::MMDB_LIB_VERSION') && version_compare(Reader::MMDB_LIB_VERSION, '1.2.0', '<')) {
@@ -266,7 +262,7 @@ public function testV6AddressV4Database(): void
266262

267263
public function testIpValidation(): void
268264
{
269-
$this->expectException(InvalidArgumentException::class);
265+
$this->expectException(\InvalidArgumentException::class);
270266
$this->expectExceptionMessage('The value "not_ip" is not a valid IP address.');
271267
$reader = new Reader('tests/data/test-data/MaxMind-DB-test-decoder.mmdb');
272268
$reader->get('not_ip');
@@ -298,7 +294,7 @@ public function testBrokenDataPointer(): void
298294

299295
public function testMissingDatabase(): void
300296
{
301-
$this->expectException(InvalidArgumentException::class);
297+
$this->expectException(\InvalidArgumentException::class);
302298
$this->expectExceptionMessage('The file "file-does-not-exist.mmdb" does not exist or is not readable.');
303299
new Reader('file-does-not-exist.mmdb');
304300
}
@@ -312,7 +308,7 @@ public function testNonDatabase(): void
312308

313309
public function testTooManyConstructorArgs(): void
314310
{
315-
$this->expectException(ArgumentCountError::class);
311+
$this->expectException(\ArgumentCountError::class);
316312
$this->expectExceptionMessage('MaxMind\Db\Reader::__construct() expects exactly 1');
317313
new Reader('README.md', 1);
318314
}
@@ -322,14 +318,14 @@ public function testTooManyConstructorArgs(): void
322318
*/
323319
public function testNoConstructorArgs(): void
324320
{
325-
$this->expectException(ArgumentCountError::class);
321+
$this->expectException(\ArgumentCountError::class);
326322
// @phpstan-ignore-next-line
327323
new Reader();
328324
}
329325

330326
public function testTooManyGetArgs(): void
331327
{
332-
$this->expectException(ArgumentCountError::class);
328+
$this->expectException(\ArgumentCountError::class);
333329
$this->expectExceptionMessage('MaxMind\Db\Reader::get() expects exactly 1');
334330
$reader = new Reader(
335331
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -342,7 +338,7 @@ public function testTooManyGetArgs(): void
342338
*/
343339
public function testNoGetArgs(): void
344340
{
345-
$this->expectException(ArgumentCountError::class);
341+
$this->expectException(\ArgumentCountError::class);
346342
$reader = new Reader(
347343
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
348344
);
@@ -352,7 +348,7 @@ public function testNoGetArgs(): void
352348

353349
public function testMetadataArgs(): void
354350
{
355-
$this->expectException(ArgumentCountError::class);
351+
$this->expectException(\ArgumentCountError::class);
356352
$this->expectExceptionMessage('MaxMind\Db\Reader::metadata() expects exactly 0');
357353
$reader = new Reader(
358354
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -372,7 +368,7 @@ public function testClose(): void
372368

373369
public function testCloseArgs(): void
374370
{
375-
$this->expectException(ArgumentCountError::class);
371+
$this->expectException(\ArgumentCountError::class);
376372
$this->expectExceptionMessage('MaxMind\Db\Reader::close() expects exactly 0');
377373
$reader = new Reader(
378374
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -382,7 +378,7 @@ public function testCloseArgs(): void
382378

383379
public function testDoubleClose(): void
384380
{
385-
$this->expectException(BadMethodCallException::class);
381+
$this->expectException(\BadMethodCallException::class);
386382
$this->expectExceptionMessage('Attempt to close a closed MaxMind DB.');
387383
$reader = new Reader(
388384
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -393,7 +389,7 @@ public function testDoubleClose(): void
393389

394390
public function testClosedGet(): void
395391
{
396-
$this->expectException(BadMethodCallException::class);
392+
$this->expectException(\BadMethodCallException::class);
397393
$this->expectExceptionMessage('Attempt to read from a closed MaxMind DB.');
398394
$reader = new Reader(
399395
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -404,7 +400,7 @@ public function testClosedGet(): void
404400

405401
public function testClosedMetadata(): void
406402
{
407-
$this->expectException(BadMethodCallException::class);
403+
$this->expectException(\BadMethodCallException::class);
408404
$this->expectExceptionMessage('Attempt to read from a closed MaxMind DB.');
409405
$reader = new Reader(
410406
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
@@ -415,7 +411,7 @@ public function testClosedMetadata(): void
415411

416412
public function testReaderIsNotFinal(): void
417413
{
418-
$reflectionClass = new ReflectionClass(Reader::class);
414+
$reflectionClass = new \ReflectionClass(Reader::class);
419415
$this->assertFalse($reflectionClass->isFinal());
420416
}
421417

0 commit comments

Comments
 (0)