Skip to content

Commit

Permalink
#7170 Simplifying the geoCoordinate() code
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed Aug 6, 2015
1 parent 2c0c9c6 commit ccf8cb9
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ public static function uploadedFile($file, array $options = [])
*
* ### Options
*
* - `type` - A string of the coordinate format, right now only `longLat`.
* - `type` - A string of the coordinate format, right now only `latLong`.
* - `latLong` - By default `both`, can be `long` and `lat` as well to validate
* only a part of the coordinate.
*
Expand All @@ -1045,18 +1045,17 @@ public static function geoCoordinate($value, array $options = [])
'latLong' => 'both',
'type' => 'latLong'
];
if ($options['type'] !== 'latLong') {
throw new \RuntimeException(sprintf('Unsupported coordinate type "%s".', $options['type']));
}
if ($options['type'] === 'latLong') {
if ($options['latLong'] === 'both') {
$pattern = '/^' . self::$_pattern['latitude'] . ',\s*' . self::$_pattern['longitude'] . '$/';
}
$pattern = '/^' . self::$_pattern['latitude'] . ',\s*' . self::$_pattern['longitude'] . '$/';
if ($options['latLong'] === 'long') {
$pattern = '/^' . self::$_pattern['longitude'] . '$/';
}
if ($options['latLong'] === 'lat') {
$pattern = '/^' . self::$_pattern['latitude'] . '$/';
}
} else {
throw new \RuntimeException(sprintf('Unsupported coordinate type "%s".', $options['type']));
}
return (bool)preg_match($pattern, $value);
}
Expand Down

0 comments on commit ccf8cb9

Please sign in to comment.