Skip to content
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

InvalidArgument: 'expects a public static callable, but a non-static callable provided' #10936

Closed
loevgaard opened this issue May 3, 2024 · 4 comments

Comments

@loevgaard
Copy link

loevgaard commented May 3, 2024

Between version 5.23.1 and 5.24.0 there is a difference in Psalm handling this code:

<?php

declare(strict_types=1);

namespace App\Twig\Extension;

use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class Extension extends AbstractExtension
{
    public function getFunctions(): array
    {
        return [
            new TwigFunction('previous_checkout_step', [Runtime::class, 'previousCheckoutStep']),
            new TwigFunction('next_checkout_step', [Runtime::class, 'nextCheckoutStep']),
            new TwigFunction('taxon', [Runtime::class, 'taxon']),
        ];
    }
}

In 5.24.0 Psalm gives me these errors:

ERROR: InvalidArgument - src/Twig/Extension/Extension.php:15:56 - Argument 2 of Twig\TwigFunction::__construct expects a public static callable, but a non-static callable provided (see https://psalm.dev/004)
            new TwigFunction('previous_checkout_step', [Runtime::class, 'previousCheckoutStep']),


ERROR: InvalidArgument - src/Twig/Extension/Extension.php:16:52 - Argument 2 of Twig\TwigFunction::__construct expects a public static callable, but a non-static callable provided (see https://psalm.dev/004)
            new TwigFunction('next_checkout_step', [Runtime::class, 'nextCheckoutStep']),


ERROR: InvalidArgument - src/Twig/Extension/Extension.php:17:39 - Argument 2 of Twig\TwigFunction::__construct expects a public static callable, but a non-static callable provided (see https://psalm.dev/004)
            new TwigFunction('taxon', [Runtime::class, 'taxon']),

In 5.23.1 I get no errors.

The constructor for TwigFunction looks like this:

/**
 * @param callable|array{class-string, string}|null $callable A callable implementing the function. If null, you need to overwrite the "node_class" option to customize compilation.
 */
public function __construct(string $name, $callable = null, array $options = [])
{
    $this->name = $name;
    $this->callable = $callable;
    $this->options = array_merge([
        'needs_environment' => false,
        'needs_context' => false,
        'is_variadic' => false,
        'is_safe' => null,
        'is_safe_callback' => null,
        'node_class' => FunctionExpression::class,
        'deprecated' => false,
        'alternative' => null,
    ], $options);
}

I am not able to reproduce the bug unfortunately: https://psalm.dev/.

I have no idea, but somehow I think it's related to this PR: #10839

@VincentLanglet
Copy link
Contributor

A PR is opened #10935

@weirdan
Copy link
Collaborator

weirdan commented May 5, 2024

Fixed in #10935

@weirdan weirdan closed this as completed May 5, 2024
greg0ire added a commit to greg0ire/DoctrineMongoDBBundle that referenced this issue May 5, 2024
@loevgaard
Copy link
Author

Cool, thanks!

loevgaard added a commit to Setono/TagBagBundle that referenced this issue May 21, 2024
@loevgaard
Copy link
Author

I think this issue was reintroduced in 5.25.0. I am getting the same error nonetheless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants