diff --git a/src/GpsPoint.php b/src/GpsPoint.php index 521fba51..3078b68c 100644 --- a/src/GpsPoint.php +++ b/src/GpsPoint.php @@ -58,14 +58,12 @@ private function isValidCoordinate(string $value, float $maxBoundary): bool return false; } - $doubleLatitude = (double) $value; - - if ($doubleLatitude <= $maxBoundary && $doubleLatitude >= $maxBoundary * -1) { - return true; + if (!$this->isValueInbound((float) $value, $maxBoundary)) { + $this->error(self::OUT_OF_BOUNDS); + return false; } - $this->error(self::OUT_OF_BOUNDS); - return false; + return true; } /** @@ -85,7 +83,7 @@ private function convertValue(string $value): false|float return false; } - return $matches[1][0] + $matches[2][0] / 60 + ((double) $matches[3][0]) / 3600; + return $matches[1][0] + $matches[2][0] / 60 + ((float) $matches[3][0]) / 3600; } private function removeWhiteSpace(string $value): string @@ -97,4 +95,11 @@ private function removeDegreeSign(string $value): string { return str_replace('°', '', $value); } + + private function isValueInbound(float $value, float $boundary): bool + { + $max = $boundary; + $min = -1 * $boundary; + return ($min <= $value && $value <= $max); + } }