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

Action setLabel does not allow to use arrow function with given entities #6624

Open
astronati opened this issue Dec 5, 2024 · 1 comment

Comments

@astronati
Copy link

astronati commented Dec 5, 2024

Describe the bug
PHPStan reports an error when the following code snippet is used:

 $addRoundAction = Action::new(self::ADD_ROUND_ACTION)
            ->setLabel(fn (Lead $lead): string => $this->translator->trans('lead.ADD_ROUND', ['count' => $lead->getActiveRoundCount() +  1]))

The error generated is:

  151    Parameter #1 $label of method EasyCorp\Bundle\EasyAdminBundle\Config\Action::setLabel() expects (callable(object):
         string)|string|Symfony\Contracts\Translation\TranslatableInterface|false|null, Closure(App\Domain\Entity\Lead\Lead): string given.
         💡 Type App\Domain\Entity\Lead\Lead of parameter #1 $lead of passed callable needs to be same or wider than parameter type object of accepting callable.

To Reproduce
To Reproduce

  • Add the setLabel method to an Action.
  • Use an arrow function (fn) with a strongly typed parameter (Lead) for the setLabel callable.

See
#6599

@astronati
Copy link
Author

Hi @hhamon ,

I've noticed this strange behaviour of PHPSTAN.
Could you take a look at this? Thanks

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

1 participant