From 9220418d6a5d02a16d7ac8b0bca69772d4f4d3e0 Mon Sep 17 00:00:00 2001 From: codisart Date: Thu, 12 Jan 2023 10:32:39 +0100 Subject: [PATCH] bug: #135 Add numeric state test to check if string is a real number --- src/GpsPoint.php | 2 +- test/GPSPointTest.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/GpsPoint.php b/src/GpsPoint.php index 3078b68c..dd3fcb5b 100644 --- a/src/GpsPoint.php +++ b/src/GpsPoint.php @@ -53,7 +53,7 @@ private function isValidCoordinate(string $value, float $maxBoundary): bool $value = $this->removeDegreeSign($value); } - if ($value === false || $value === null) { + if ($value === false || $value === null || !is_numeric($value)) { $this->error(self::CONVERT_ERROR); return false; } diff --git a/test/GPSPointTest.php b/test/GPSPointTest.php index d5304d7e..62e46599 100644 --- a/test/GPSPointTest.php +++ b/test/GPSPointTest.php @@ -86,10 +86,11 @@ public function basicDataProvider(): array public function errorMessageTestValues(): array { return [ - ['63 47 24.691 N, 18 2 54.363 W', GpsPoint::OUT_OF_BOUNDS, '63 47 24.691 N'], + ['63 47 24.691 N, 18 2 54.363 W', GpsPoint::CONVERT_ERROR, '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, '° \' " N'], + ['foo,bar', GpsPoint::CONVERT_ERROR, 'foo'], ]; } }