From a7e1dff56f577cd4945401da2cdb250c3de59c9f Mon Sep 17 00:00:00 2001 From: codisart Date: Fri, 6 Jan 2023 15:17:19 +0100 Subject: [PATCH] chore: #135 Clean a little bit of the syntax Signed-off-by: codisart --- src/GpsPoint.php | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/src/GpsPoint.php b/src/GpsPoint.php index 0c7133ba1..521fba51b 100644 --- a/src/GpsPoint.php +++ b/src/GpsPoint.php @@ -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', ]; /** @@ -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); @@ -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; @@ -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); @@ -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); }