szepeviktor/phpstan-wordpress

Call to function is_wp_error() with int<0, max> will always evaluate to false.

Flynsarmy opened this issue · 2 comments

In phpstan-wordpress v1.1 (not previous versions) with PHPStan level 6, when running something along the lines of:

$id = wp_insert_post([
    'post_title' => "Some Title",
]);
if (is_wp_error($id)) {
    ...
}

I get the errors:

Call to function is_wp_error() with int<0, max> will always evaluate to false.
is_wp_error(int<0, max>) will always evaluate to false.

This function can return an instance of WP_Error though [1][2][3][4][5][6], so the code is correct.

Here's my phpstan.neon

includes:
    # Include this extension
    - vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
    level: 6
    inferPrivatePropertyTypeFromConstructor: true
    paths:
        - MyFolder

The return type extension makes it quite smart there. Are you sure that the $wp_error argument, which is false by default, is set to true? Without that it will never return WP_Error.
But this behavior should exist since 1.0.5 AFAIK.

Ahh, you're absolutely right. My bad!