Repository navigation
Drupal URL and query extender return types - #577
Merged
Merged
Conversation
Core declares extend() on a query to return ExtendableInterface, so
->extend(PagerSelectExtender::class)->limit(10) reported limit() as
unknown. Make the declaring interface's extend() generic over the class
string it takes; the select and extender classes inherit it through
{@inheritdoc}. A string that is not a class literal still gives the
interface, and a core that changes the declaration keeps its own.
Assisted-by: claude-code/claude-opus-5-5
Assisted-by: claude-code/claude-opus-5-5
Url::toString(), generateFromRoute() and assemble() declare string|GeneratedUrl, but return a GeneratedUrl only when $collect_bubbleable_metadata is TRUE. Key their return type on that flag. Assisted-by: claude-code/claude-opus-5-5
Assisted-by: claude-code/claude-opus-5-5
Assisted-by: claude-code/claude-opus-5-5
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Nov 22, 2026
Closed
The conditional return on the URL methods built `true` by hand; PhpType::true_() hands out the interned keyword type instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Thanks |
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.
Adds DR21: PHPantom gives precise return types to core methods whose docblocks are wider than what the call returns.
What changes
Url::toString(),UrlGeneratorInterface::generateFromRoute()andUnroutedUrlAssemblerInterface::assemble()return astring, and aGeneratedUrlonly when$collect_bubbleable_metadataisTRUE. Aboolvariable keeps the union.extend()returns the extender class it is given, chains included. A plain string argument keepsExtendableInterface.{@inheritdoc}, such asUrlGenerator,SelectandSelectExtender, get the same types.PHPStan's Drupal extension corrects only
Url::toString();generateFromRoute()andassemble()take the same flag, so they are included. The roadmap namestoString()only.A repeated identical call in one method, such as a second
$url->toString(), is still typed wide. That is an engine bug outside Drupal, fixed in a separate PR.Checked
analyzeon Drupal core 11.4: 376 reports are gone and 3 are new. One new report is a real mismatch in core:StringDatabaseStoragedeclares@return Selectbut returns aPagerSelectExtender. The others are existing reports reworded.analyzeon a site with theredirectandflagmodules: 421 gone, 5 new, the same kinds.How to test
Run
composer installinexamples/drupal, open it with this branch's build, and follow the "Try:" comments:web/modules/custom/acme/src/CoreLinks.php,firstNodePath(): the plaintoString()passed to astringparameter is not reported, and$generated->completesgetGeneratedUrl().web/modules/custom/acme/src/NoteCounter.php,firstPageIds(): complete after->extend(PagerSelectExtender::class)->to seelimit().Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,examples/)config-schema.json). Not applicable: this PR adds or changes no setting.the changes and why they are needed.
the changelog, and other user-facing content, and removed or corrected
anything inaccurate, unclear, or unnecessary.