Skip to content

Commit 5f2aee7

Browse files
committed
upgrade vimeo/psalm (4.30.0 = => 6.15.1)
Root cause: Psalm's strict binary operands mode (psalm.dev/058) forbids mixing int and float in arithmetic without explicit casts. Changes made: 1. degToSex / degToSec — Changed return type from float|int to float, added $angle = (float) $angle; at the top, and replaced all int literals in arithmetic with float literals (60 → 60.0, 100 → 100.0, etc.) and added (float) casts on $deg and $min before arithmetic. 2. fromMN95ToWGSLatitude / fromMN95ToWGSLongitude — Cast float|int params with (float) $east / (float) $north, and changed integer constants to float literals (2600000 → 2600000.0, 1000000 → 1000000.0, 100 / 36 → 100.0 / 36.0). 3. fromMN03ToWGSLatitude / fromMN03ToWGSLongitude — Changed integer constants to float literals (600000 → 600000.0, 200000 → 200000.0, 1000000 → 1000000.0, 100 / 36 → 100.0 / 36.0). 4. All four WGSToMN* methods — Changed / 10000 → / 10000.0 in the auxiliary value calculations (the subtraction operands were already float literals, so once degToSec returns float, those lines are clean).
1 parent c4045ab commit 5f2aee7

File tree

7 files changed

+68
-53
lines changed

7 files changed

+68
-53
lines changed

.github/workflows/styles.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Setup PHP
1313
uses: shivammathur/setup-php@v2
1414
with:
15-
php-version: '8.3'
15+
php-version: '8.5'
1616
extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv
1717
tools: php-cs-fixer, cs2pr
1818
- uses: actions/checkout@v2
@@ -26,7 +26,7 @@ jobs:
2626
- name: Setup PHP
2727
uses: shivammathur/setup-php@v2
2828
with:
29-
php-version: '8.3'
29+
php-version: '8.5'
3030
extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv
3131
- uses: actions/checkout@v2
3232
- run: composer install --prefer-dist
@@ -39,7 +39,7 @@ jobs:
3939
- name: Setup PHP
4040
uses: shivammathur/setup-php@v2
4141
with:
42-
php-version: '8.3'
42+
php-version: '8.5'
4343
extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv
4444
- uses: actions/checkout@v2
4545
- run: composer install --prefer-dist
@@ -52,7 +52,7 @@ jobs:
5252
- name: Setup PHP
5353
uses: shivammathur/setup-php@v2
5454
with:
55-
php-version: '8.3'
55+
php-version: '8.5'
5656
extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv
5757
tools: phpstan, cs2pr
5858
- uses: actions/checkout@v2
@@ -66,7 +66,7 @@ jobs:
6666
- name: Setup PHP
6767
uses: shivammathur/setup-php@v2
6868
with:
69-
php-version: '8.3'
69+
php-version: '8.5'
7070
extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv
7171
- uses: actions/checkout@v2
7272
- run: composer install --prefer-dist

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
13+
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
1414
steps:
1515
- name: Setup PHP
1616
uses: shivammathur/setup-php@v2

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- add tests coverage for PHP 8.5
10+
- upgrade vimeo/psalm (4.30.0 = => 6.15.1)
811

912
## [1.0.2] - 2025-06-03
1013
### Added

CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ Pull requests for bugs are more than welcome - please explain the bug you're try
1313

1414
## Developing
1515

16+
## 🧪 Running tests
17+
18+
Run the test suite without code coverage (no Xdebug required):
19+
20+
```bash
21+
./vendor/bin/phpunit --no-coverage
22+
```
23+
24+
Run the test suite with code coverage (requires [Xdebug](https://xdebug.org/) or [PCOV](https://github.com/krakjoe/pcov)):
25+
26+
```bash
27+
XDEBUG_MODE=coverage ./vendor/bin/phpunit
28+
```
29+
30+
> **Note:** Running `./vendor/bin/phpunit` without `--no-coverage` and without a coverage driver will fail with _"No code coverage driver available"_. Use `--no-coverage` for day-to-day local development.
31+
1632
## 🚔 Check Symfony 4 coding standards & best practices
1733

1834
You need to run composer before using [FriendsOfPHP/PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"sebastian/phpcpd": "^6.0",
1414
"php-coveralls/php-coveralls": "^2.1",
1515
"php-mock/php-mock-phpunit": "^2.4",
16-
"vimeo/psalm": "^4.29",
16+
"vimeo/psalm": "^6.0",
1717
"phpstan/phpstan-deprecation-rules": "^0.12.2"
1818
},
1919
"autoload": {

psalm.xml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
<?xml version="1.0"?>
22
<psalm
33
errorLevel="1"
4-
autoloader="vendor/autoload.php"
5-
requireVoidReturnType="false"
4+
resolveFromConfigFile="true"
5+
findUnusedBaselineEntry="true"
6+
findUnusedCode="true"
67
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
78
xmlns="https://getpsalm.org/schema/config"
8-
xsi:schemaLocation="https://getpsalm.org/schema/config file:///app/vendor/vimeo/psalm/config.xsd">
9-
9+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
10+
>
1011
<projectFiles>
1112
<directory name="src" />
12-
1313
<ignoreFiles>
1414
<directory name="vendor" />
15+
<directory name="bin" />
1516
</ignoreFiles>
1617
</projectFiles>
17-
18-
<fileExtensions>
19-
<extension name="php" />
20-
<extension name="inc" />
21-
</fileExtensions>
22-
23-
<issueHandlers>
24-
<!-- Suppress some errors -->
25-
<!-- @see https://github.com/vimeo/psalm/blob/master/docs/dealing_with_code_issues.md -->
26-
</issueHandlers>
27-
2818
</psalm>

src/SwisstopoConverter.php

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
/**
66
* Convert GPS (WGS84) to Swiss (LV03 or LV95) coordinates - and vice versa.
7+
*
8+
* @psalm-api
79
*/
810
class SwisstopoConverter
911
{
@@ -105,8 +107,8 @@ private static function fromWGSToMN03y(float $lat, float $long): float
105107
$long = self::degToSec($long);
106108

107109
// Auxiliary values (% Bern).
108-
$lat_aux = ($lat - 169028.66) / 10000;
109-
$long_aux = ($long - 26782.5) / 10000;
110+
$lat_aux = ($lat - 169028.66) / 10000.0;
111+
$long_aux = ($long - 26782.5) / 10000.0;
110112

111113
// Process Swiss (MN03) Y calculation.
112114
return 600072.37
@@ -138,8 +140,8 @@ private static function fromWGSToMN03x(float $lat, float $long): float
138140
$long = self::degToSec($long);
139141

140142
// Auxiliary values (% Bern).
141-
$lat_aux = ($lat - 169028.66) / 10000;
142-
$long_aux = ($long - 26782.5) / 10000;
143+
$lat_aux = ($lat - 169028.66) / 10000.0;
144+
$long_aux = ($long - 26782.5) / 10000.0;
143145

144146
// Process Swiss (MN03) X calculation.
145147
return 200147.07
@@ -173,8 +175,8 @@ private static function fromWGSToMN95North(float $lat, float $long): float
173175

174176
// Calculate the auxiliary values (differences of latitude and longitude
175177
// relative to Bern in the unit[10000"]).
176-
$phi_aux = ($phi - 169028.66) / 10000;
177-
$lambda_aux = ($lambda - 26782.5) / 10000;
178+
$phi_aux = ($phi - 169028.66) / 10000.0;
179+
$lambda_aux = ($lambda - 26782.5) / 10000.0;
178180

179181
// Process Swiss (MN95) North calculation.
180182
return 1200147.07
@@ -208,8 +210,8 @@ private static function fromWGSToMN95East(float $lat, float $long): float
208210

209211
// Calculate the auxiliary values (differences of latitude and longitude
210212
// relative to Bern in the unit[10000"]).
211-
$phi_aux = ($phi - 169028.66) / 10000;
212-
$lambda_aux = ($lambda - 26782.5) / 10000;
213+
$phi_aux = ($phi - 169028.66) / 10000.0;
214+
$lambda_aux = ($lambda - 26782.5) / 10000.0;
213215

214216
// Process Swiss (MN95) East calculation.
215217
return 2600072.37
@@ -234,8 +236,8 @@ public static function fromMN95ToWGSLatitude(float|int $east, float|int $north):
234236
{
235237
// Convert the projection coordinates E (easting) and N (northing) in MN95
236238
// into the civilian system (Bern = 0 / 0) and express in the unit 1000 km.
237-
$y_aux = ($east - 2600000) / 1000000;
238-
$x_aux = ($north - 1200000) / 1000000;
239+
$y_aux = ((float) $east - 2600000.0) / 1000000.0;
240+
$x_aux = ((float) $north - 1200000.0) / 1000000.0;
239241

240242
// Process latitude calculation.
241243
$lat = 16.9023892
@@ -246,7 +248,7 @@ public static function fromMN95ToWGSLatitude(float|int $east, float|int $north):
246248
- 0.0140 * pow($x_aux, 3);
247249

248250
// Unit 10000" to 1" and converts seconds to degrees notation.
249-
$lat = $lat * 100 / 36;
251+
$lat = $lat * 100.0 / 36.0;
250252

251253
return $lat;
252254
}
@@ -266,8 +268,8 @@ private static function fromMN95ToWGSLongitude(float|int $east, float|int $north
266268
{
267269
// Convert the projection coordinates E (easting) and N (northing) in MN95
268270
// into the civilian system (Bern = 0 / 0) and express in the unit 1000 km.
269-
$y_aux = ($east - 2600000) / 1000000;
270-
$x_aux = ($north - 1200000) / 1000000;
271+
$y_aux = ((float) $east - 2600000.0) / 1000000.0;
272+
$x_aux = ((float) $north - 1200000.0) / 1000000.0;
271273

272274
// Process longitude calculation.
273275
$long = 2.6779094
@@ -277,7 +279,7 @@ private static function fromMN95ToWGSLongitude(float|int $east, float|int $north
277279
- 0.0436 * pow($y_aux, 3);
278280

279281
// Unit 10000" to 1" and converts seconds to degrees notation.
280-
$long = $long * 100 / 36;
282+
$long = $long * 100.0 / 36.0;
281283

282284
return $long;
283285
}
@@ -297,8 +299,8 @@ public static function fromMN03ToWGSLatitude(float $y, float $x): float
297299
{
298300
// Convert the projection coordinates y and x in MN03 into the civilian
299301
// system (Bern = 0 / 0) and express in the unit [1000 km].
300-
$y_aux = ($y - 600000) / 1000000;
301-
$x_aux = ($x - 200000) / 1000000;
302+
$y_aux = ($y - 600000.0) / 1000000.0;
303+
$x_aux = ($x - 200000.0) / 1000000.0;
302304

303305
// Process latitude calculation.
304306
$lat = 16.9023892
@@ -309,7 +311,7 @@ public static function fromMN03ToWGSLatitude(float $y, float $x): float
309311
- 0.0140 * pow($x_aux, 3);
310312

311313
// Unit 10000" to 1" and converts seconds to degrees notation.
312-
$lat = $lat * 100 / 36;
314+
$lat = $lat * 100.0 / 36.0;
313315

314316
return $lat;
315317
}
@@ -329,8 +331,8 @@ private static function fromMN03ToWGSLongitude(float $y, float $x): float
329331
{
330332
// Convert the projection coordinates y and x in MN03 into the civilian
331333
// system (Bern = 0 / 0) and express in the unit [1000 km].
332-
$y_aux = ($y - 600000) / 1000000;
333-
$x_aux = ($x - 200000) / 1000000;
334+
$y_aux = ($y - 600000.0) / 1000000.0;
335+
$x_aux = ($x - 200000.0) / 1000000.0;
334336

335337
// Process longitude calculation.
336338
$long = 2.6779094
@@ -340,7 +342,7 @@ private static function fromMN03ToWGSLongitude(float $y, float $x): float
340342
- 0.0436 * pow($y_aux, 3);
341343

342344
// Unit 10000" to 1" and converts seconds to degrees notation.
343-
$long = $long * 100 / 36;
345+
$long = $long * 100.0 / 36.0;
344346

345347
return $long;
346348
}
@@ -351,18 +353,20 @@ private static function fromMN03ToWGSLongitude(float $y, float $x): float
351353
* @param float|int $angle
352354
* The Decimal Degrees notation of angle to convert in Sexagesimal notation
353355
*
354-
* @return float|int
356+
* @return float
355357
* The converted Decimal Degrees to Sexagesimal Degrees
356358
*/
357-
private static function degToSex(float|int $angle): float|int
359+
private static function degToSex(float|int $angle): float
358360
{
361+
$angle = (float) $angle;
362+
359363
// Extract D°M'S".
360364
$deg = (int) $angle;
361-
$min = (int) (($angle - $deg) * 60);
362-
$sec = ((($angle - $deg) * 60) - $min) * 60;
365+
$min = (int) (($angle - (float) $deg) * 60.0);
366+
$sec = ((($angle - (float) $deg) * 60.0) - (float) $min) * 60.0;
363367

364368
// Result in degrees sec (dd.mmss)
365-
return $deg + $min / 100 + $sec / 10000;
369+
return (float) $deg + (float) $min / 100.0 + $sec / 10000.0;
366370
}
367371

368372
/**
@@ -371,17 +375,19 @@ private static function degToSex(float|int $angle): float|int
371375
* @param float|int $angle
372376
* The Decimal Degrees notation of angle to convert in Seconds of Arc
373377
*
374-
* @return float|int
378+
* @return float
375379
* The converted Decimal Degrees to Seconds of Arc
376380
*/
377-
private static function degToSec(float|int $angle): float|int
381+
private static function degToSec(float|int $angle): float
378382
{
383+
$angle = (float) $angle;
384+
379385
// Extract D°M'S".
380386
$deg = (int) $angle;
381-
$min = (int) (($angle - $deg) * 100);
382-
$sec = ((($angle - $deg) * 100) - $min) * 100;
387+
$min = (int) (($angle - (float) $deg) * 100.0);
388+
$sec = ((($angle - (float) $deg) * 100.0) - (float) $min) * 100.0;
383389

384390
// Result in degrees sec (dd.mmss).
385-
return $sec + $min * 60 + $deg * 3600;
391+
return $sec + (float) $min * 60.0 + (float) $deg * 3600.0;
386392
}
387393
}

0 commit comments

Comments
 (0)