Skip to content

Commit

Permalink
fix static analysis flags
Browse files Browse the repository at this point in the history
  • Loading branch information
fokosun committed Sep 21, 2023
1 parent 19213b0 commit dd370ca
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/Utils/LocationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}
Expand Down

0 comments on commit dd370ca

Please sign in to comment.