From 25581d171c287450ce1bc6f4531087f4f7191835 Mon Sep 17 00:00:00 2001 From: Marian <42134098+IanDelMar@users.noreply.github.com> Date: Mon, 25 Nov 2024 04:22:17 +0100 Subject: [PATCH 1/2] Add conditional return type for get_user() --- functionMap.php | 1 + tests/TypeInferenceTest.php | 1 + tests/data/get_user.php | 16 ++++++++++++++++ wordpress-stubs.php | 1 + 4 files changed, 19 insertions(+) create mode 100644 tests/data/get_user.php diff --git a/functionMap.php b/functionMap.php index 35ed641..8958f83 100644 --- a/functionMap.php +++ b/functionMap.php @@ -210,4 +210,5 @@ 'WP_Widget_Factory::unregister' => [null, 'widget' => 'class-string<\WP_Widget>|\WP_Widget'], 'Custom_Image_Header::show_header_selector' => [null, 'type' => "'default'|'uploaded'"], 'Custom_Image_Header::set_header_image' => [null, 'choice' => 'string|array{attachment_id: int<1, max>, url: string, width: int<0, max>, height: int<0, max>}'], + 'get_user' => ['($user_id is int ? false : \WP_User|false)'], ]; diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index 26ba090..1d4ddf2 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -38,6 +38,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/get_taxonomies.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_term.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_taxonomies_for_attachments.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/get_user.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/has_filter.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/is_new_day.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/is_wp_error.php'); diff --git a/tests/data/get_user.php b/tests/data/get_user.php new file mode 100644 index 0000000..7e32d2b --- /dev/null +++ b/tests/data/get_user.php @@ -0,0 +1,16 @@ + ? false : \WP_User|false) */ function get_user($user_id) { From f989807d014ee7c25f5c1f45520aeb6b5be2c9f5 Mon Sep 17 00:00:00 2001 From: Marian <42134098+IanDelMar@users.noreply.github.com> Date: Mon, 25 Nov 2024 04:32:43 +0100 Subject: [PATCH 2/2] Add conditional return type for get_user_by() --- functionMap.php | 1 + tests/TypeInferenceTest.php | 1 + tests/data/get_user_by.php | 22 ++++++++++++++++++++++ wordpress-stubs.php | 1 + 4 files changed, 25 insertions(+) create mode 100644 tests/data/get_user_by.php diff --git a/functionMap.php b/functionMap.php index 8958f83..12045d1 100644 --- a/functionMap.php +++ b/functionMap.php @@ -211,4 +211,5 @@ 'Custom_Image_Header::show_header_selector' => [null, 'type' => "'default'|'uploaded'"], 'Custom_Image_Header::set_header_image' => [null, 'choice' => 'string|array{attachment_id: int<1, max>, url: string, width: int<0, max>, height: int<0, max>}'], 'get_user' => ['($user_id is int ? false : \WP_User|false)'], + 'get_user_by' => ["(\$field is 'id'|'ID' ? (\$value is int ? false : \WP_User|false) : \WP_User|false)"], ]; diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index 1d4ddf2..42067a5 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -39,6 +39,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/get_term.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_taxonomies_for_attachments.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_user.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/get_user_by.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/has_filter.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/is_new_day.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/is_wp_error.php'); diff --git a/tests/data/get_user_by.php b/tests/data/get_user_by.php new file mode 100644 index 0000000..3226ce0 --- /dev/null +++ b/tests/data/get_user_by.php @@ -0,0 +1,22 @@ + ? false : \WP_User|false) : \WP_User|false) */ function get_user_by($field, $value) {