Repository navigation
Conversation
Immutable classes and enums are tagged @phpstan-all-methods-pure, with @phpstan-impure on the methods that read the clock (now(), isFuture(), isPast()), consume a DateTimeParseResult (from()) or return a generator (getIterator()). The mutable classes (the clocks, Stopwatch, DefaultClock, DateTimeParseResult, PatternParserBuilder) tag each method. This lets PHPStan report a discarded result, such as `$date->plusDays(1);` on its own line, in the library and in its users' code. PHPStan is upgraded to 2.3.4, as earlier versions ignore @phpstan-all-methods-pure on a method without a doc comment. It now analyses for the PHP versions the library supports, where DateInterval::createFromDateString() can still return false. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y1vvcUHV6d9eTuxE4GW5MX
This was referenced Nov 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every method of the library now tells PHPStan whether it is pure, so that PHPStan can catch a discarded result, in the library and in its users' code:
Change
@phpstan-all-methods-pure, with@phpstan-impureonly on the methods that:now(),isFuture(),isPast();DateTimeParseResult:from(), asgetField()shifts the values off the result;getIterator()on the ranges.Stopwatch,DefaultClock,DateTimeParseResultandPatternParserBuilder.Clock::getTime()is impure, whileFixedClock::getTime()is pure.Field\*::check()validators are@phpstan-pure. PHPStan accepts that on a void method that declares@throws.Some methods are pure as far as their callers can tell, though PHPStan cannot see it. The errors that shows are ignored in
phpstan.neon, each with the reason:staticvariable memoizing a constant (Duration::zero(),IsoParsers::localDate()…);parse()handingfrom()the result it has just created;TimeZoneOffset::getId()caching the ID it computes;IsoParsersandPatternParser::parse()mutating a builder or result they created on the spot (the latter, andZonedDateTime::toNativeDateTime(), as inline ignores);preg_match(),assert(),DateTime*,DateInterval,DatePeriod;check()validators, which PHPStan counts as impure because they return void, although it accepts them as pure.Tooling
@phpstan-all-methods-purewas ignored for callers of a method without a doc comment of its own, so$instant->getNano()still looked possibly impure.phpVersionrange) instead of the PHP running it. Otherwise 2.3.4 reports theassert()inPeriod::toNativeDateInterval()as always true, sinceDateInterval::createFromDateString()only stopped returningfalsein PHP 8.3.No CHANGELOG entry; I'll leave the wording to you.
A follow-up PR adds a PHPStan rule that keeps these tags from going missing on new methods (its
--fixproduced the per-method tags here).🤖 Generated with Claude Code
https://claude.ai/code/session_01Y1vvcUHV6d9eTuxE4GW5MX