66
77use GeoIp2 \Exception \AddressNotFoundException ;
88use GeoIp2 \Model \AbstractModel ;
9+ use GeoIp2 \Model \AnonymousIp ;
10+ use GeoIp2 \Model \Asn ;
11+ use GeoIp2 \Model \City ;
12+ use GeoIp2 \Model \ConnectionType ;
13+ use GeoIp2 \Model \Country ;
14+ use GeoIp2 \Model \Domain ;
15+ use GeoIp2 \Model \Enterprise ;
16+ use GeoIp2 \Model \Isp ;
917use GeoIp2 \ProviderInterface ;
1018use MaxMind \Db \Reader as DbReader ;
1119use MaxMind \Db \Reader \InvalidDatabaseException ;
@@ -80,10 +88,10 @@ public function __construct(
8088 * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
8189 * is corrupt or invalid
8290 */
83- public function city (string $ ipAddress ): \ GeoIp2 \ Model \ City
91+ public function city (string $ ipAddress ): City
8492 {
8593 // @phpstan-ignore-next-line
86- return $ this ->modelFor (' City ' , 'City ' , $ ipAddress );
94+ return $ this ->modelFor (City::class , 'City ' , $ ipAddress );
8795 }
8896
8997 /**
@@ -96,10 +104,10 @@ public function city(string $ipAddress): \GeoIp2\Model\City
96104 * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
97105 * is corrupt or invalid
98106 */
99- public function country (string $ ipAddress ): \ GeoIp2 \ Model \ Country
107+ public function country (string $ ipAddress ): Country
100108 {
101109 // @phpstan-ignore-next-line
102- return $ this ->modelFor (' Country ' , 'Country ' , $ ipAddress );
110+ return $ this ->modelFor (Country::class , 'Country ' , $ ipAddress );
103111 }
104112
105113 /**
@@ -112,11 +120,11 @@ public function country(string $ipAddress): \GeoIp2\Model\Country
112120 * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
113121 * is corrupt or invalid
114122 */
115- public function anonymousIp (string $ ipAddress ): \ GeoIp2 \ Model \ AnonymousIp
123+ public function anonymousIp (string $ ipAddress ): AnonymousIp
116124 {
117125 // @phpstan-ignore-next-line
118126 return $ this ->flatModelFor (
119- ' AnonymousIp ' ,
127+ AnonymousIp::class ,
120128 'GeoIP2-Anonymous-IP ' ,
121129 $ ipAddress
122130 );
@@ -132,11 +140,11 @@ public function anonymousIp(string $ipAddress): \GeoIp2\Model\AnonymousIp
132140 * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
133141 * is corrupt or invalid
134142 */
135- public function asn (string $ ipAddress ): \ GeoIp2 \ Model \ Asn
143+ public function asn (string $ ipAddress ): Asn
136144 {
137145 // @phpstan-ignore-next-line
138146 return $ this ->flatModelFor (
139- ' Asn ' ,
147+ Asn::class ,
140148 'GeoLite2-ASN ' ,
141149 $ ipAddress
142150 );
@@ -152,11 +160,11 @@ public function asn(string $ipAddress): \GeoIp2\Model\Asn
152160 * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
153161 * is corrupt or invalid
154162 */
155- public function connectionType (string $ ipAddress ): \ GeoIp2 \ Model \ ConnectionType
163+ public function connectionType (string $ ipAddress ): ConnectionType
156164 {
157165 // @phpstan-ignore-next-line
158166 return $ this ->flatModelFor (
159- ' ConnectionType ' ,
167+ ConnectionType::class ,
160168 'GeoIP2-Connection-Type ' ,
161169 $ ipAddress
162170 );
@@ -172,11 +180,11 @@ public function connectionType(string $ipAddress): \GeoIp2\Model\ConnectionType
172180 * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
173181 * is corrupt or invalid
174182 */
175- public function domain (string $ ipAddress ): \ GeoIp2 \ Model \ Domain
183+ public function domain (string $ ipAddress ): Domain
176184 {
177185 // @phpstan-ignore-next-line
178186 return $ this ->flatModelFor (
179- ' Domain ' ,
187+ Domain::class ,
180188 'GeoIP2-Domain ' ,
181189 $ ipAddress
182190 );
@@ -192,10 +200,10 @@ public function domain(string $ipAddress): \GeoIp2\Model\Domain
192200 * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
193201 * is corrupt or invalid
194202 */
195- public function enterprise (string $ ipAddress ): \ GeoIp2 \ Model \ Enterprise
203+ public function enterprise (string $ ipAddress ): Enterprise
196204 {
197205 // @phpstan-ignore-next-line
198- return $ this ->modelFor (' Enterprise ' , 'Enterprise ' , $ ipAddress );
206+ return $ this ->modelFor (Enterprise::class , 'Enterprise ' , $ ipAddress );
199207 }
200208
201209 /**
@@ -208,11 +216,11 @@ public function enterprise(string $ipAddress): \GeoIp2\Model\Enterprise
208216 * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
209217 * is corrupt or invalid
210218 */
211- public function isp (string $ ipAddress ): \ GeoIp2 \ Model \ Isp
219+ public function isp (string $ ipAddress ): Isp
212220 {
213221 // @phpstan-ignore-next-line
214222 return $ this ->flatModelFor (
215- ' Isp ' ,
223+ Isp::class ,
216224 'GeoIP2-ISP ' ,
217225 $ ipAddress
218226 );
@@ -225,8 +233,6 @@ private function modelFor(string $class, string $type, string $ipAddress): Abstr
225233 $ record ['traits ' ]['ip_address ' ] = $ ipAddress ;
226234 $ record ['traits ' ]['prefix_len ' ] = $ prefixLen ;
227235
228- $ class = 'GeoIp2 \\Model \\' . $ class ;
229-
230236 return new $ class ($ record , $ this ->locales );
231237 }
232238
@@ -236,15 +242,14 @@ private function flatModelFor(string $class, string $type, string $ipAddress): A
236242
237243 $ record ['ip_address ' ] = $ ipAddress ;
238244 $ record ['prefix_len ' ] = $ prefixLen ;
239- $ class = 'GeoIp2 \\Model \\' . $ class ;
240245
241246 return new $ class ($ record );
242247 }
243248
244249 private function getRecord (string $ class , string $ type , string $ ipAddress ): array
245250 {
246251 if (strpos ($ this ->dbType , $ type ) === false ) {
247- $ method = lcfirst ($ class );
252+ $ method = lcfirst (( new \ ReflectionClass ( $ class))-> getShortName () );
248253
249254 throw new \BadMethodCallException (
250255 "The $ method method cannot be used to open a {$ this ->dbType } database "
0 commit comments