Skip to content

PHPStan fails on a clean master, so no PR can get a green Tests run #768

Open

Description

@dhrupo

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|false over parent::diff(), whose native return type is DateInterval. DateTime::diff() has not returned false since PHP 8.0, which is below this package's floor of ^8.1, so the |false and the if ($result === false) branch under it look unreachable on every supported version.
  • lib/DateTime.php:58 — @var DateTime|false over parent::modify(); native type is static(Safe\DateTime)|false at 8.1 and DateTime at 8.6.
  • lib/DateTime.php:75 — @var DateTime|false over parent::setDate(); native type is DateTime.

The other two are tentative return types, and they move with the version:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions