Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for wrong validation #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/MeetMe/GeoPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -101,7 +102,7 @@ public function __construct($lat, $lon, $format)
);
}

$this->validateParameters($lat, $lon);
$this->validateParameters();
}

/**
Expand Down Expand Up @@ -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');
Expand All @@ -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');
}
}
Expand Down