feat(psr20): ban relative date strings in DateTime/DateTimeImmutable constructors - #13
Merged
Merged
Conversation
- Introduced a new static method `isRelativeDateString()` in `Psr20Rule` to detect relative date strings. - Updated `processNode()` to flag any relative date strings passed to `new DateTime` or `new DateTimeImmutable`. - Added a comprehensive set of regex patterns to identify various relative date formats. - Extended test cases in `Psr20RuleTest` to cover new relative date scenarios and ensure existing behaviors are preserved. - Updated the fixture file to include examples of both relative and absolute date strings. - Revised documentation in `README.md` to reflect changes in the rule's behavior and examples.
…docs - Add fixture lines for 'TOMORROW' (uppercase, US1/AC6) and new \stdClass() (non-clock class must not trigger) with matching test assertions - Regenerate phpstan baseline (31 errors) - Update data-model.md to document \b word boundary patterns and explain compound modifier rationale (replaces stale $ anchors) - Update quickstart.md scenario 1 to include compound modifier examples Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
eexit
requested changes
Jul 23, 2026
eexit
approved these changes
Jul 27, 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.
Summary
Psr20Ruleto flag all relative date string literals passed tonew DateTime/new DateTimeImmutable, not only'now'and the empty constructor'2023-01-15') and variable arguments remain allowed — no false positives'yesterday noon','monday 14:00:00') are also caught via\bword boundary matchingclock.disallowDateTimeNowpreserved for backward compatibility with existing@phpstan-ignoresuppressionsWhat triggers the rule now
Keywords:
now,yesterday,today,tomorrow,noon,midnight(and with time suffix e.g.'today midnight')Day names:
monday–sunday(and with time suffix e.g.'monday 14:00:00')Signed/unsigned offsets:
+1 day,-2 weeks,0 daysAgo/in expressions:
2 days ago,in 3 weeksQualifiers:
next Monday,last week,previous year,this monthDay-of-month selectors:
first day of this month,last day of January 2023Clock-relative:
back of 10,front of 11All matching is case-insensitive.
What does NOT trigger the rule
Absolute ISO dates (
'2023-01-15','2023-12-31 23:59:59','2023-01-15T12:00:00+00:00'), time-only strings ('12:00:00'), variable arguments ($dateString), variadic placeholders (...$args), and non-DateTime/DateTimeImmutableclasses.Test plan
docker compose run --rm php composer test— PHPUnit green (22 assertions)docker compose run --rm php composer phpstan— no errorsdocker compose run --rm php composer cs-check— no style issues🤖 Generated with Claude Code