diff --git a/.gitignore b/.gitignore index 3fb1f97..af1e553 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ composer.lock # PHPCS cache files .php_cs.cache .phpcs-cache +.php-cs-fixer.cache diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 60% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 8dd29b8..81ff38b 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -1,16 +1,15 @@ exclude('vendor') ->exclude('.sonarlint') - ->in(__DIR__) -; + ->in(__DIR__); -return PhpCsFixer\Config::create() - ->setRules([ +$config = new \PhpCsFixer\Config(); + +return $config->setRules([ '@Symfony' => true, 'array_syntax' => ['syntax' => 'short'], 'phpdoc_align' => ['align' => 'vertical', 'tags' => ['type', 'var']], ]) - ->setFinder($finder) -; + ->setFinder($finder); diff --git a/CHANGELOG.md b/CHANGELOG.md index 7023c44..a947fd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- fixed deprecations for development +- fixed deprecations for PHP 8.1 + ### Changed - update changelog following 'keep a changelog' format - run code-styles Github Actions on PHP 8.1 diff --git a/LICENSE b/LICENSE index 354343d..c81dca7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Antistatique +Copyright (c) 2020–2022 Antistatique Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 5ddaefe..70b6ca9 100644 --- a/composer.json +++ b/composer.json @@ -3,18 +3,18 @@ "description": "Convert GPS (WGS84) to Swiss (LV03 and LV95) coordinates (and vice versa)", "license": "MIT", "require": { - "php": ">=7.4" + "php": ">=8.0" }, "require-dev": { "phpunit/phpunit": "^9.0.0", "phpunit/php-code-coverage": "^9.2.0", - "friendsofphp/php-cs-fixer": "^2.16", + "friendsofphp/php-cs-fixer": "^3.0", "phpmd/phpmd": "^2.8", "sebastian/phpcpd": "^6.0", "sensiolabs/security-checker": "^5.0", "php-coveralls/php-coveralls": "^2.1", "php-mock/php-mock-phpunit": "^2.4", - "vimeo/psalm": "^3.11", + "vimeo/psalm": "^4.29", "phpstan/phpstan-deprecation-rules": "^0.12.2" }, "autoload": { diff --git a/phpunit.xml b/phpunit.xml index d4c28c4..42e3057 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,27 +1,23 @@ - + + + + src + + + + + + ./tests/ - - - - - - - src - - + - - + + diff --git a/psalm.xml b/psalm.xml index 550821b..d1c0af3 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,7 +1,7 @@ self::fromMN95ToWGSLatitude($east, $north), - 'long' => self::fromMN95ToWGSLongitude($east, $north), - ]; + 'lat' => self::fromMN95ToWGSLatitude($east, $north), + 'long' => self::fromMN95ToWGSLongitude($east, $north), + ]; } /** @@ -40,9 +40,9 @@ public static function fromMN95ToWGS(int $east, int $north): array public static function fromWGSToMN95(float $lat, float $long): array { return [ - 'east' => self::fromWGSToMN95East($lat, $long), - 'north' => self::fromWGSToMN95North($lat, $long), - ]; + 'east' => self::fromWGSToMN95East($lat, $long), + 'north' => self::fromWGSToMN95North($lat, $long), + ]; } /** @@ -59,9 +59,9 @@ public static function fromWGSToMN95(float $lat, float $long): array public static function fromMN03ToWGS(int $y, int $x): array { return [ - 'lat' => self::fromMN03ToWGSLatitude($y, $x), - 'long' => self::fromMN03ToWGSLongitude($y, $x), - ]; + 'lat' => self::fromMN03ToWGSLatitude($y, $x), + 'long' => self::fromMN03ToWGSLongitude($y, $x), + ]; } /** @@ -78,9 +78,9 @@ public static function fromMN03ToWGS(int $y, int $x): array public static function fromWGSToMN03(float $lat, float $long): array { return [ - 'x' => self::fromWGSToMN03x($lat, $long), - 'y' => self::fromWGSToMN03y($lat, $long), - ]; + 'x' => self::fromWGSToMN03x($lat, $long), + 'y' => self::fromWGSToMN03y($lat, $long), + ]; } /** @@ -110,10 +110,10 @@ private static function fromWGSToMN03y(float $lat, float $long): float // Process Swiss (MN03) Y calculation. return 600072.37 - + 211455.93 * $long_aux - - 10938.51 * $long_aux * $lat_aux - - 0.36 * $long_aux * pow($lat_aux, 2) - - 44.54 * pow($long_aux, 3); + + 211455.93 * $long_aux + - 10938.51 * $long_aux * $lat_aux + - 0.36 * $long_aux * pow($lat_aux, 2) + - 44.54 * pow($long_aux, 3); } /** @@ -143,11 +143,11 @@ private static function fromWGSToMN03x(float $lat, float $long): float // Process Swiss (MN03) X calculation. return 200147.07 - + 308807.95 * $lat_aux - + 3745.25 * pow($long_aux, 2) - + 76.63 * pow($lat_aux, 2) - - 194.56 * pow($long_aux, 2) * $lat_aux - + 119.79 * pow($lat_aux, 3); + + 308807.95 * $lat_aux + + 3745.25 * pow($long_aux, 2) + + 76.63 * pow($lat_aux, 2) + - 194.56 * pow($long_aux, 2) * $lat_aux + + 119.79 * pow($lat_aux, 3); } /** @@ -178,11 +178,11 @@ private static function fromWGSToMN95North(float $lat, float $long): float // Process Swiss (MN95) North calculation. return 1200147.07 - + 308807.95 * $phi_aux - + 3745.25 * pow($lambda_aux, 2) - + 76.63 * pow($phi_aux, 2) - - 194.56 * pow($lambda_aux, 2) * $phi_aux - + 119.79 * pow($phi_aux, 3); + + 308807.95 * $phi_aux + + 3745.25 * pow($lambda_aux, 2) + + 76.63 * pow($phi_aux, 2) + - 194.56 * pow($lambda_aux, 2) * $phi_aux + + 119.79 * pow($phi_aux, 3); } /** @@ -213,24 +213,24 @@ private static function fromWGSToMN95East(float $lat, float $long): float // Process Swiss (MN95) East calculation. return 2600072.37 - + 211455.93 * $lambda_aux - - 10938.51 * $lambda_aux * $phi_aux - - 0.36 * $lambda_aux * pow($phi_aux, 2) - - 44.54 * pow($lambda_aux, 3); + + 211455.93 * $lambda_aux + - 10938.51 * $lambda_aux * $phi_aux + - 0.36 * $lambda_aux * pow($phi_aux, 2) + - 44.54 * pow($lambda_aux, 3); } /** * Convert Swiss (MN95) coordinates East & North to WGS latitude value. * - * @param int $east + * @param float|int $east * The East Swiss (MN95) coordinate point - * @param int $north + * @param float|int $north * The North Swiss (MN95) coordinate point * * @return float * The converted Swiss (MN95) coordinates to WGS latitude */ - public static function fromMN95ToWGSLatitude(int $east, int $north): float + public static function fromMN95ToWGSLatitude(float|int $east, float|int $north): float { // Convert the projection coordinates E (easting) and N (northing) in MN95 // into the civilian system (Bern = 0 / 0) and express in the unit 1000 km. @@ -239,11 +239,11 @@ public static function fromMN95ToWGSLatitude(int $east, int $north): float // Process latitude calculation. $lat = 16.9023892 - + 3.238272 * $x_aux - - 0.270978 * pow($y_aux, 2) - - 0.002528 * pow($x_aux, 2) - - 0.0447 * pow($y_aux, 2) * $x_aux - - 0.0140 * pow($x_aux, 3); + + 3.238272 * $x_aux + - 0.270978 * pow($y_aux, 2) + - 0.002528 * pow($x_aux, 2) + - 0.0447 * pow($y_aux, 2) * $x_aux + - 0.0140 * pow($x_aux, 3); // Unit 10000" to 1" and converts seconds to degrees notation. $lat = $lat * 100 / 36; @@ -254,15 +254,15 @@ public static function fromMN95ToWGSLatitude(int $east, int $north): float /** * Convert Swiss (MN95) coordinates East & North to WGS longitude value. * - * @param int $east + * @param float|int $east * The East Swiss (MN95) coordinate point - * @param int $north + * @param float|int $north * The North Swiss (MN95) coordinate point * * @return float * The converted Swiss (MN95) coordinates to WGS longitude */ - private static function fromMN95ToWGSLongitude(int $east, int $north): float + private static function fromMN95ToWGSLongitude(float|int $east, float|int $north): float { // Convert the projection coordinates E (easting) and N (northing) in MN95 // into the civilian system (Bern = 0 / 0) and express in the unit 1000 km. @@ -271,10 +271,10 @@ private static function fromMN95ToWGSLongitude(int $east, int $north): float // Process longitude calculation. $long = 2.6779094 - + 4.728982 * $y_aux - + 0.791484 * $y_aux * $x_aux - + 0.1306 * $y_aux * pow($x_aux, 2) - - 0.0436 * pow($y_aux, 3); + + 4.728982 * $y_aux + + 0.791484 * $y_aux * $x_aux + + 0.1306 * $y_aux * pow($x_aux, 2) + - 0.0436 * pow($y_aux, 3); // Unit 10000" to 1" and converts seconds to degrees notation. $long = $long * 100 / 36; @@ -285,15 +285,15 @@ private static function fromMN95ToWGSLongitude(int $east, int $north): float /** * Convert Swiss (MN03) coordinates y & x to WGS latitude value. * - * @param int $y + * @param float $y * The Y Swiss (MN03) coordinate point - * @param int $x + * @param float $x * The X Swiss (MN03) coordinate point * * @return float * The converted Swiss (MN03) coordinates to WGS latitude */ - public static function fromMN03ToWGSLatitude(int $y, int $x): float + public static function fromMN03ToWGSLatitude(float $y, float $x): float { // Convert the projection coordinates y and x in MN03 into the civilian // system (Bern = 0 / 0) and express in the unit [1000 km]. @@ -302,11 +302,11 @@ public static function fromMN03ToWGSLatitude(int $y, int $x): float // Process latitude calculation. $lat = 16.9023892 - + 3.238272 * $x_aux - - 0.270978 * pow($y_aux, 2) - - 0.002528 * pow($x_aux, 2) - - 0.0447 * pow($y_aux, 2) * $x_aux - - 0.0140 * pow($x_aux, 3); + + 3.238272 * $x_aux + - 0.270978 * pow($y_aux, 2) + - 0.002528 * pow($x_aux, 2) + - 0.0447 * pow($y_aux, 2) * $x_aux + - 0.0140 * pow($x_aux, 3); // Unit 10000" to 1" and converts seconds to degrees notation. $lat = $lat * 100 / 36; @@ -317,15 +317,15 @@ public static function fromMN03ToWGSLatitude(int $y, int $x): float /** * Convert Swiss (MN03) coordinates y & x to WGS longitude value. * - * @param int $y + * @param float $y * The Y Swiss (MN03) coordinate point - * @param int $x + * @param float $x * The X Swiss (MN03) coordinate point * * @return float * The converted Swiss (MN03) coordinates to WGS longitude */ - private static function fromMN03ToWGSLongitude(int $y, int $x): float + private static function fromMN03ToWGSLongitude(float $y, float $x): float { // Convert the projection coordinates y and x in MN03 into the civilian // system (Bern = 0 / 0) and express in the unit [1000 km]. @@ -334,10 +334,10 @@ private static function fromMN03ToWGSLongitude(int $y, int $x): float // Process longitude calculation. $long = 2.6779094 - + 4.728982 * $y_aux - + 0.791484 * $y_aux * $x_aux - + 0.1306 * $y_aux * pow($x_aux, 2) - - 0.0436 * pow($y_aux, 3); + + 4.728982 * $y_aux + + 0.791484 * $y_aux * $x_aux + + 0.1306 * $y_aux * pow($x_aux, 2) + - 0.0436 * pow($y_aux, 3); // Unit 10000" to 1" and converts seconds to degrees notation. $long = $long * 100 / 36; @@ -354,7 +354,7 @@ private static function fromMN03ToWGSLongitude(int $y, int $x): float * @return float|int * The converted Decimal Degrees to Sexagesimal Degrees */ - private static function degToSex($angle) + private static function degToSex(float|int $angle): float|int { // Extract D°M'S". $deg = (int) $angle; @@ -374,7 +374,7 @@ private static function degToSex($angle) * @return float|int * The converted Decimal Degrees to Seconds of Arc */ - private static function degToSec($angle) + private static function degToSec(float|int $angle): float|int { // Extract D°M'S". $deg = (int) $angle; diff --git a/tests/SwisstopoConverterTests.php b/tests/SwisstopoConverterTests.php index acd667c..72ea296 100644 --- a/tests/SwisstopoConverterTests.php +++ b/tests/SwisstopoConverterTests.php @@ -36,8 +36,8 @@ public function testDegToSex($degrees, $expected): void public function decimalDegreesToSexagesimalProvider() { return [ - [12.76389, 12.4550004], - ]; + [12.76389, 12.4550004], + ]; } /** @@ -63,11 +63,11 @@ public function testDegToSec($degrees, $expected): void public function decimalDegreesToSecondsOfArcProvider() { return [ - [1, 3600], - [1.24, 5040], - [360, 1.296e+6], - [-12, -43200], - ['1.24', 5040], - ]; + [1, 3600], + [1.24, 5040], + [360, 1.296e+6], + [-12, -43200], + ['1.24', 5040], + ]; } } diff --git a/tests/SwisstopoConverterWGSToMN03Tests.php b/tests/SwisstopoConverterWGSToMN03Tests.php index 5a52a17..94ffc26 100644 --- a/tests/SwisstopoConverterWGSToMN03Tests.php +++ b/tests/SwisstopoConverterWGSToMN03Tests.php @@ -32,9 +32,9 @@ public function testFromWGSToMN03(): void $swiss_converter = new SwisstopoConverter(); $coordinates = $swiss_converter->fromWGSToMN03(46.462057617639, 6.8486736590762); $this->assertSame([ - 'x' => 145807.4339423232, - 'y' => 554679.5530031546, - ], $coordinates); + 'x' => 145807.4339423232, + 'y' => 554679.5530031546, + ], $coordinates); } /** diff --git a/tests/SwisstopoConverterWGSToMN95Tests.php b/tests/SwisstopoConverterWGSToMN95Tests.php index 264568a..d24bb17 100644 --- a/tests/SwisstopoConverterWGSToMN95Tests.php +++ b/tests/SwisstopoConverterWGSToMN95Tests.php @@ -32,9 +32,9 @@ public function testFromWGSToMN95(): void $swiss_converter = new SwisstopoConverter(); $coordinates = $swiss_converter->fromWGSToMN95(46.46312579498212, 6.8534397262208095); $this->assertSame([ - 'east' => 2555046.5560538797, - 'north' => 1145923.4267763223, - ], $coordinates); + 'east' => 2555046.5560538797, + 'north' => 1145923.4267763223, + ], $coordinates); } /**