Skip to content

Commit db22bf0

Browse files
authored
Add stubs for WP_Widget_Factory (#221)
1 parent 90de094 commit db22bf0

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

functionMap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,7 @@
193193
'WP_Translations::translate' => ['($singular is null ? null : string)'],
194194
'WP_Translations::translate_plural' => ['($singular is null ? null : ($plural is null ? T : string))', '@phpstan-template T' => 'of string|null', 'singular' => 'T', 'count' => 'int'],
195195
'WP_Query' => [null, '@phpstan-property-read bool $query_vars_changed' => '', '@phpstan-property-read bool|string $query_vars_hash' => '', '@phpstan-method void init_query_flags()' => ''],
196+
'WP_Widget_Factory::$widgets' => [null, '@phpstan-var' => 'array<string, \WP_Widget>'],
197+
'WP_Widget_Factory::register' => [null, 'widget' => 'class-string<\WP_Widget>|\WP_Widget'],
198+
'WP_Widget_Factory::unregister' => [null, 'widget' => 'class-string<\WP_Widget>|\WP_Widget'],
196199
];

tests/TypeInferenceTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function dataFileAsserts(): iterable
6060
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_tag_cloud.php');
6161
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php');
6262
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_translations.php');
63+
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_widget_factory.php');
6364
yield from $this->gatherAssertTypes(__DIR__ . '/data/wpdb.php');
6465
}
6566

tests/data/wp_widget_factory.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use WP_Widget_Factory;
8+
9+
use function PHPStan\Testing\assertType;
10+
11+
$factory = new WP_Widget_Factory();
12+
13+
assertType('array<string, WP_Widget>', $factory->widgets);

wordpress-stubs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56518,6 +56518,7 @@ class WP_Widget_Factory
5651856518
*
5651956519
* @since 2.8.0
5652056520
* @var array
56521+
* @phpstan-var array<string, \WP_Widget>
5652156522
*/
5652256523
public $widgets = array();
5652356524
/**
@@ -56547,6 +56548,7 @@ public function WP_Widget_Factory()
5654756548
* instead of simply a `WP_Widget` subclass name.
5654856549
*
5654956550
* @param string|WP_Widget $widget Either the name of a `WP_Widget` subclass or an instance of a `WP_Widget` subclass.
56551+
* @phpstan-param class-string<\WP_Widget>|\WP_Widget $widget
5655056552
*/
5655156553
public function register($widget)
5655256554
{
@@ -56559,6 +56561,7 @@ public function register($widget)
5655956561
* instead of simply a `WP_Widget` subclass name.
5656056562
*
5656156563
* @param string|WP_Widget $widget Either the name of a `WP_Widget` subclass or an instance of a `WP_Widget` subclass.
56564+
* @phpstan-param class-string<\WP_Widget>|\WP_Widget $widget
5656256565
*/
5656356566
public function unregister($widget)
5656456567
{

0 commit comments

Comments
 (0)