szepeviktor / phpstan-wordpress

WordPress extensions for PHPStan ⛏️
https://packagist.org/packages/szepeviktor/phpstan-wordpress
MIT License
256 stars 25 forks source link

Closure not recognized #233

Closed szepeviktor closed 1 week ago

szepeviktor commented 2 weeks ago
        add_filter(
            'frm_fields_in_entries_list_table',
            function ( $form_cols ) {
                return array_filter(
                    $form_cols,
                    function ( $form_col ) {
                        return 'gateway' !== $form_col->type;
                    }
                );
            }
        );
Filter callback return statement is missing.

@IanDelMar What is up here??

szepeviktor commented 2 weeks ago

function ( $form_cols ): array solves the problem but this code runs on PHP 7.0.

szepeviktor commented 2 weeks ago

return []; in place of array_filter also "solves" the problem.

johnbillion commented 2 weeks ago

I think this is because the closure has no return type declared either via its signature or via a docblock.

szepeviktor commented 2 weeks ago

or via a docblock.

I've tried /** @return array */, it does not help.

IanDelMar commented 1 week ago

I'll have a look later today.

IanDelMar commented 1 week ago

@szepeviktor This seems to be related to issue #221. (The fix in #223 has not been released yet.) "Filter callback return statement is missing" is no longer reported from dev-master#1e3cae664d215bed28602ee7ed2c356efd11b011 onwards and is most likely not present in version 1.3.4 with PHPStan versions below 1.10.50.

IanDelMar commented 1 week ago

and is most likely not present in version 1.3.4 with PHPStan versions below 1.10.50

I just tested this, and indeed, it is not reported.

szepeviktor commented 1 week ago

@IanDelMar You are a treasure.

https://github.com/szepeviktor/phpstan-wordpress/releases/tag/v1.3.5