Skip to content

Narrow return type for wp_update_category() #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
'wp_unschedule_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args' => $cronArgsType],
'wp_unschedule_hook' => ['($wp_error is false ? int<0, max>|false : int<0, max>|\WP_Error)'],
'wp_unslash' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
'wp_update_category' => ['int<0, max>|false'],
'wp_update_comment' => ['($wp_error is false ? 0|1|false : 0|1|\WP_Error)'],
'wp_update_link' => ['int<0, max>|\WP_Error'],
'wp_update_post' => ['($wp_error is false ? int<0, max> : int<1, max>|\WP_Error)'],
Expand Down
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function dataFileAsserts(): iterable
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_unique_id.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_update_category.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_update_link.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_widget_factory.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_widget_rss.php');
Expand Down
12 changes: 12 additions & 0 deletions tests/data/wp_update_category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function wp_update_category;
use function PHPStan\Testing\assertType;

assertType('int<0, max>|false', wp_update_category([]));
assertType('int<0, max>|false', wp_update_category(['cat_ID' => 123]));
assertType('int<0, max>|false', wp_update_category(Faker::array()));
1 change: 1 addition & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -89582,6 +89582,7 @@ function wp_insert_category($catarr, $wp_error = \false)
*
* @param array $catarr The 'cat_ID' value is required. All other keys are optional.
* @return int|false The ID number of the new or updated Category on success. Zero or FALSE on failure.
* @phpstan-return int<0, max>|false
*/
function wp_update_category($catarr)
{
Expand Down