From a4be87506ff0a7ef807a7860dd0b540fa08046d6 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Tue, 23 Sep 2025 20:45:23 +0100 Subject: [PATCH] Various cleanup and PHP 8 syntax --- src/Formatters/GlobeCoordinateFormatter.php | 5 +--- src/Formatters/LatLongFormatter.php | 17 ++++------- src/GlobeMath.php | 12 +++----- src/PackagePrivate/LatLongPrecisionParser.php | 7 ++--- src/PackagePrivate/PreciseLatLong.php | 8 +----- src/PackagePrivate/Precision.php | 4 ++- src/PackagePrivate/PrecisionParser.php | 8 +----- src/Parsers/DdCoordinateParser.php | 28 +++++++------------ src/Parsers/DmCoordinateParser.php | 16 +++-------- src/Parsers/DmsCoordinateParser.php | 14 ++++------ src/Parsers/FloatCoordinateParser.php | 12 ++++---- src/Parsers/GlobeCoordinateParser.php | 3 +- src/Parsers/LatLongParser.php | 9 ++---- src/Parsers/LatLongParserBase.php | 8 ++---- src/Values/GlobeCoordinateValue.php | 4 +-- src/Values/LatLongValue.php | 6 ++-- tests/unit/GlobeMathTest.php | 5 +--- tests/unit/PackagePrivate/PrecisionTest.php | 5 ++-- tests/unit/Parsers/DdCoordinateParserTest.php | 8 ++---- tests/unit/Parsers/DmCoordinateParserTest.php | 8 ++---- .../unit/Parsers/DmsCoordinateParserTest.php | 4 +-- .../Parsers/FloatCoordinateParserTest.php | 8 ++---- 22 files changed, 70 insertions(+), 129 deletions(-) diff --git a/src/Formatters/GlobeCoordinateFormatter.php b/src/Formatters/GlobeCoordinateFormatter.php index 90461f7..18acb8d 100644 --- a/src/Formatters/GlobeCoordinateFormatter.php +++ b/src/Formatters/GlobeCoordinateFormatter.php @@ -26,10 +26,7 @@ */ class GlobeCoordinateFormatter implements ValueFormatter { - /** - * @var LatLongFormatter - */ - private $formatter; + private LatLongFormatter $formatter; public function __construct( ?FormatterOptions $options = null ) { $this->formatter = new LatLongFormatter( $options ); diff --git a/src/Formatters/LatLongFormatter.php b/src/Formatters/LatLongFormatter.php index 08f14b1..5800459 100644 --- a/src/Formatters/LatLongFormatter.php +++ b/src/Formatters/LatLongFormatter.php @@ -161,7 +161,7 @@ private function getPrecisionFromOptions(): float { * @since 0.5 * * @param LatLongValue $value - * @param float|int $precision The desired precision, given as fractional degrees. + * @param ?float $precision The desired precision, given as fractional degrees. * * @return string Plain text * @throws InvalidArgumentException @@ -171,15 +171,13 @@ public function formatLatLongValue( LatLongValue $value, ?float $precision ): st $precision = self::DEFAULT_PRECISION; } - $formatted = implode( + return implode( $this->options->getOption( self::OPT_SEPARATOR_SYMBOL ) . $this->getSpacing( self::OPT_SPACE_LATLONG ), [ $this->formatLatitude( $value->getLatitude(), $precision ), $this->formatLongitude( $value->getLongitude(), $precision ) ] ); - - return $formatted; } /** @@ -188,10 +186,7 @@ public function formatLatLongValue( LatLongValue $value, ?float $precision ): st * @return string */ private function getSpacing( string $spacingLevel ): string { - if ( in_array( $spacingLevel, $this->options->getOption( self::OPT_SPACING_LEVEL ) ) ) { - return ' '; - } - return ''; + return in_array( $spacingLevel, $this->options->getOption( self::OPT_SPACING_LEVEL ) ) ? ' ' : ''; } private function formatLatitude( float $latitude, float $precision ): string { @@ -347,9 +342,9 @@ private function getInDecimalMinuteFormat( float $floatDegrees, float $precision } /** - * @param float|int $unitsPerDegree The number of target units per degree + * @param float $unitsPerDegree The number of target units per degree * (60 for minutes, 3600 for seconds) - * @param float|int $degreePrecision + * @param float $degreePrecision * * @return int The number of digits to show after the decimal point * (resp. before, if the result is negative). @@ -366,7 +361,7 @@ private function getSignificantDigits( float $unitsPerDegree, float $degreePreci */ private function formatNumber( float $number, int $digits = 0 ): string { // TODO: use NumberLocalizer - return sprintf( '%.' . ( $digits > 0 ? $digits : 0 ) . 'F', $number ); + return sprintf( '%.' . ( max( $digits, 0 ) ) . 'F', $number ); } private function defaultOption( string $option, mixed $default ): void { diff --git a/src/GlobeMath.php b/src/GlobeMath.php index ed7f163..48bd25b 100644 --- a/src/GlobeMath.php +++ b/src/GlobeMath.php @@ -61,14 +61,10 @@ public function normalizeGlobeCoordinate( GlobeCoordinateValue $value ): GlobeCo * @return LatLongValue */ public function normalizeGlobeLatLong( LatLongValue $value, ?string $globe = null ): LatLongValue { - switch ( $this->normalizeGlobe( $globe ) ) { - case GlobeCoordinateValue::GLOBE_EARTH: - case self::GLOBE_MOON: - $minimumLongitude = -180; - break; - default: - $minimumLongitude = 0; - } + $minimumLongitude = match ( $this->normalizeGlobe( $globe ) ) { + GlobeCoordinateValue::GLOBE_EARTH, self::GLOBE_MOON => -180, + default => 0, + }; return $this->normalizeLatLong( $value, $minimumLongitude ); } diff --git a/src/PackagePrivate/LatLongPrecisionParser.php b/src/PackagePrivate/LatLongPrecisionParser.php index ff27df4..4b160e6 100644 --- a/src/PackagePrivate/LatLongPrecisionParser.php +++ b/src/PackagePrivate/LatLongPrecisionParser.php @@ -13,19 +13,16 @@ * @api */ class LatLongPrecisionParser { - - private ?ParserOptions $options; private ?array $parsers = null; - public function __construct( ?ParserOptions $options = null ) { - $this->options = $options; + public function __construct( private ?ParserOptions $options = null ) { } public function parse( string $coordinate ): PreciseLatLong { foreach ( $this->getParsers() as $parser ) { try { $latLongPrecision = $parser->parse( $coordinate ); - } catch ( ParseException $parseException ) { + } catch ( ParseException ) { continue; } diff --git a/src/PackagePrivate/PreciseLatLong.php b/src/PackagePrivate/PreciseLatLong.php index a8c01cc..1d16bd2 100644 --- a/src/PackagePrivate/PreciseLatLong.php +++ b/src/PackagePrivate/PreciseLatLong.php @@ -10,13 +10,7 @@ * @api */ class PreciseLatLong { - - private LatLongValue $latLong; - private Precision $precision; - - public function __construct( LatLongValue $latLong, Precision $precision ) { - $this->latLong = $latLong; - $this->precision = $precision; + public function __construct( private readonly LatLongValue $latLong, private readonly Precision $precision ) { } public function getLatLong(): LatLongValue { diff --git a/src/PackagePrivate/Precision.php b/src/PackagePrivate/Precision.php index ae9815f..2ef8ad7 100644 --- a/src/PackagePrivate/Precision.php +++ b/src/PackagePrivate/Precision.php @@ -4,6 +4,8 @@ namespace DataValues\Geo\PackagePrivate; +use InvalidArgumentException; + /** * @api */ @@ -13,7 +15,7 @@ class Precision { public function __construct( float $precisionInDegrees ) { if ( $precisionInDegrees < -360 || $precisionInDegrees > 360 ) { - throw new \InvalidArgumentException( '$precision needs to be between -360 and 360' ); + throw new InvalidArgumentException( '$precision needs to be between -360 and 360' ); } $this->precision = $precisionInDegrees; diff --git a/src/PackagePrivate/PrecisionParser.php b/src/PackagePrivate/PrecisionParser.php index b8dfcab..2bbca25 100644 --- a/src/PackagePrivate/PrecisionParser.php +++ b/src/PackagePrivate/PrecisionParser.php @@ -8,13 +8,7 @@ * @api */ class PrecisionParser { - - private ValueParser $latLongParser; - private PrecisionDetector $precisionDetector; - - public function __construct( ValueParser $latLongParser, PrecisionDetector $precisionDetector ) { - $this->latLongParser = $latLongParser; - $this->precisionDetector = $precisionDetector; + public function __construct( private readonly ValueParser $latLongParser, private readonly PrecisionDetector $precisionDetector ) { } public function parse( string $coordinate ): PreciseLatLong { diff --git a/src/Parsers/DdCoordinateParser.php b/src/Parsers/DdCoordinateParser.php index b255a6c..160da0c 100644 --- a/src/Parsers/DdCoordinateParser.php +++ b/src/Parsers/DdCoordinateParser.php @@ -45,10 +45,6 @@ public function __construct( ?ParserOptions $options = null ) { /** * @see LatLongParserBase::getParsedCoordinate - * - * @param string $coordinateSegment - * - * @return float */ protected function getParsedCoordinate( string $coordinateSegment ): float { $coordinateSegment = $this->resolveDirection( $coordinateSegment ); @@ -73,14 +69,14 @@ protected function areValidCoordinates( array $normalizedCoordinateSegments ): b $match = false; foreach ( $normalizedCoordinateSegments as $i => $segment ) { - $direction = '(' - . $this->getOption( self::OPT_NORTH_SYMBOL ) . '|' - . $this->getOption( self::OPT_SOUTH_SYMBOL ) . ')'; - if ( $i === 1 ) { $direction = '(' . $this->getOption( self::OPT_EAST_SYMBOL ) . '|' . $this->getOption( self::OPT_WEST_SYMBOL ) . ')'; + } else { + $direction = '(' + . $this->getOption( self::OPT_NORTH_SYMBOL ) . '|' + . $this->getOption( self::OPT_SOUTH_SYMBOL ) . ')'; } $match = preg_match( @@ -90,10 +86,12 @@ protected function areValidCoordinates( array $normalizedCoordinateSegments ): b if ( $directional ) { // Directionality is only set after parsing latitude: When the latitude is - // is directional, the longitude needs to be as well. Therefore we break here since + // directional, the longitude needs to be as well. Therefore, we break here since // checking for directionality is the only check needed for longitude. break; - } elseif ( $match ) { + } + + if ( $match ) { // Latitude is directional, no need to check for non-directionality. $directional = true; continue; @@ -139,9 +137,7 @@ protected function getNormalizedNotation( string $coordinates ): string { $this->getOption( self::OPT_DEGREE_SYMBOL ), $coordinates ); - $coordinates = $this->removeInvalidChars( $coordinates ); - - return $coordinates; + return $this->removeInvalidChars( $coordinates ); } /** @@ -160,10 +156,6 @@ protected function removeInvalidChars( string $string ): string { /** * Converts a coordinate segment to float representation. - * - * @param string $coordinateSegment - * - * @return float */ protected function parseCoordinate( string $coordinateSegment ): float { return (float)str_replace( @@ -186,7 +178,7 @@ protected function splitString( string $normalizedCoordinateString ): array { $normalizedCoordinateSegments = explode( $separator, $normalizedCoordinateString ); if ( count( $normalizedCoordinateSegments ) !== 2 ) { - // Separator not present within the string, trying to figure out the segments by + // Separator is not present within the string, trying to figure out the segments by // splitting after the first direction character or degree symbol: $delimiters = $this->defaultDelimiters; diff --git a/src/Parsers/DmCoordinateParser.php b/src/Parsers/DmCoordinateParser.php index bf21d0c..645395d 100644 --- a/src/Parsers/DmCoordinateParser.php +++ b/src/Parsers/DmCoordinateParser.php @@ -109,21 +109,13 @@ protected function areValidCoordinates( array $normalizedCoordinateSegments ): b /** * @see DdCoordinateParser::getNormalizedNotation - * - * @param string $coordinates - * - * @return string */ protected function getNormalizedNotation( string $coordinates ): string { - $minute = $this->getOption( self::OPT_MINUTE_SYMBOL ); - - $coordinates = str_replace( [ '′', '′', '´', '′' ], $minute, $coordinates ); + $coordinates = str_replace( [ '′', '′', '´', '′' ], $this->getOption( self::OPT_MINUTE_SYMBOL ), $coordinates ); - $coordinates = parent::getNormalizedNotation( $coordinates ); - - $coordinates = $this->removeInvalidChars( $coordinates ); - - return $coordinates; + return $this->removeInvalidChars( + parent::getNormalizedNotation( $coordinates ) + ); } /** diff --git a/src/Parsers/DmsCoordinateParser.php b/src/Parsers/DmsCoordinateParser.php index 421c5ec..6e4a193 100644 --- a/src/Parsers/DmsCoordinateParser.php +++ b/src/Parsers/DmsCoordinateParser.php @@ -68,14 +68,14 @@ protected function areValidCoordinates( array $normalizedCoordinateSegments ): b $directional = false; foreach ( $normalizedCoordinateSegments as $i => $segment ) { - $direction = '(' - . $this->getOption( self::OPT_NORTH_SYMBOL ) . '|' - . $this->getOption( self::OPT_SOUTH_SYMBOL ) . ')'; - if ( $i === 1 ) { $direction = '(' . $this->getOption( self::OPT_EAST_SYMBOL ) . '|' . $this->getOption( self::OPT_WEST_SYMBOL ) . ')'; + } else { + $direction = '(' + . $this->getOption( self::OPT_NORTH_SYMBOL ) . '|' + . $this->getOption( self::OPT_SOUTH_SYMBOL ) . ')'; } $match = preg_match( @@ -130,11 +130,7 @@ protected function getNormalizedNotation( string $coordinates ): string { ); $coordinates = str_replace( [ '´', '´' ], $second, $coordinates ); - $coordinates = parent::getNormalizedNotation( $coordinates ); - - $coordinates = $this->removeInvalidChars( $coordinates ); - - return $coordinates; + return $this->removeInvalidChars( parent::getNormalizedNotation( $coordinates ) ); } /** diff --git a/src/Parsers/FloatCoordinateParser.php b/src/Parsers/FloatCoordinateParser.php index 9637bc2..ac9ad58 100644 --- a/src/Parsers/FloatCoordinateParser.php +++ b/src/Parsers/FloatCoordinateParser.php @@ -45,14 +45,14 @@ protected function areValidCoordinates( array $normalizedCoordinateSegments ): b foreach ( $normalizedCoordinateSegments as $i => $segment ) { $segment = str_replace( ' ', '', $segment ); - $direction = '(' - . $this->getOption( self::OPT_NORTH_SYMBOL ) . '|' - . $this->getOption( self::OPT_SOUTH_SYMBOL ) . ')'; - if ( $i === 1 ) { $direction = '(' . $this->getOption( self::OPT_EAST_SYMBOL ) . '|' . $this->getOption( self::OPT_WEST_SYMBOL ) . ')'; + } else { + $direction = '(' + . $this->getOption( self::OPT_NORTH_SYMBOL ) . '|' + . $this->getOption( self::OPT_SOUTH_SYMBOL ) . ')'; } $match = preg_match( @@ -89,8 +89,8 @@ protected function splitString( string $normalizedCoordinateString ): array { $normalizedCoordinateSegments = explode( $separator, $normalizedCoordinateString ); if ( count( $normalizedCoordinateSegments ) !== 2 ) { - // Separator not present within the string, trying to figure out the segments by - // splitting at the the first SPACE after the first direction character or digit: + // Separator is not present within the string, trying to figure out the segments by + // splitting at the first SPACE after the first direction character or digit: $numberRegEx = '-?\d{1,3}(\.\d{1,20})?'; $ns = '(' diff --git a/src/Parsers/GlobeCoordinateParser.php b/src/Parsers/GlobeCoordinateParser.php index f3e8f2b..4a05ff6 100644 --- a/src/Parsers/GlobeCoordinateParser.php +++ b/src/Parsers/GlobeCoordinateParser.php @@ -7,6 +7,7 @@ use DataValues\Geo\PackagePrivate\LatLongPrecisionParser; use DataValues\Geo\PackagePrivate\Precision; use DataValues\Geo\Values\GlobeCoordinateValue; +use Exception; use ValueParsers\ParseException; use ValueParsers\ParserOptions; use ValueParsers\ValueParser; @@ -56,7 +57,7 @@ public function parse( $value ): GlobeCoordinateValue { try { $latLongPrecision = $parser->parse( $value ); - } catch ( \Exception $ex ) { + } catch ( Exception ) { throw new ParseException( 'The format of the coordinate could not be determined.', $value, diff --git a/src/Parsers/LatLongParser.php b/src/Parsers/LatLongParser.php index 3425ed5..6714a77 100644 --- a/src/Parsers/LatLongParser.php +++ b/src/Parsers/LatLongParser.php @@ -58,14 +58,11 @@ class LatLongParser implements ValueParser { public const OPT_SECOND_SYMBOL = 'second'; /** - * The symbol to use as separator between latitude and longitude. + * The symbol to use as a separator between latitude and longitude. */ public const OPT_SEPARATOR_SYMBOL = 'separator'; - /** - * @var ParserOptions - */ - private $options; + private ParserOptions $options; public function __construct( ?ParserOptions $options = null ) { $this->options = ( $options ?: new ParserOptions() )->withDefaultOption( ValueParser::OPT_LANG, 'en' ); @@ -83,7 +80,7 @@ public function parse( $value ): LatLongValue { foreach ( $this->getParsers() as $parser ) { try { return $parser->parse( $value ); - } catch ( ParseException $ex ) { + } catch ( ParseException ) { continue; } } diff --git a/src/Parsers/LatLongParserBase.php b/src/Parsers/LatLongParserBase.php index f8df6a0..156e7b6 100644 --- a/src/Parsers/LatLongParserBase.php +++ b/src/Parsers/LatLongParserBase.php @@ -29,7 +29,7 @@ abstract class LatLongParserBase implements ValueParser { public const OPT_WEST_SYMBOL = 'west'; /** - * The symbol to use as separator between latitude and longitude. + * The symbol to use as a separator between latitude and longitude. */ public const OPT_SEPARATOR_SYMBOL = 'separator'; @@ -57,10 +57,7 @@ private function defaultOption( string $option, mixed $default ): void { /** * Parses a single coordinate segment (either latitude or longitude) and returns it as a float. * - * @param string $coordinateSegment - * * @throws ParseException - * @return float */ abstract protected function getParsedCoordinate( string $coordinateSegment ): float; @@ -80,7 +77,6 @@ abstract protected function areValidCoordinates( array $normalizedCoordinateSegm * @param string $value * * @throws ParseException - * @return LatLongValue */ public function parse( $value ): LatLongValue { if ( !is_string( $value ) ) { @@ -140,7 +136,7 @@ protected function removeInvalidChars( string $string ): string { * * @param string $normalizedCoordinateString * - * @throws ParseException if unable to split input string into two segments + * @throws ParseException if unable to split the input string into two segments * @return string[] */ abstract protected function splitString( string $normalizedCoordinateString ): array; diff --git a/src/Values/GlobeCoordinateValue.php b/src/Values/GlobeCoordinateValue.php index c7e82c2..f52d19b 100644 --- a/src/Values/GlobeCoordinateValue.php +++ b/src/Values/GlobeCoordinateValue.php @@ -224,8 +224,8 @@ public static function newFromArray( $data ): self { (float)$data['latitude'], (float)$data['longitude'] ), - ( isset( $data['precision'] ) ) ? $data['precision'] : null, - ( isset( $data['globe'] ) ) ? $data['globe'] : null + $data['precision'] ?? null, + $data['globe'] ?? null ); } diff --git a/src/Values/LatLongValue.php b/src/Values/LatLongValue.php index d188217..bfe876b 100644 --- a/src/Values/LatLongValue.php +++ b/src/Values/LatLongValue.php @@ -26,8 +26,8 @@ class LatLongValue implements DataValue { private float $longitude; /** - * @param float|int $latitude Latitude in degrees within the range [-360, 360] - * @param float|int $longitude Longitude in degrees within the range [-360, 360] + * @param float $latitude Latitude in degrees within the range [-360, 360] + * @param float $longitude Longitude in degrees within the range [-360, 360] * * @throws InvalidArgumentException */ @@ -170,7 +170,7 @@ public static function newFromArray( $data ): self { public function toArray(): array { return [ 'value' => $this->getArrayValue(), - 'type' => $this->getType(), + 'type' => self::getType(), ]; } diff --git a/tests/unit/GlobeMathTest.php b/tests/unit/GlobeMathTest.php index 1f8d1cd..8ad54d1 100644 --- a/tests/unit/GlobeMathTest.php +++ b/tests/unit/GlobeMathTest.php @@ -22,10 +22,7 @@ class GlobeMathTest extends TestCase { private const EPSILON = 0.0000000000001; - /** - * @var GlobeMath - */ - private $math; + private GlobeMath $math; protected function setUp(): void { $this->math = new GlobeMath(); diff --git a/tests/unit/PackagePrivate/PrecisionTest.php b/tests/unit/PackagePrivate/PrecisionTest.php index 405edd9..e7b1360 100644 --- a/tests/unit/PackagePrivate/PrecisionTest.php +++ b/tests/unit/PackagePrivate/PrecisionTest.php @@ -5,6 +5,7 @@ namespace Tests\DataValues\Geo\PackagePrivate; use DataValues\Geo\PackagePrivate\Precision; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; /** @@ -16,12 +17,12 @@ class PrecisionTest extends TestCase { public function testConstructorThrowsExceptionForTooHighValues() { - $this->expectException( \InvalidArgumentException::class ); + $this->expectException( InvalidArgumentException::class ); new Precision( 360.1 ); } public function testConstructorThrowsExceptionForTooLowValues() { - $this->expectException( \InvalidArgumentException::class ); + $this->expectException( InvalidArgumentException::class ); new Precision( -360.1 ); } diff --git a/tests/unit/Parsers/DdCoordinateParserTest.php b/tests/unit/Parsers/DdCoordinateParserTest.php index 664a865..133c5c3 100644 --- a/tests/unit/Parsers/DdCoordinateParserTest.php +++ b/tests/unit/Parsers/DdCoordinateParserTest.php @@ -21,10 +21,8 @@ class DdCoordinateParserTest extends ParserTestBase { /** * @see ParserTestBase::getInstance - * - * @return DdCoordinateParser */ - protected function getInstance() { + protected function getInstance(): DdCoordinateParser { return new DdCoordinateParser(); } @@ -48,7 +46,7 @@ public function validInputProvider() { '5.5°S,37°W ' => [ -5.5, -37, 0.1 ], '-5.5°,-37° ' => [ -5.5, -37, 0.1 ], - // Coordinate strings without separator: + // Coordinate strings without a separator: '55.7557860° N 37.6176330° W' => [ 55.7557860, -37.6176330 ], '55.7557860° -37.6176330°' => [ 55.7557860, -37.6176330 ], '55° S 37.6176330 ° W' => [ -55, -37.6176330 ], @@ -56,7 +54,7 @@ public function validInputProvider() { '5.5°S 37°W ' => [ -5.5, -37 ], '-5.5° -37° ' => [ -5.5, -37 ], - // Coordinate string starting with direction character: + // Coordinate string starting with a direction character: 'N5.5° W37°' => [ 5.5, -37 ], 'S 5.5° E 37°' => [ -5.5, 37 ], ]; diff --git a/tests/unit/Parsers/DmCoordinateParserTest.php b/tests/unit/Parsers/DmCoordinateParserTest.php index eb32397..b6a5793 100644 --- a/tests/unit/Parsers/DmCoordinateParserTest.php +++ b/tests/unit/Parsers/DmCoordinateParserTest.php @@ -21,10 +21,8 @@ class DmCoordinateParserTest extends ParserTestBase { /** * @see ParserTestBase::getInstance - * - * @return DmCoordinateParser */ - protected function getInstance() { + protected function getInstance(): DmCoordinateParser { return new DmCoordinateParser(); } @@ -48,7 +46,7 @@ public function validInputProvider() { "0° 0.3' S, 0° 0.3' W" => [ -0.005, -0.005 ], "55° 30′, 37° 30′" => [ 55.5, 37.5 ], - // Coordinate strings without separator: + // Coordinate strings without a separator: "55° 0' 37° 0'" => [ 55, 37 ], "55 ° 30 ' 37 ° 30 '" => [ 55.5, 37.5 ], "0° 0' 0° 0'" => [ 0, 0 ], @@ -56,7 +54,7 @@ public function validInputProvider() { "0° 0.3' S 0° 0.3' W" => [ -0.005, -0.005 ], "55° 30′ 37° 30′" => [ 55.5, 37.5 ], - // Coordinate string starting with direction character: + // Coordinate string starting with a direction character: "S 0° 0.3', W 0° 0.3'" => [ -0.005, -0.005 ], "N 0° 0.3' E 0° 0.3'" => [ 0.005, 0.005 ], ]; diff --git a/tests/unit/Parsers/DmsCoordinateParserTest.php b/tests/unit/Parsers/DmsCoordinateParserTest.php index 9066fd3..531f60f 100644 --- a/tests/unit/Parsers/DmsCoordinateParserTest.php +++ b/tests/unit/Parsers/DmsCoordinateParserTest.php @@ -52,13 +52,13 @@ public function validInputProvider() { ' 0° 0\' 18" S , 0° 0\' 18" W ' => new LatLongValue( -0.005, -0.005 ), '55° 0′ 18″, 37° 0′ 18″' => new LatLongValue( 55.005, 37.005 ), - // Coordinate strings without separator: + // Coordinate strings without a separator: '55° 45\' 20.8296" 37° 37\' 3.4788"' => new LatLongValue( 55.755786, 37.617633 ), '55 ° 45 \' 20.8296 " -37 ° 37 \' 3.4788 "' => new LatLongValue( 55.755786, -37.617633 ), '-55 ° 45 \' 20.8296 " -37° 37\' 3.4788"' => new LatLongValue( -55.755786, -37.617633 ), '55° 0′ 18″ 37° 0′ 18″' => new LatLongValue( 55.005, 37.005 ), - // Coordinate string starting with direction character: + // Coordinate string starting with a direction character: 'N 0° 0\' 18", E 0° 0\' 18"' => new LatLongValue( 0.005, 0.005 ), 'S 0° 0\' 18" E 0° 0\' 18"' => new LatLongValue( -0.005, 0.005 ), ]; diff --git a/tests/unit/Parsers/FloatCoordinateParserTest.php b/tests/unit/Parsers/FloatCoordinateParserTest.php index efd814a..c43b29a 100644 --- a/tests/unit/Parsers/FloatCoordinateParserTest.php +++ b/tests/unit/Parsers/FloatCoordinateParserTest.php @@ -21,10 +21,8 @@ class FloatCoordinateParserTest extends ParserTestBase { /** * @see ParserTestBase::getInstance - * - * @return FloatCoordinateParser */ - protected function getInstance() { + protected function getInstance(): FloatCoordinateParser { return new FloatCoordinateParser(); } @@ -49,7 +47,7 @@ public function validInputProvider() { '-5.5,-37 ' => [ -5.5, -37 ], '4,2' => [ 4, 2 ], - // Coordinate strings without separator: + // Coordinate strings without a separator: '55.7557860 N 37.6176330 W' => [ 55.7557860, -37.6176330 ], '55.7557860 -37.6176330' => [ 55.7557860, -37.6176330 ], '55 S 37.6176330 W' => [ -55, -37.6176330 ], @@ -58,7 +56,7 @@ public function validInputProvider() { '-5.5 -37 ' => [ -5.5, -37 ], '4 2' => [ 4, 2 ], - // Coordinate string starting with direction character: + // Coordinate string starting with a direction character: 'S5.5 W37 ' => [ -5.5, -37 ], 'N 5.5 E 37 ' => [ 5.5, 37 ], ];