Skip to content

Commit df4eef7

Browse files
authored
Merge arguments when an inheriting function specifies some arguments (#50)
1 parent edc47d6 commit df4eef7

File tree

2 files changed

+240
-9
lines changed

2 files changed

+240
-9
lines changed

visitor.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ public function format(): array
144144
);
145145
}
146146

147-
148147
return $strings;
149148
}
150149
}
@@ -499,18 +498,32 @@ private function addTags(string $name, Doc $docComment): ?Doc
499498
*/
500499
private function discoverInheritedArgs(DocBlock $docblock, array $additions): array
501500
{
502-
foreach ($additions as $add) {
503-
if ($add->tag === '@phpstan-param') {
504-
// We can't yet handle merging args.
505-
return $additions;
506-
}
507-
}
508-
509501
/** @var Param[] $params */
510502
$params = $docblock->getTagsByName('param');
511503

504+
$phpStanParams = array_filter($additions, function(WordPressTag $addition): bool {
505+
return $addition->tag === '@phpstan-param';
506+
});
507+
512508
foreach ($params as $param) {
513-
$additions = array_merge($additions, $this->getInheritedTagsForParam($param));
509+
$inherited = $this->getInheritedTagsForParam($param);
510+
511+
if (count($inherited) === 0) {
512+
continue;
513+
}
514+
515+
foreach ($phpStanParams as $addition) {
516+
foreach ($inherited as $inherit) {
517+
if ($addition->name !== $inherit->name) {
518+
continue;
519+
}
520+
521+
$addition->children = array_merge($addition->children, $inherit->children);
522+
continue 3;
523+
}
524+
}
525+
526+
$additions = array_merge($additions, $inherited);
514527
}
515528

516529
return $additions;

wordpress-stubs.php

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91538,6 +91538,39 @@ function category_description($category = 0)
9153891538
* hide_if_empty?: bool,
9153991539
* required?: bool,
9154091540
* walker?: Walker,
91541+
* taxonomy?: string|string[],
91542+
* object_ids?: int|int[],
91543+
* orderby?: string,
91544+
* order?: string,
91545+
* hide_empty?: bool|int,
91546+
* include?: int[]|string,
91547+
* exclude?: int[]|string,
91548+
* exclude_tree?: int[]|string,
91549+
* number?: int|string,
91550+
* offset?: int,
91551+
* fields?: string,
91552+
* count?: bool,
91553+
* name?: string|string[],
91554+
* slug?: string|string[],
91555+
* term_taxonomy_id?: int|int[],
91556+
* hierarchical?: bool,
91557+
* search?: string,
91558+
* name__like?: string,
91559+
* description__like?: string,
91560+
* pad_counts?: bool,
91561+
* get?: string,
91562+
* child_of?: int,
91563+
* parent?: int,
91564+
* childless?: bool,
91565+
* cache_domain?: string,
91566+
* update_term_meta_cache?: bool,
91567+
* meta_key?: string|string[],
91568+
* meta_value?: string|string[],
91569+
* meta_compare?: string,
91570+
* meta_compare_key?: string,
91571+
* meta_type?: string,
91572+
* meta_type_key?: string,
91573+
* meta_query?: array,
9154191574
* } $args
9154291575
*/
9154391576
function wp_dropdown_categories($args = '')
@@ -91610,6 +91643,7 @@ function wp_dropdown_categories($args = '')
9161091643
* title_li?: string,
9161191644
* use_desc_for_title?: bool|int,
9161291645
* walker?: Walker,
91646+
* taxonomy?: string,
9161391647
* } $args
9161491648
*/
9161591649
function wp_list_categories($args = '')
@@ -91645,6 +91679,19 @@ function wp_list_categories($args = '')
9164591679
* link?: string,
9164691680
* post_type?: string,
9164791681
* echo?: bool,
91682+
* smallest?: int,
91683+
* largest?: int,
91684+
* unit?: string,
91685+
* number?: int,
91686+
* format?: string,
91687+
* separator?: string,
91688+
* orderby?: string,
91689+
* order?: string,
91690+
* filter?: int|bool,
91691+
* topic_count_text?: string,
91692+
* topic_count_text_callback?: callable,
91693+
* topic_count_scale_callback?: callable,
91694+
* show_count?: bool|int,
9164891695
* } $args
9164991696
*/
9165091697
function wp_tag_cloud($args = '')
@@ -109687,6 +109734,22 @@ function the_posts_navigation($args = array())
109687109734
* screen_reader_text?: string,
109688109735
* aria_label?: string,
109689109736
* class?: string,
109737+
* base?: string,
109738+
* format?: string,
109739+
* total?: int,
109740+
* current?: int,
109741+
* aria_current?: string,
109742+
* show_all?: bool,
109743+
* end_size?: int,
109744+
* mid_size?: int,
109745+
* prev_next?: bool,
109746+
* prev_text?: bool,
109747+
* next_text?: bool,
109748+
* type?: string,
109749+
* add_args?: array,
109750+
* add_fragment?: string,
109751+
* before_page_number?: string,
109752+
* after_page_number?: string,
109690109753
* } $args
109691109754
*/
109692109755
function get_the_posts_pagination($args = array())
@@ -109703,6 +109766,22 @@ function get_the_posts_pagination($args = array())
109703109766
* screen_reader_text?: string,
109704109767
* aria_label?: string,
109705109768
* class?: string,
109769+
* base?: string,
109770+
* format?: string,
109771+
* total?: int,
109772+
* current?: int,
109773+
* aria_current?: string,
109774+
* show_all?: bool,
109775+
* end_size?: int,
109776+
* mid_size?: int,
109777+
* prev_next?: bool,
109778+
* prev_text?: bool,
109779+
* next_text?: bool,
109780+
* type?: string,
109781+
* add_args?: array,
109782+
* add_fragment?: string,
109783+
* before_page_number?: string,
109784+
* after_page_number?: string,
109706109785
* } $args See get_the_posts_pagination()
109707109786
*/
109708109787
function the_posts_pagination($args = array())
@@ -120334,6 +120413,79 @@ function is_post_publicly_viewable($post = \null)
120334120413
* include?: int[],
120335120414
* exclude?: int[],
120336120415
* suppress_filters?: bool,
120416+
* attachment_id?: int,
120417+
* author?: int|string,
120418+
* author_name?: string,
120419+
* author__in?: int[],
120420+
* author__not_in?: int[],
120421+
* cache_results?: bool,
120422+
* cat?: int|string,
120423+
* category__and?: int[],
120424+
* category__in?: int[],
120425+
* category__not_in?: int[],
120426+
* category_name?: string,
120427+
* comment_count?: array|int,
120428+
* comment_status?: string,
120429+
* comments_per_page?: int,
120430+
* date_query?: array,
120431+
* day?: int,
120432+
* exact?: bool,
120433+
* fields?: string,
120434+
* hour?: int,
120435+
* ignore_sticky_posts?: int|bool,
120436+
* m?: int,
120437+
* meta_key?: string|string[],
120438+
* meta_value?: string|string[],
120439+
* meta_compare?: string,
120440+
* meta_compare_key?: string,
120441+
* meta_type?: string,
120442+
* meta_type_key?: string,
120443+
* meta_query?: array,
120444+
* menu_order?: int,
120445+
* minute?: int,
120446+
* monthnum?: int,
120447+
* name?: string,
120448+
* nopaging?: bool,
120449+
* no_found_rows?: bool,
120450+
* offset?: int,
120451+
* order?: string,
120452+
* orderby?: string|array,
120453+
* p?: int,
120454+
* page?: int,
120455+
* paged?: int,
120456+
* page_id?: int,
120457+
* pagename?: string,
120458+
* perm?: string,
120459+
* ping_status?: string,
120460+
* post__in?: int[],
120461+
* post__not_in?: int[],
120462+
* post_mime_type?: string,
120463+
* post_name__in?: string[],
120464+
* post_parent?: int,
120465+
* post_parent__in?: int[],
120466+
* post_parent__not_in?: int[],
120467+
* post_type?: string|string[],
120468+
* post_status?: string|string[],
120469+
* posts_per_page?: int,
120470+
* posts_per_archive_page?: int,
120471+
* s?: string,
120472+
* second?: int,
120473+
* sentence?: bool,
120474+
* suppress_filters?: bool,
120475+
* tag?: string,
120476+
* tag__and?: int[],
120477+
* tag__in?: int[],
120478+
* tag__not_in?: int[],
120479+
* tag_id?: int,
120480+
* tag_slug__and?: string[],
120481+
* tag_slug__in?: string[],
120482+
* tax_query?: array,
120483+
* title?: string,
120484+
* update_post_meta_cache?: bool,
120485+
* update_post_term_cache?: bool,
120486+
* lazy_load_term_meta?: bool,
120487+
* w?: int,
120488+
* year?: int,
120337120489
* } $args
120338120490
*/
120339120491
function get_posts($args = \null)
@@ -120909,6 +121061,39 @@ function wp_get_post_tags($post_id = 0, $args = array())
120909121061
* WP_Error object if `$taxonomy` doesn't exist.
120910121062
* @phpstan-param array{
120911121063
* fields?: string,
121064+
* taxonomy?: string|string[],
121065+
* object_ids?: int|int[],
121066+
* orderby?: string,
121067+
* order?: string,
121068+
* hide_empty?: bool|int,
121069+
* include?: int[]|string,
121070+
* exclude?: int[]|string,
121071+
* exclude_tree?: int[]|string,
121072+
* number?: int|string,
121073+
* offset?: int,
121074+
* fields?: string,
121075+
* count?: bool,
121076+
* name?: string|string[],
121077+
* slug?: string|string[],
121078+
* term_taxonomy_id?: int|int[],
121079+
* hierarchical?: bool,
121080+
* search?: string,
121081+
* name__like?: string,
121082+
* description__like?: string,
121083+
* pad_counts?: bool,
121084+
* get?: string,
121085+
* child_of?: int,
121086+
* parent?: int,
121087+
* childless?: bool,
121088+
* cache_domain?: string,
121089+
* update_term_meta_cache?: bool,
121090+
* meta_key?: string|string[],
121091+
* meta_value?: string|string[],
121092+
* meta_compare?: string,
121093+
* meta_compare_key?: string,
121094+
* meta_type?: string,
121095+
* meta_type_key?: string,
121096+
* meta_query?: array,
120912121097
* } $args
120913121098
*/
120914121099
function wp_get_post_terms($post_id = 0, $taxonomy = 'post_tag', $args = array())
@@ -130022,6 +130207,39 @@ function setup_userdata($for_user_id = 0)
130022130207
* role?: string|array,
130023130208
* role__in?: string[],
130024130209
* role__not_in?: string[],
130210+
* blog_id?: int,
130211+
* role?: string|string[],
130212+
* role__in?: string[],
130213+
* role__not_in?: string[],
130214+
* meta_key?: string|string[],
130215+
* meta_value?: string|string[],
130216+
* meta_compare?: string,
130217+
* meta_compare_key?: string,
130218+
* meta_type?: string,
130219+
* meta_type_key?: string,
130220+
* meta_query?: array,
130221+
* capability?: string|string[],
130222+
* capability__in?: string[],
130223+
* capability__not_in?: string[],
130224+
* include?: int[],
130225+
* exclude?: int[],
130226+
* search?: string,
130227+
* search_columns?: string[],
130228+
* orderby?: string|array,
130229+
* order?: string,
130230+
* offset?: int,
130231+
* number?: int,
130232+
* paged?: int,
130233+
* count_total?: bool,
130234+
* fields?: string|string[],
130235+
* who?: string,
130236+
* has_published_posts?: bool|string[],
130237+
* nicename?: string,
130238+
* nicename__in?: string[],
130239+
* nicename__not_in?: string[],
130240+
* login?: string,
130241+
* login__in?: string[],
130242+
* login__not_in?: string[],
130025130243
* } $args
130026130244
*/
130027130245
function wp_dropdown_users($args = '')

0 commit comments

Comments
 (0)