From 62a179d2ae4048d7e3e3f13d31a0037a1c211cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20G=C5=82ogosz?= Date: Thu, 13 Jul 2017 21:50:00 +0200 Subject: [PATCH] fix for wrong validation --- src/MeetMe/GeoPoint.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/MeetMe/GeoPoint.php b/src/MeetMe/GeoPoint.php index 63da8f8..f6e2ae4 100644 --- a/src/MeetMe/GeoPoint.php +++ b/src/MeetMe/GeoPoint.php @@ -80,6 +80,7 @@ class GeoPoint */ public function __construct($lat, $lon, $format) { + $this->preValidateParameters($lat, $lon); $this->maxLatitude = (M_PI / 2); $this->minLatitude = -$this->maxLatitude; $this->minLogitude = -$this->maxLongitude; @@ -101,7 +102,7 @@ public function __construct($lat, $lon, $format) ); } - $this->validateParameters($lat, $lon); + $this->validateParameters(); } /** @@ -313,7 +314,7 @@ protected function getGeoPoint($lat, $lon, $format) * @param int|float $lat * @param int|float $lon */ - protected function validateParameters($lat, $lon) + protected function preValidateParameters($lat, $lon) { if (!is_numeric($lat)) { throw new RuntimeException('Latitude must be numeric'); @@ -322,12 +323,19 @@ protected function validateParameters($lat, $lon) if (!is_numeric($lon)) { throw new RuntimeException('Longitude must be numeric'); } + } + /** + * Validates the parameters from the constructor + * + */ + protected function validateParameters() + { if ($this->radLat < $this->minLatitude || $this->radLat > $this->maxLatitude) { throw new RuntimeException('Latitude out of bounds'); } - if ($this->radLon < $this->minLatitude || $this->radLon > $this->maxLatitude) { + if ($this->radLon < $this->minLogitude || $this->radLon > $this->maxLongitude) { throw new RuntimeException('Longitude out of bounds'); } }