Repository navigation
Allow function map annotations to override Core PHPStan tags - #498
szepeviktor wants to merge 6 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. |
wordpress-stubs will be still able to override code tags. |
Function-map annotations now replace matching Core annotations instead of being skipped or appended as duplicates. For example,
check_admin_referer()retains the mapped1|2|falseconditional return type instead of Core's broader integer type.Use PHPStan's PHPDoc parser to identify tags by kind and target, and replace their token ranges while preserving unrelated annotations and comment formatting. This supports return types, individual parameters, templates, properties, methods, aliases, imports, assertions, and interfaces. Declare the parser as a direct development dependency.
Compare WordPress trunk at
WordPress/wordpress-develop@4a96bbdd833db4a7b692924ddbf375482a163620against the pinned WordPress 7.1.2 source. Remove the identicalstripslashes_from_strings_only()template entry from the map because the pinned Core already provides it. Keep refinements with different types and annotations only available in trunk; generation remains on 7.1.2.Regenerate the stubs, restore the 137 type assertions for mapped refinements, and add regression coverage for targeted annotation replacement and preservation of unrelated comments and tags.
Validation:
git diff --checkpassed.