Repository navigation
Preserve existing phpstan-return tags when applying function map - #498
szepeviktor wants to merge 4 commits into
Conversation
|
@westonruter Please chime in! |
Map parameters replace the ones generated from the hash notation, and map parameters and templates do not duplicate the ones written in core, like map return types since php-stubs#498. PHPStan doesn't support shapes of generic arrays (array<K, V>{...}), so they become unsealed shapes (array{..., ...<K, V>}), and the string type of args parameters is only removed from the top-level union. Lists of lists of shapes are nested generic arrays. Claude-Session: https://claude.ai/code/session_01WNSb29tptiTQoc44Tk7XZW
Why would this be? Wouldn't types in core be better at least in that they will be more up to date? And we're working on migrating the types from this repo over to core. Once that's done, I should think core should be the source of truth. |
|
Here is what RoboViktor says.
|
Which removes the ability to "correct" types. |
I do not dare to go against Weston. |
|
We haven't finished porting the PHPStan types from stubs to core, so it's not really right to compare yet. But let's say we do port everything over: after that, I should think core's types should be considered canonical. Now, maybe there are some types in core which are needing to be written in a way internally that isn't appropriate for themes and plugins. In that case, perhaps wordpress-stubs should have a mechanism to override types on an as-needed basis. But hopefully this wouldn't be needed extensively. |
|
Can this move forward? Note that this question is related to bringing PHPStan analysis into Gutenberg: I want to use stubs generated from |
|
Or should this be waiting for the rest of the stubs to be merged into core? |
|
Note that I've incorporated the logic here into the above PR which adds PHPStan analysis for Gutenberg. It now bundles it's own wordpress-stubs which is generated from core |
|
Remaining stubs PRs not yet merged:
These were split out from WordPress/wordpress-develop#13530. I believe once these are all merged, then WordPress core will have a superset of the annotations that exist in wordpress-stubs. |
The Visitor appended function-map return types even when a docblock already contained
@phpstan-return, producing duplicate tags. Skip the mapped return tag when one is already present, preserving the existing type and all other mapped tags.Use the existing docblock parser to detect return tags. Add a regression test covering preservation of an existing return tag, retention of mapped parameter tags, and addition of a mapped return type when none exists.
Regenerate wordpress-stubs.php, removing all 15 duplicate mapped return tags while preserving the existing types.
Remove 137 type assertions that depended on the skipped map return types. Keep passing assertions in mixed fixtures and delete four fixtures left without assertions.
Validation: the full PHPUnit suite passed (1281 tests, 1463 assertions); PHPStan, PHPCS for changed PHP files, the generated stub syntax check, and git diff --check passed. A scan of the regenerated stub found zero docblocks with duplicate @phpstan-return tags.