@@ -135,6 +135,8 @@ private function userAgent(): string
135135 * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent
136136 * class to the above exceptions. It will be thrown directly
137137 * if a 200 status code is returned but the body is invalid.
138+ * @throws \InvalidArgumentException if something other than a single IP address or "me" is
139+ * passed to the method
138140 */
139141 public function city (string $ ipAddress = 'me ' ): City
140142 {
@@ -165,6 +167,8 @@ public function city(string $ipAddress = 'me'): City
165167 * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent class to the above exceptions. It
166168 * will be thrown directly if a 200 status code is returned but
167169 * the body is invalid.
170+ * @throws \InvalidArgumentException if something other than a single IP address or "me" is
171+ * passed to the method
168172 */
169173 public function country (string $ ipAddress = 'me ' ): Country
170174 {
@@ -195,6 +199,8 @@ public function country(string $ipAddress = 'me'): Country
195199 * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent
196200 * class to the above exceptions. It will be thrown directly
197201 * if a 200 status code is returned but the body is invalid.
202+ * @throws \InvalidArgumentException if something other than a single IP address or "me" is
203+ * passed to the method
198204 */
199205 public function insights (string $ ipAddress = 'me ' ): Insights
200206 {
@@ -204,6 +210,11 @@ public function insights(string $ipAddress = 'me'): Insights
204210
205211 private function responseFor (string $ endpoint , string $ class , string $ ipAddress ): Country
206212 {
213+ if ($ ipAddress !== 'me ' && !filter_var ($ ipAddress , \FILTER_VALIDATE_IP )) {
214+ throw new \InvalidArgumentException (
215+ "The value \"$ ipAddress \" is not a valid IP address. "
216+ );
217+ }
207218 $ path = implode ('/ ' , [self ::$ basePath , $ endpoint , $ ipAddress ]);
208219
209220 try {
0 commit comments