From 86d768f64a0a366a792fdd5e8965e3dc04ab55f9 Mon Sep 17 00:00:00 2001 From: Marian <42134098+IanDelMar@users.noreply.github.com> Date: Mon, 26 Aug 2024 22:44:33 +0200 Subject: [PATCH] Add cond. return type for wp_parse_list() --- functionMap.php | 1 + tests/TypeInferenceTest.php | 1 + tests/data/wp_parse_list.php | 10 ++++++++++ wordpress-stubs.php | 1 + 4 files changed, 13 insertions(+) create mode 100644 tests/data/wp_parse_list.php diff --git a/functionMap.php b/functionMap.php index 6b15877..5f71fb2 100644 --- a/functionMap.php +++ b/functionMap.php @@ -157,5 +157,6 @@ 'WP_Widget::form' => [null, 'instance' => 'T'], 'WP_Widget::update' => [null, 'new_instance' => 'T', 'old_instance' => 'T'], 'WP_Widget::widget' => [null, 'instance' => 'T', 'args' => 'array{name:string,id:string,description:string,class:string,before_widget:string,after_widget:string,before_title:string,after_title:string,before_sidebar:string,after_sidebar:string,show_in_rest:boolean,widget_id:string,widget_name:string}'], + 'wp_parse_list' => ['($input_list is array ? array : list)'], 'wp_parse_str' => [null, '@phpstan-param-out' => 'array $result'], ]; diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index cf78f4e..bcc0fbc 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -41,6 +41,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_bookmarks.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_categories.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_pages.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_parse_list.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_rest_request.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wpdb.php'); diff --git a/tests/data/wp_parse_list.php b/tests/data/wp_parse_list.php new file mode 100644 index 0000000..d697682 --- /dev/null +++ b/tests/data/wp_parse_list.php @@ -0,0 +1,10 @@ +', wp_parse_list((string)$_GET['input_list'])); +assertType('array', wp_parse_list((array)$_GET['input_list'])); diff --git a/wordpress-stubs.php b/wordpress-stubs.php index 0eea48e..9b08518 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -114324,6 +114324,7 @@ function wp_parse_args($args, $defaults = array()) * * @param array|string $input_list List of values. * @return array Array of values. + * @phpstan-return ($input_list is array ? array : list) */ function wp_parse_list($input_list) {