From db22bf0554b03c897f45ef3cab04747f96e8eeec Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Thu, 12 Sep 2024 06:43:20 +0200 Subject: [PATCH] Add stubs for WP_Widget_Factory (#221) --- functionMap.php | 3 +++ tests/TypeInferenceTest.php | 1 + tests/data/wp_widget_factory.php | 13 +++++++++++++ wordpress-stubs.php | 3 +++ 4 files changed, 20 insertions(+) create mode 100644 tests/data/wp_widget_factory.php diff --git a/functionMap.php b/functionMap.php index 1baf52b..df0a5a6 100644 --- a/functionMap.php +++ b/functionMap.php @@ -193,4 +193,7 @@ 'WP_Translations::translate' => ['($singular is null ? null : string)'], 'WP_Translations::translate_plural' => ['($singular is null ? null : ($plural is null ? T : string))', '@phpstan-template T' => 'of string|null', 'singular' => 'T', 'count' => 'int'], 'WP_Query' => [null, '@phpstan-property-read bool $query_vars_changed' => '', '@phpstan-property-read bool|string $query_vars_hash' => '', '@phpstan-method void init_query_flags()' => ''], + 'WP_Widget_Factory::$widgets' => [null, '@phpstan-var' => 'array'], + 'WP_Widget_Factory::register' => [null, 'widget' => 'class-string<\WP_Widget>|\WP_Widget'], + 'WP_Widget_Factory::unregister' => [null, 'widget' => 'class-string<\WP_Widget>|\WP_Widget'], ]; diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index 3d827e5..1ef79bc 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -60,6 +60,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_tag_cloud.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_translations.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_widget_factory.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wpdb.php'); } diff --git a/tests/data/wp_widget_factory.php b/tests/data/wp_widget_factory.php new file mode 100644 index 0000000..023f99e --- /dev/null +++ b/tests/data/wp_widget_factory.php @@ -0,0 +1,13 @@ +', $factory->widgets); diff --git a/wordpress-stubs.php b/wordpress-stubs.php index ec7eaee..2555af5 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -56518,6 +56518,7 @@ class WP_Widget_Factory * * @since 2.8.0 * @var array + * @phpstan-var array */ public $widgets = array(); /** @@ -56547,6 +56548,7 @@ public function WP_Widget_Factory() * instead of simply a `WP_Widget` subclass name. * * @param string|WP_Widget $widget Either the name of a `WP_Widget` subclass or an instance of a `WP_Widget` subclass. + * @phpstan-param class-string<\WP_Widget>|\WP_Widget $widget */ public function register($widget) { @@ -56559,6 +56561,7 @@ public function register($widget) * instead of simply a `WP_Widget` subclass name. * * @param string|WP_Widget $widget Either the name of a `WP_Widget` subclass or an instance of a `WP_Widget` subclass. + * @phpstan-param class-string<\WP_Widget>|\WP_Widget $widget */ public function unregister($widget) {