Repository navigation
Description
Summary
vendor/bin/phpstan analyse fails on a clean master (b713b22), so no pull request can get a green Tests run. The three lib/DateTime.php errors below appear at every supported phpVersion.
master currently shows green only because the Tests workflow last ran there on 24 October.
Reproducing
git checkout master # b713b22
composer install
vendor/bin/phpstan analyse
phpstan.neon sets no phpVersion, so PHPStan analyses as the running version and each matrix job (8.1 … 8.7) reports a slightly different set. Forcing it:
phpVersion |
errors |
|---|---|
| 8.1 | lib/DateTime.php 43, 55, 58, 75 + lib/DateTimeImmutable.php 99 (5) |
| 8.3 | lib/DateTime.php 43, 55, 58, 75 (4) |
| 8.6 | lib/DateTime.php 43, 58, 75 + lib/DateTimeImmutable.php 246 (4) |
Tested with PHPStan 2.3.4 on PHP 8.4.27.
The errors
Three are @var tags that contradict the native return type, and they fail at 8.1, 8.3 and 8.6 alike:
lib/DateTime.php:43—@var \DateInterval|falseoverparent::diff(), whose native return type isDateInterval.DateTime::diff()has not returnedfalsesince PHP 8.0, which is below this package's floor of^8.1, so the|falseand theif ($result === false)branch under it look unreachable on every supported version.lib/DateTime.php:58—@var DateTime|falseoverparent::modify(); native type isstatic(Safe\DateTime)|falseat 8.1 andDateTimeat 8.6.lib/DateTime.php:75—@var DateTime|falseoverparent::setDate(); native type isDateTime.
The other two are tentative return types, and they move with the version:
lib/DateTime.php:55—Safe\DateTime::modify()is not covariant with the tentativestatic(DateTime)|false. Reported at 8.1 and 8.3, not at 8.6.lib/DateTimeImmutable.php:99— the same forSafe\DateTimeImmutable::modify(). Reported at 8.1 only, and Fix PHP 8.6 deprecations from DateTimeImmutable tentative return types #767 removes it.
Why I have not sent a patch
The @var tags cannot simply lose their |false: whether these methods can return false depends on the version, and phpstan.neon enables bleedingEdge, whose output asks that the cause be fixed rather than suppressed with @phpstan-ignore or a baseline. Dropping the === false branches removes an exception path on any version that can still return false, so the right shape depends on how far back you intend Safe\DateTime to keep throwing DatetimeException. Happy to send a patch once you say which way you would like it.
Note on runtime
These are static-analysis findings. Loading Safe\DateTime emits no deprecations on 8.2, 8.3 or 8.6. Safe\DateTimeImmutable emits 18 on 8.6.0-dev, which is what #767 addresses.
Activity