diff --git a/src/GpsPoint.php b/src/GpsPoint.php index 0c7133ba..521fba51 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); }