psalm / psalm-plugin-wordpress

WordPress stubs and plugin for Psalm
MIT License
69 stars 18 forks source link

method signature mismatch, add_theme_support $args is variadic as of 5.3.0 #2

Closed bapcltd-marv closed 4 years ago

bapcltd-marv commented 4 years ago

Not sure what version of wordpress is targeted/supported, but currently getting TooFewArguments - dist\functions.php:37:2 - Too few arguments for add_theme_support - expecting 2 but saw 1:

https://github.com/WordPress/WordPress/blob/4d8ef4961891bb2187a2bd9a44abae97145ffc37/wp-includes/theme.php#L2472

ntwb commented 4 years ago

Thanks @bapcltd-marv, I'm still new to Psalm, but here's a copy of the function in the stubs file of this repo:

❯ rg -pS add_theme_support -C 7
stubs/wordpress.php
39818-    }
39819-    /**
39820-     * @param string $feature
39821-     * @param mixed $args
39822-     *
39823-     * @return bool|null
39824-     */
39825:    function add_theme_support($feature, $args)

The source as per the link has:

https://github.com/WordPress/WordPress/blob/4d8ef4961891bb2187a2bd9a44abae97145ffc37/wp-includes/theme.php#L2472-L2486

 * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
 *              by adding it to the function signature.
 *
 * @global array $_wp_theme_features
 *
 * @param string $feature The feature being added. Likely core values include 'post-formats', 'post-thumbnails',
 *                        'custom-header', 'custom-background', 'custom-logo', 'menus', 'automatic-feed-links',
 *                        'html5', 'title-tag', 'customize-selective-refresh-widgets', 'starter-content',
 *                        'responsive-embeds', 'align-wide', 'dark-editor-style', 'disable-custom-colors',
 *                        'disable-custom-font-sizes', 'editor-color-palette', 'editor-font-sizes',
 *                        'editor-styles', and 'wp-block-styles'.
 * @param mixed  ...$args Optional extra arguments to pass along with certain features.
 * @return void|bool False on failure, void otherwise.
 */
function add_theme_support( $feature, ...$args ) {

So the stubs here are not using the spread operator ...$args, and also omits the optional @param context.

I'm guessing this is due to the stubs generator @joehoyle?

joehoyle commented 4 years ago

Hrm yeah I think this is a problem with the stub generation. I think it's reading the docblock which is mixed which I don't think means optional. I think variadics should always be optional though?

bapcltd-marv commented 4 years ago

does the stub generator check for ReflectionParameter::isVariadic() ?

joehoyle commented 4 years ago

Fixed in https://github.com/humanmade/psalm-plugin-wordpress/commit/58a7c8a1decf2334482e02d8bc25420789f43030#diff-acd9f9d9de79d2da0df4e18504594c1fL39825!