44
55namespace MaxMind \Db ;
66
7- use ArgumentCountError ;
8- use BadMethodCallException ;
9- use Exception ;
10- use InvalidArgumentException ;
117use MaxMind \Db \Reader \Decoder ;
128use MaxMind \Db \Reader \InvalidDatabaseException ;
139use MaxMind \Db \Reader \Metadata ;
1410use 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 }
0 commit comments