Skip to content

Commit

Permalink
chore: laminas#135 Clean a little bit of the syntax
Browse files Browse the repository at this point in the history
Signed-off-by: codisart <[email protected]>
  • Loading branch information
codisart committed Feb 21, 2024
1 parent 84e1ae5 commit a7e1dff
Showing 1 changed file with 10 additions and 32 deletions.
42 changes: 10 additions & 32 deletions src/GpsPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ final class GpsPoint extends AbstractValidator
public const CONVERT_ERROR = 'gpsPointConvertError';
public const INCOMPLETE_COORDINATE = 'gpsPointIncompleteCoordinate';

/** @var array */
protected $messageTemplates = [
'gpsPointOutOfBounds' => '%value% is out of Bounds.',
'gpsPointConvertError' => '%value% can not converted into a Decimal Degree Value.',
'gpsPointIncompleteCoordinate' => '%value% did not provided a complete Coordinate',
protected array $messageTemplates = [
self::OUT_OF_BOUNDS => '%value% is out of Bounds.',
self::CONVERT_ERROR => '%value% can not converted into a Decimal Degree Value.',
self::INCOMPLETE_COORDINATE => '%value% did not provided a complete Coordinate',
];

/**
Expand All @@ -29,11 +28,9 @@ final class GpsPoint extends AbstractValidator
* getMessages() will return an array of messages that explain why the
* validation failed.
*
* @param mixed $value
* @return bool
* @throws Exception\RuntimeException If validation of $value is impossible.
*/
public function isValid($value)
public function isValid(mixed $value): bool
{
if (! str_contains($value, ',')) {
$this->error(self::INCOMPLETE_COORDINATE, $value);
Expand All @@ -42,17 +39,10 @@ public function isValid($value)

[$lat, $long] = explode(',', $value);

if ($this->isValidCoordinate($lat, 90.0000) && $this->isValidCoordinate($long, 180.000)) {
return true;
}

return false;
return $this->isValidCoordinate($lat, 90.0000) && $this->isValidCoordinate($long, 180.000);
}

/**
* @param string $value
*/
private function isValidCoordinate($value, float $maxBoundary): bool
private function isValidCoordinate(string $value, float $maxBoundary): bool
{
$this->value = $value;

Expand Down Expand Up @@ -86,11 +76,7 @@ private function isDMSValue(string $value): bool
return preg_match('/([°\'"]+[NESW])/', $value) > 0;
}

/**
* @param string $value
* @return false|float
*/
private function convertValue($value)
private function convertValue(string $value): false|float
{
$matches = [];
$result = preg_match_all('/(\d{1,3})°(\d{1,2})\'(\d{1,2}[\.\d]{0,6})"[NESW]/i', $value, $matches);
Expand All @@ -102,20 +88,12 @@ private function convertValue($value)
return $matches[1][0] + $matches[2][0] / 60 + ((double) $matches[3][0]) / 3600;
}

/**
* @param string $value
* @return string
*/
private function removeWhiteSpace($value)
private function removeWhiteSpace(string $value): string
{
return preg_replace('/\s/', '', $value);
}

/**
* @param string $value
* @return string
*/
private function removeDegreeSign($value)
private function removeDegreeSign(string $value): string
{
return str_replace('°', '', $value);
}
Expand Down

0 comments on commit a7e1dff

Please sign in to comment.