Skip to content

Commit f69ef87

Browse files
committed
phpstan: conditional returns
1 parent 67a857b commit f69ef87

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/wp-includes/load.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,8 +1801,11 @@ function wp_doing_cron() {
18011801
* @param mixed $thing The variable to check.
18021802
* @return bool Whether the variable is an instance of WP_Error.
18031803
*
1804+
* @phpstan-template T
1805+
* @phpstan-param T|WP_Error $thing
18041806
* @phpstan-return ($thing is \WP_Error ? true : false)
18051807
* @phpstan-assert-if-true \WP_Error $thing
1808+
* @phpstan-assert-if-false !\WP_Error $thing
18061809
*/
18071810
function is_wp_error( $thing ) {
18081811
$is_wp_error = ( $thing instanceof WP_Error );

src/wp-includes/revision.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ function wp_restore_post_revision( $revision, $fields = null ) {
465465
$revision = wp_get_post_revision( $revision, ARRAY_A );
466466

467467
if ( ! $revision ) {
468-
return $revision;
468+
return null;
469469
}
470470

471471
if ( ! is_array( $fields ) ) {
@@ -940,7 +940,11 @@ function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
940940
* @param null|array|string $value The value to return - a single metadata value, or an array of values.
941941
* @param int $post_id Post ID.
942942
* @param string $meta_key Meta key.
943-
* @return null|array The default return value or the post thumbnail meta array.
943+
* @return null|array|string The default return value or the post thumbnail meta array.
944+
*
945+
* @template T
946+
* @phpstan-param T $value
947+
* @phpstan-return T|''|numeric-string
944948
*/
945949
function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
946950
$post = get_post();

src/wp-includes/taxonomy.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,9 @@ function get_term_field( $field, $term, $taxonomy = '', $context = 'display' ) {
12561256
*
12571257
* @param int|object $id Term ID or object.
12581258
* @param string $taxonomy Taxonomy name.
1259-
* @return string|int|null|WP_Error Will return empty string if $term is not an object.
1259+
* @return string|WP_Term|WP_Error Will return empty string if $term is not an object.
1260+
*
1261+
* @phpstan-return ''|\WP_Error|\WP_Term|WP_Error
12601262
*/
12611263
function get_term_to_edit( $id, $taxonomy ) {
12621264
$term = get_term( $id, $taxonomy );

0 commit comments

Comments
 (0)