Skip to content

Commit

Permalink
chore: laminas#135 Extract isValueInbound method
Browse files Browse the repository at this point in the history
Signed-off-by: codisart <[email protected]>
  • Loading branch information
codisart committed Jan 12, 2023
1 parent 815a207 commit 9b9fd8c
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/GpsPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ private function isValidCoordinate(string $value, float $maxBoundary): bool
return false;
}

$doubleLatitude = (double) $value;

if ($doubleLatitude <= $maxBoundary && $doubleLatitude >= $maxBoundary * -1) {
return true;
if (!$this->isValueInbound((float) $value, $maxBoundary)) {
$this->error(self::OUT_OF_BOUNDS);
return false;
}

$this->error(self::OUT_OF_BOUNDS);
return false;
return true;
}

/**
Expand All @@ -85,7 +83,7 @@ private function convertValue(string $value): false|float
return false;
}

return $matches[1][0] + $matches[2][0] / 60 + ((double) $matches[3][0]) / 3600;
return $matches[1][0] + $matches[2][0] / 60 + ((float) $matches[3][0]) / 3600;
}

private function removeWhiteSpace(string $value): string
Expand All @@ -97,4 +95,11 @@ private function removeDegreeSign(string $value): string
{
return str_replace('°', '', $value);
}

private function isValueInbound(float $value, float $boundary): bool
{
$max = $boundary;
$min = -1 * $boundary;
return ($min <= $value && $value <= $max);
}
}

0 comments on commit 9b9fd8c

Please sign in to comment.