Skip to content

Commit

Permalink
Additional validation on the LatLong entity object.
Browse files Browse the repository at this point in the history
  • Loading branch information
allebb committed Nov 24, 2014
1 parent 67d82b6 commit 7fca180
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Distical/Entities/LatLong.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,32 @@ class LatLong

public function __construct($lat, $lng)
{

$this->lat = $lat;
$this->lng = $lng;
if(!$this->validateLat()){
throw new Exception('The latitude parameter is invalid, should be between -90 and 90');
}
if(!$this->validateLng()){
throw new Exception('The longitude parameter is invalid, should be between -180 and 180');
}
}

private function validateLat()
{

return preg_match(this::LAT_VALIDATION_REGEX, $this->lat);
}

private function validateLng()
{
return preg_match(this::LNG_VALIDATION_REGEX, $this->lng);
}

public function getLatitude()
{
return $this->lat;
}

public function getLongditude()
public function getLongitude()
{
return $this->long;
}
Expand All @@ -38,7 +50,7 @@ public function getLat()

public function getLng()
{
return $this->getLongditude();
return $this->getLongitude();
}

}

0 comments on commit 7fca180

Please sign in to comment.