Skip to content

Commit cbe488c

Browse files
authored
Narrow return type for categories block functions (#360)
1 parent 9d3cdfb commit cbe488c

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

functionMap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
'addslashes_gpc' => ['T', '@phpstan-template' => 'T', 'gpc' => 'T'],
5656
'block_version' => ["(\$content is '' ? 0 : 0|1)"],
5757
'bool_from_yn' => ["(\$yn is 'y' ? true : false)"],
58+
'build_dropdown_script_block_core_categories' => ['non-falsy-string'],
5859
'check_admin_referer' => ['1|2|false', 'action' => '-1|string'],
5960
'check_ajax_referer' => ['1|2|false', 'action' => '-1|string'],
6061
'comment_class' => ['($display is true ? void : string)'],
@@ -120,6 +121,7 @@
120121
'prep_atom_text_construct' => ["array{'html'|'text'|'xhtml', string}"],
121122
'previous_posts' => ['($display is true ? void : string)'],
122123
'rawurlencode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
124+
'render_block_core_categories' => ['non-falsy-string'],
123125
'rest_authorization_required_code' => ['401|403'],
124126
'rest_sanitize_boolean' => ["(T is bool ? T : (T is ''|'false'|'FALSE'|'0'|0 ? false : true))", '@phpstan-template T' => 'of bool|string|int', 'value' => 'T'],
125127
'rest_ensure_response' => ['($response is \WP_Error ? \WP_Error : \WP_REST_Response)'],

tests/TypeInferenceTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function dataFileAsserts(): iterable
1414
yield from $this->gatherAssertTypes(__DIR__ . '/data/__return.php');
1515
yield from $this->gatherAssertTypes(__DIR__ . '/data/_get_list_table.php');
1616
yield from $this->gatherAssertTypes(__DIR__ . '/data/absint.php');
17+
yield from $this->gatherAssertTypes(__DIR__ . '/data/block_core.php');
1718
yield from $this->gatherAssertTypes(__DIR__ . '/data/block_version.php');
1819
yield from $this->gatherAssertTypes(__DIR__ . '/data/bookmark-admin.php');
1920
yield from $this->gatherAssertTypes(__DIR__ . '/data/bookmark.php');

tests/data/block_core.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 function build_dropdown_script_block_core_categories;
8+
use function render_block_core_categories;
9+
use function PHPStan\Testing\assertType;
10+
11+
assertType('non-falsy-string', render_block_core_categories(Faker::array(), Faker::string(), Faker::wpBlock()));
12+
13+
assertType('non-falsy-string', build_dropdown_script_block_core_categories(Faker::string()));

wordpress-stubs.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96571,6 +96571,7 @@ function block_core_calendar_update_has_published_post_on_transition_post_status
9657196571
* @param WP_Block $block Block instance.
9657296572
*
9657396573
* @return string Returns the categories list/dropdown markup.
96574+
* @phpstan-return non-falsy-string
9657496575
*/
9657596576
function render_block_core_categories($attributes, $content, $block)
9657696577
{
@@ -96583,6 +96584,7 @@ function render_block_core_categories($attributes, $content, $block)
9658396584
* @param string $dropdown_id ID of the dropdown field.
9658496585
*
9658596586
* @return string Returns the dropdown onChange redirection script.
96587+
* @phpstan-return non-falsy-string
9658696588
*/
9658796589
function build_dropdown_script_block_core_categories($dropdown_id)
9658896590
{

0 commit comments

Comments
 (0)