From dd370ca3be0c8816a2119abc4494536b28e580c4 Mon Sep 17 00:00:00 2001 From: fokosun Date: Thu, 21 Sep 2023 15:24:44 -0400 Subject: [PATCH] fix static analysis flags --- app/Utils/LocationHelper.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Utils/LocationHelper.php b/app/Utils/LocationHelper.php index 31800bc2..b29dd547 100644 --- a/app/Utils/LocationHelper.php +++ b/app/Utils/LocationHelper.php @@ -26,10 +26,14 @@ public static function getLocFromIpAddress(string $ipAddress): string ) ->where('ip2nation.ip', '=', $sanitizeIp) ->get(['ip2nationCountries.lon', 'ip2nationCountries.lat']) - ->first(); + ->toArray(); - if ($lonLat->lon !== null && $lonLat->lat !== null) { - return sprintf("%s,%s", number_format($lonLat->lon, 4), number_format($lonLat->lat, 4)); + if (count($lonLat) > 0) { + return sprintf( + "%s,%s", + number_format($lonLat[0]->lon, 4), + number_format($lonLat[0]->lat, 4) + ); } return sprintf("%s,%s", "unknown", "unknown"); @@ -45,15 +49,15 @@ public static function getCountryCodeFromIpAddress(string $ipAddress): string $country = DB::table('ip2nation') ->where('ip', '=', $sanitizeIp) ->pluck('country') - ->first(); + ->toArray(); } - return sprintf("%s", $country); + return sprintf("%s", $country[0]); } private static function isPrivate(string $ipAddress) { - $privateIps = ["172.21.0.1"]; + $privateIps = ["172.21.0.1", "0.0.0.0", "127.0.0.1", "192.169.0.1"]; return in_array($ipAddress, $privateIps); }