From 534be49e8ce3222745f68ab22e168f632e522cbd Mon Sep 17 00:00:00 2001 From: Marian <42134098+IanDelMar@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:13:26 +0200 Subject: [PATCH] Add conditional return type for _wp_json_sanity_check() --- functionMap.php | 1 + tests/TypeInferenceTest.php | 1 + tests/data/_wp_json_sanity_check.php | 18 ++++++++++++++++++ wordpress-stubs.php | 4 ++++ 4 files changed, 24 insertions(+) create mode 100644 tests/data/_wp_json_sanity_check.php diff --git a/functionMap.php b/functionMap.php index 3c5063a..17f0291 100644 --- a/functionMap.php +++ b/functionMap.php @@ -32,6 +32,7 @@ * @link https://github.com/phpstan/phpstan-src/blob/1.10.x/resources/functionMap.php */ return [ + '_wp_json_sanity_check' => ['T', '@phpstan-template' => 'T', 'value' => 'T', 'depth' => 'positive-int'], '_get_list_table' => ["(\$class_name is 'WP_Posts_List_Table'|'WP_Media_List_Table'|'WP_Terms_List_Table'|'WP_Users_List_Table'|'WP_Comments_List_Table'|'WP_Post_Comments_List_Table'|'WP_Links_List_Table'|'WP_Plugin_Install_List_Table'|'WP_Themes_List_Table'|'WP_Theme_Install_List_Table'|'WP_Plugins_List_Table'|'WP_Application_Passwords_List_Table'|'WP_MS_Sites_List_Table'|'WP_MS_Users_List_Table'|'WP_MS_Themes_List_Table'|'WP_Privacy_Data_Export_Requests_List_Table'|'WP_Privacy_Data_Removal_Requests_List_Table' ? T : false)", '@phpstan-template' => 'T', 'class_name' => 'class-string', 'args' => 'array{screen?: string}'], 'addslashes_gpc' => ['T', '@phpstan-template' => 'T', 'gpc' => 'T'], 'add_submenu_page' => [null, 'callback' => "''|callable"], diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index bdf00c8..b2edf2f 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -10,6 +10,7 @@ class TypeInferenceTest extends \PHPStan\Testing\TypeInferenceTestCase public function dataFileAsserts(): iterable { yield from $this->gatherAssertTypes(__DIR__ . '/data/_get_list_table.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/_wp_json_sanity_check.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/current_time.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/echo_parameter.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_approved_comments.php'); diff --git a/tests/data/_wp_json_sanity_check.php b/tests/data/_wp_json_sanity_check.php new file mode 100644 index 0000000..ec06d94 --- /dev/null +++ b/tests/data/_wp_json_sanity_check.php @@ -0,0 +1,18 @@ +