diff --git a/psalm-baseline.xml b/psalm-baseline.xml index c09d39b9..f076966d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1513,10 +1513,6 @@ - - $value === false || $value === null - $value === null - $matches[1][0] $matches[2][0] diff --git a/src/GpsPoint.php b/src/GpsPoint.php index dd3fcb5b..93918495 100644 --- a/src/GpsPoint.php +++ b/src/GpsPoint.php @@ -3,6 +3,7 @@ namespace Laminas\Validator; use function explode; +use function is_numeric; use function preg_match; use function preg_match_all; use function preg_replace; @@ -53,12 +54,18 @@ private function isValidCoordinate(string $value, float $maxBoundary): bool $value = $this->removeDegreeSign($value); } - if ($value === false || $value === null || !is_numeric($value)) { + if ($value === false) { $this->error(self::CONVERT_ERROR); return false; } - if (!$this->isValueInbound((float) $value, $maxBoundary)) { + $castedValue = (float) $value; + if (! is_numeric($value) && $castedValue === 0.0) { + $this->error(self::CONVERT_ERROR); + return false; + } + + if (! $this->isValueInbound($castedValue, $maxBoundary)) { $this->error(self::OUT_OF_BOUNDS); return false; } @@ -100,6 +107,6 @@ private function isValueInbound(float $value, float $boundary): bool { $max = $boundary; $min = -1 * $boundary; - return ($min <= $value && $value <= $max); + return $min <= $value && $value <= $max; } } diff --git a/test/GPSPointTest.php b/test/GPSPointTest.php index 26d007fd..dab43bd6 100644 --- a/test/GPSPointTest.php +++ b/test/GPSPointTest.php @@ -73,11 +73,12 @@ public static function basicDataProvider(): array public static function errorMessageTestValues(): array { return [ - ['63 47 24.691 N, 18 2 54.363 W', GpsPoint::CONVERT_ERROR, '63 47 24.691 N'], + ['63 47 24.691 N, 18 2 54.363 W', GpsPoint::OUT_OF_BOUNDS, '63 47 24.691 N'], ['65° 4\' N,-22.728867530822754', GpsPoint::CONVERT_ERROR, '65° 4\' N'], ['° \' " N,° \' " E', GpsPoint::CONVERT_ERROR, '° \' " N'], ['° \' " N', GpsPoint::INCOMPLETE_COORDINATE, '° \' " N'], ['foo,bar', GpsPoint::CONVERT_ERROR, 'foo'], + [' ,-22.4', GpsPoint::CONVERT_ERROR, ' '], ]; } }